在下面的代码中,如果单击“按钮”,将调用所有三个函数。 但在所有其他情况下,只会触发舞台事件。 为什么“精灵”事件没有被解雇?
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");
}
}
答案 0 :(得分:1)
解释是“在主类实例中忽略了矢量图形”(鼠标交互) 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
答案 1 :(得分:0)
这很奇怪...当您的测试类是文档类时会发生此行为。 如果您将测试嵌入到文档类中,则每个项目都按预期运行。我对这种行为没有解释。
package {
import flash.display.Sprite;
public class Main extends Sprite {
public function Main() {
var test : EventFlowTest = new EventFlowTest();
addChild(test);
}
}
}