currentTarget用法
[效果]
[代码]AS3中代码可用currentTarget指向
[效果]
0.swf
(2008-11-19 16:10:26, Size: 1 KB, Downloads: 2)
[代码]AS3中代码可用currentTarget指向
CODE:
var myText:TextField=new TextField;
addChild(myText);
for (var j:uint=1; j<4; j++) {
var _btn:Sprite=new Sprite;
_btn.graphics.beginFill(0xff0000);
_btn.graphics.lineStyle(1,0,100);
_btn.graphics.drawRect(0,0,80,20);
_btn.graphics.endFill();
addChild(_btn);
_btn.buttonMode=true;
_btn.x=j*100;
_btn.y=100;
_btn.name="按钮"+j;
_btn.addEventListener(MouseEvent.MOUSE_DOWN,ax);
_btn.addEventListener(MouseEvent.MOUSE_UP,sk);
}
function ax(event:MouseEvent) {
myText.text="你按下了 :"+event.currentTarget.name;
event.currentTarget.alpha=0.5;
}
function sk(event:MouseEvent) {
myText.text="你释放了 :"+event.currentTarget.name;
event.currentTarget.alpha=1;
}
[后记]在AS2中this就可以指向你按下的按钮
CODE:
this.createEmptyMovieClip("_btn",0);
_btn.beginFill(0xff0000);
_btn.lineStyle(1,0x000000);
_btn.moveTo(0,0);
_btn.lineTo(80,0);
_btn.lineTo(80,20);
_btn.lineTo(0,20);
_btn.lineTo(0,0);
_btn.endFill();
_btn._visible=0
for (j=1; j<4; j++) {
duplicateMovieClip("_btn", "_btn"+j, j);
this["_btn"+j]._x = j*100
this["_btn"+j]._y = 100;
this["_btn"+j].id=j
this["_btn"+j].onPress = function() {
trace("你按下了:按钮"+this.id)
this._alpha=50
};
this["_btn"+j].onRelease = function() {
trace("你释放了:按钮"+this.id)
this._alpha=100
};
}