Mailing List
Home
Flash Pro
Extending Flash
Flash Macromedia Developer
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
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)