Actionscript 3 - First steps VII

      失落的学习 2005-10-26 9:20

Interactivity is the soul of real experience. How can we interact with our new friend Flash 8.5? In the old days we could add handlers like on(release){} or this.onRelease = function(){} to our MovieClip instances. In ActionScript 3 we have to use a way, which is similar to that of the v2 components - addEventListener.

As we learned before, we use a Sprite object now, instead of a MovieClip.


package {
import flash.events.Event;
import flash.events.MouseEventType;
import flash.util.trace;
import flash.display.Sprite;


public class Test extends Sprite {

public function Test() {
graphics.beginFill(0xff0000);
graphics.drawRect(0, 0, 100, 100);
graphics.endFill();

this.addEventListener(MouseEventType.MOUSE_UP, mouseUpListener);
}

public function mouseUpListener( evt:Event){
trace( "Test::mouseUpListener " + this + ":" + evt);
}
}

}


In contrast to the old addEventListener in Actionscript 2 we don't have to use Delegate.create to bind a function to the scope of a handler, this is done implicitely now.
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commenttime}{commentauthor}

{CommentUrl}
{commentcontent}