Reputation: 753
In the following code, if I click on the 'button', all three function will be called. But in all other cases, only stage event are fired. Why the 'sprite' event didn't got fired?
public class EventFlowTest extends Sprite
{
private var button:Sprite;
public function EventFlowTest()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN,stageMouseDown,false);
graphics.beginFill(0x11);
graphics.drawCircle(100,100,100);
addEventListener(MouseEvent.MOUSE_DOWN,spriteMouseDown,false);
button=new Sprite();
addChild(button);
button.graphics.beginFill(0xF1);
button.graphics.drawCircle(100,100,10);
button.addEventListener(MouseEvent.MOUSE_DOWN,buttonMouseDown,false);
}
private function spriteMouseDown(e:MouseEvent):void
{
trace("sprite");
}
private function stageMouseDown(e:MouseEvent):void
{
trace("stage");
}
private function buttonMouseDown(e:MouseEvent):void
{
trace("button");
}
}
Upvotes: 0
Views: 71
Reputation: 1118
The explanation is "Vector graphics ignored in main class instance" (mouse interactions) http://books.google.ru/books?id=gUHX2fcLKxYC&lpg=PA533&ots=cvPZ0qbQv8&dq=Vector%20graphics%20ignored%20in%20main-class%20instance&pg=PA533#v=onepage&q=Vector%20graphics%20ignored%20in%20main-class%20instance&f=false
Upvotes: 1
Reputation: 3548
that's strange... this behavior occur when your test class is the document class. If you embed your test in a document class, every thing is running as expected. I have no explaination for that behavior.
package {
import flash.display.Sprite;
public class Main extends Sprite {
public function Main() {
var test : EventFlowTest = new EventFlowTest();
addChild(test);
}
}
}
Upvotes: 0