日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java调flash注册方法_FlEX FLASH对象注册点调整方法

發布時間:2023/12/29 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java调flash注册方法_FlEX FLASH对象注册点调整方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

flash 和flex中的所有可視對象的注冊點全部都是默認在(0,0)點,也就是左上角.在flash內編輯狀態下 可以調整注冊點位置但要是程序生成的就沒有辦法了 因為還沒發現有注冊點屬性.只操作位置 x,y時注冊點在什么位置并不重要 但要是操作旋轉rotation 縮放scaleX,scaleY 注冊點在上面總感覺別扭,習慣上的位置應該是幾何中心.

調整方法(一):雙層容器嵌套;

這中方法就是 用兩層容器包裹起對象 內層容器的幾何中心放在外層的注冊點位置 也就是說內層的xy位width/2,height/2.這樣一來就技巧的實現了對外層的操作轉化成了內層幾何中心的操作.

調整方法(二)動態調整坐標

其實注冊點的不同,產生的效果就是操作或的位置不同.那么根據不同的操作和注冊點的偏差,進行調整也能實現對注冊點的改變,而且這種方式更直接和方便.自己看類的結構就明白了.

package com.makyoo.geometry

{

//www.makyoo.cn??? QQ:84407979

//動態改變注冊點類

import flash.display.DisplayObject;

import flash.geom.Point;

//動態設置注冊點

public class DynamicRegistration

{

//需更改的注冊點位置

private var regpoint:Point

//更改注冊的顯示對象

private var target:DisplayObject

private var Height:Number

private var Width:Number

//首先要確定初始狀態

public function DynamicRegistration(target:DisplayObject,regpoint:Point,iWidth:Number=320,iHeight:Number=240)

{

Width=iWidth

Height=iHeight

this.target=target

this.regpoint=regpoint

}

//設置顯示對象的屬性

public function flush(prop:String,value:Number):void

{

var mc=this.target

//轉換為全局坐標

var A:Point=mc.parent.globalToLocal(mc.localToGlobal(regpoint))

if(prop=="x"||prop=="y")

{

mc[prop]=value-regpoint[prop]

}else if(prop=="scaleX" || prop=="scaleY")

{

if(mc[prop]>value){

//放大過程

mc.x+=((Width*(value+0.1))-(Width*value))/4

mc.y+=((Height*(value+0.1))-(Height*value))/4

}else{

//縮小過程

mc.x-=((Width*value)-(Width*(value-0.1)))/4

mc.y-=((Height*value)-(Height*(value-0.1)))/4

}

mc[prop]=value

}

else

{

mc[prop]=value

//執行旋轉等屬性后,再重新計算全局坐標

var B:Point=mc.parent.globalToLocal(mc.localToGlobal(regpoint))

//把注冊點從B點移到A點

mc.x+=A.x-B.x

mc.y+=A.y-B.y

}

}

}

}

----------------------------------------

動態改變MC注冊點————我能找到的,想到的

2009年04月07日 星期二 18:41

動態改變MC注冊點(一)--原理

轉自 藍色理想

無論是采用哪種辦法來動態改變MC的注冊點,其實質都是把MC變化之前的位置和變化之后的位置記下,然后算出某個點在這個過程中向什么地方變化了,然后把 這個點重置回原處,并沒有真正的象我們制作MC時那樣把那個小加號(注冊點)改了位置,也就是說,所謂的動態改變MC注冊點是一種修正方法,在視覺上使人 感覺MC的注冊點改變了。

為什么要談到MC變化之前,變化之后呢?因為沒有變化,我們是看不出來注冊點到底在哪,當MC縮放時,我們可以觀察到注冊點,最易觀察到注冊點位置的變化狀態是旋轉,下面就以旋轉為例,說說MC注冊點調整的原理。

具體解釋見http://yjbzl.blog.china.com/200903/4520670.html

實現代碼如下,創建MC,起名fang,當點擊MC時,它會以點擊點為中心進行旋轉

fang.addEventListener(MouseEvent.CLICK,rota);

var xx:Number;

var yy:Number;

var newxx:Number;

var newyy:Number;

function rota(e:MouseEvent) {

var mymc:MovieClip=e.currentTarget as MovieClip;

var mypt:Point=new Point(mymc.mouseX,mymc.mouseY);

xx=mymc.localToGlobal(mypt).x;

yy=mymc.localToGlobal(mypt).y;

mymc.rotation+=10;

//旋轉之后,剛才的點mymc.mouseX,y,相對于舞臺的全局坐標和旋轉之前不一樣了,有一個差值,我們就用這個差值把MC的位置調整一下。

newxx=mymc.localToGlobal(mypt).x;

newyy=mymc.localToGlobal(mypt).y;

fang.x=fang.x-(newxx-xx);

fang.y=fang.y-(newyy-yy);

}

在網上查到的一些改變MC注冊點的方法(二)利用DynamicRegistration 類一、類文件:

package {//動態設置注冊點

import flash.display.DisplayObject;

import flash.geom.Point;

public class DynamicRegistration {

//需更改的注冊點位置

private var regpoint:Point;

//更改注冊點的顯示對象

private var target: DisplayObject;

function DynamicRegistration(target: DisplayObject,regpoint:Point) {

this.target=target;

this.regpoint=regpoint;

}

//設置顯示對象的屬性

public function flush(prop:String,value:Number):void {

var mc=this.target;

//轉換為全局坐標

var A:Point=mc.localToGlobal(regpoint);

mc[prop]+=value;

//執行旋轉等屬性后,再重新計算全局坐標

var B:Point=mc.localToGlobal(regpoint);

//把注冊點從B點移到A點

mc.x-=B.x-A.x;

mc.y-=B.y-A.y;

}

}

}

