  | |  | Extending MovieClip in AS2 with event handlers | Extending MovieClip in AS2 with event handlers
2004-02-24 - By Yechezkal Gutfreund
Back A week ago, chris at placticineweb wrote about problems with creating
extensions for MovieClip in AS2 and doing event handling. I have continued
to explore this and gotton the following to work. But there are some
oddities (noted below);
dynamic class TestSprite extends MovieClip {
var myName:String;
var xloc:Number;
var yloc:Number;
function TestSprite() {
trace( "creating sprite "+myName+ " @ ( "+xloc+ ", "+yloc+ ") ");
this.myLabel.text = myName;
_x = xloc;
_y = yloc;
}
function onPress() {
trace( "Selected: "+this.myLabel.text+ " @ ( "+_x+ ", "+_y+ ") ");
this.startDrag();
}
function onRelease() {
this.stopDrag();
}
}
* TestSprite is a MovieClip in the library that is exported for AS2
* TestSprite is linked to the TestSprite class
* TestSprite (the symbol) has a TextField called myLabel
I created three instances in the main timeline:
attachMovie( "TestSprite ", "Troop1 ", 100, {myName: "Troop 1 ", xloc:50,
yloc:50});
attachMovie( "TestSprite ", "Troop2 ", 101, {myName: "Troop 2 ", xloc:50,
yloc:150});
attachMovie( "TestSprite ", "Troop3 ", 102, {myName: "Troop 3 ", xloc:50,
yloc:250});
I have to use the this keyword in the constructor for if I did
myLabel.text = myName (then it would NOT set the textfield)
There is also a need for the this prefix in the onPress handler.
* I also have to use this.startDrag() or I will get syntax errors with just
startDrag().
However, one can freely test instance variables such as xloc and myName in
the envent handlers without the THIS clause.
* The code also works with Flash 6r65
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Dr. Yechezkal Gutfreund
Kesser Technical Group
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:105152
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |