Arcanelab Blog
text

AS3 joy and frustration In the past few weeks I’ve been digging into the realms of the…

AS3 joy and frustration

In the past few weeks I’ve been digging into the realms of the Actionscript world as much as I could. (And I was never as excited about any programming language before as I am about AS3.) I’ve been reading tons of documentations (primarily this one, several times), and still I have black spots even on pretty basic stuff.

For example, take this code:

package 
{
import flash.display.Sprite;
import flash.events.*;

public class Main extends Sprite
{

public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point

graphics.beginFill(0x7f7f7f);
graphics.drawCircle(300, 300, 300);
graphics.endFill();

addEventListener(MouseEvent.MOUSE_MOVE, handler);
}

private function handler(e:MouseEvent):void
{
trace(e);
}
}
}


Seems pretty trivial, eh? The problem is that if I attach an event-listener to the main class of the swf file (as I did in the example above), seemingly no MouseEvent will be dispatched to the handler. If I add the very same event-listener to the stage, the mouse events suddenly start to be delievered.

Please, somebody educate me, why?