二、這個類的使用方法:

import DynamicRegistration;

mymc.addEventListener(MouseEvent.CLICK,myfun);

function myfun(e:MouseEvent) {

var mypt:Point=new Point(e.currentTarget.mouseX,e.currentTarget.mouseY);

var myname: DynamicRegistration=new DynamicRegistration(mymc,mypt);

myname.flush("rotation",10);

}

改變MC注冊點的方法(三)rotateAroundInternalPoint這是一個靜態方法,開始沒搞清,以為是一個屬于某實例的方法,然后直接寫成MC.rotateAroundInternalPoint(參數,,,,,,),結果報錯,仔細看了下說明,public static function,靜態方法是屬于類的,不屬于實例。

這個算是最簡單的,不用管原理,直接給參數用就行了。

//代碼如下

import fl.motion.Motion;

var m:Matrix=new Matrix?? ;

fang.addEventListener(MouseEvent.CLICK,rota);

function rota(e:MouseEvent) {

fl.motion.MatrixTransformer.rotateAroundInternalPoint(m,e.currentTarget.mouseX,e.currentTarget.mouseY,10);

fang.transform.matrix=m;

}

不過關于這個Matrix,一點也不明白它。

結束語:同一個效果,可以有很多方法來實現,弄清原理最好,實在弄不清了,用現成的類也不錯。

動態修改MC的注冊點

引用地址:

文章地址:http://www.darronschall.com/weblog/archives/000054.cfm

下載地址:http://www.darronschall.com/downloads/DynamicRegistration.zip

演示:

Flash Player文件

使用方法:

import com.darronschall.DynamicRegistration;

// Assume there is an instance named square_mc on the stage that

// has the correct linkage as described above

var square_mc:DynamicRegistration;

// The square_mc has an original registration at 0,0 so

// let's change that to 10, 60 at runtime.

square_mc.setRegistration(10, 10);

// Now whenever we access a property of the square_mc that deals

// with the registration point, use a "2" after the property name...

// These are the available properties:

square_mc._x2 = 4;

square_mc._y2 = 7;

square_mc._rotation2 = 40;

square_mc._xscale2 = 140;

square_mc._yscale2 = 80;

// square_mc._xmouse2 is readonly

// square_mc._ymouse2 is readonly

核心代碼:

// special thanks to Robert Penner (www.robertpenner.com) for providing the

// original code for this in ActionScript 1 on the FlashCoders mailing list

dynamic class com.darronschall.DynamicRegistration {

private function DynamicRegistration() {

}

public static function initialize(target_mc):Void {

var p = _global.com.darronschall.DynamicRegistration.prototype;

target_mc.xreg = 0;

target_mc.yreg = 0;

target_mc.setRegistration = p.setRegistration;

target_mc.setPropRel = p.setPropRel;

with (target_mc) {

addProperty("_x2", p.get_x2, p.set_x2);

addProperty("_y2", p.get_y2, p.set_y2);

addProperty("_xscale2", p.get_xscale2, p.set_xscale2);

addProperty("_yscale2", p.get_yscale2, p.set_yscale2);

addProperty("_rotation2", p.get_rotation2, p.set_rotation2);

addProperty("_xmouse2", p.get_xmouse2, null);

addProperty("_ymouse2", p.get_ymouse2, null);

}

}

private function setRegistration(x:Number, y:Number):Void {

this.xreg = x;

this.yreg = y;

}

private function get_x2():Number {

var a = {x:this.xreg, y:this.yreg};

this.localToGlobal(a);

this._parent.globalToLocal(a);

return a.x;

}

private function set_x2(value:Number):Void {

var a = {x:this. xreg, y:this. yreg};;

this.localToGlobal(a);

this._parent.globalToLocal(a);

this._x += value - a.x;

}

private function get_y2():Number {

var a = {x:this.xreg, y:this.yreg};

this.localToGlobal(a);

this._parent.globalToLocal(a);

return a.y;

}

private function set_y2(value:Number):Void {

var a = {x:this.xreg, y:this.yreg};

this.localToGlobal(a);

this._parent.globalToLocal(a);

this._y += value - a.y;

}

private function set_xscale2(value:Number):Void {

this.setPropRel("_xscale", value);

}

private function get_xscale2():Number {

return this._xscale;

}

private function set_yscale2(value:Number):Void {

this.setPropRel("_yscale", value);

}

private function get_yscale2():Number {

return this._yscale;

}

private function set_rotation2(value:Number):Void {

this.setPropRel("_rotation", value);

}

private function get_rotation2():Number {

return this._rotation;

}

private function get_xmouse2():Number {

return this._xmouse - this.xreg;

}

private function get_ymouse2():Number {

return this._ymouse - this.yreg;

}

private function setPropRel(property:String, amount:Number):Void {

var a = {x:this.xreg, y:this.yreg};

this.localToGlobal (a);

this._parent.globalToLocal (a);

this[property] = amount;

var b = {x:this.xreg, y:this.yreg};

this.localToGlobal (b);

this._parent.globalToLocal (b);

this._x -= b.x - a.x;

this._y -= b.y - a.y;

}

}

相關日志

總結

以上是生活随笔為你收集整理的java调flash注册方法_FlEX FLASH对象注册点调整方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。