This is a blog about Flash & AS by betaruce :-)



Calendar

August 2007
M T W T F S S
« Jul    
  1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31  

December 29, 2006

AS 3 tips: addEventListener

Filed under: Using Flash — betaruce @ 12:10 am

I was typing some AS3 one day and was a bit lazy. I did the following:

Actionscript:
  1. // I did not specify the object to add the event
  2. addEventListener(Event.ENTER_FRAME,some_fct);
  3. addEventListener(MouseEvent.MOUSE_MOVE,some_fct_2);
  4.  
  5. // but actually the above is equivalent to the following
  6.  
  7. this.addEventListener(Event.ENTER_FRAME,some_fct);
  8. this.addEventListener(MouseEvent.MOUSE_MOVE,some_fct_2);

The EnterFrame work, but not the Mouse event. This is because the mouse event does not respond to the timeline ("this" refers to the timeline).

Therefore, to make the mouse respond to the movement, I add the event to some object e.g. stage in my case.

Actionscript:
  1. this.addEventListener(Event.ENTER_FRAME,some_fct);
  2. stage.addEventListener(MouseEvent.MOUSE_MOVE,some_fct_2);

This is also true for Keyboard events.

• • •

2 Comments »

  1. What i struggle most is accessing stage is a null object. ie cant addEventListener on it -_-

    stage is not available until FlexEvent.ApplicationComplete in Flex

    waste a lot of time , frustrating

    Comment by Paul Wong — January 25, 2007 @ 6:09 pm
  2. This post and additional comment was greatly helpful to me. Thanks both of you.

    Comment by Keith H — May 3, 2007 @ 2:27 am

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss

cheap phentermine phentermine site phentermine effects online phentermine phentermine prescription buy phentermine online phentermine alternatives phentermine deit pill cheap generic phentermine order phentermine online Clenbuterol Phentermine online pharmacy phentermine buy phentermine weight loss pill Cialis Comparison Viagra Cheap Viagra Online Prescription generic viagra sale viagra online viagra viagra pill discount sale viagra Generico Impotencia Viagra viagra sildenafil citrate Xanax Online xanax order xanax valium versus xanax