Flash dispatchEvent fired twice
I have two frames with as3 code:
// frame1:
gotoAndPlay("show controls");
// frame2 - have movieclip with name slide0
// create menu items click listeners
for (var i:int = 0; i 开发者_如何学Python< slides.items.length; i++) // slides.items.length = 1
this["menu_item"+i].addEventListener(MouseEvent.CLICK, menu_item_click);
// click on the first menu item
this["menu_item0"].dispatchEvent(new MouseEvent(MouseEvent.CLICK));
// menu item click handler
function menu_item_click(e:MouseEvent):void {
this["slide0"].gotoAndPlay("show");
}
// in movieclip slide0 on frame with label "show"
trace("slide0 show begin");
And I get 2 messages "slide0 show begin". But when I click on menu_item0 I have one message.
Please help - where is a mistake?
MovieClip(this)["menu_item"+i].addEventListener(MouseEvent.CLICK, menu_item_click);
MovieClip(this)["menu_item"+i].dispatchEvent(new MouseEvent(MouseEvent.CLICK));
You can try it as well (slides.items.length
) yeine numbers you can use.
Hmm, I move dispatchEvent to frame3 and it's working fine.
// frame3
this["menu_item0"].dispatchEvent(new MouseEvent(MouseEvent.CLICK));
But the reason for such behavior is not clear...
精彩评论