开发者

EXIT_FRAME bubbles up?

According to the Flash docs:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#

The Event.EXIT_FRAME constant defines开发者_StackOverflow社区 the value of the type property of an exitFrame event object.

Note: This event has neither a "capture phase" nor a "bubble phase", which means that event listeners must be added directly to any potential targets, whether the target is on the display list or not.

However when calling gotoAndStop on a child DisplayObject the EXIT_FRAME event is raised on it's container and there appears to be no way to stop it.

For example:

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

   this.addEventListener(Event.ENTER_FRAME, enterFrame);
   this.addEventListener(Event.EXIT_FRAME, exitFrame);
  }

  private function enterFrame(e:Event):void
  {
   trace("enter frame");
   c.setPercent(5); // this calls gotoAndStop()
  }

  private function exitFrame(e:Event):void
  {
   trace("exit frame");
  }

Output is:

enter frame

exit frame

exit frame

In Circle2 constructor I've tried this

this.addEventListener( Event.EXIT_FRAME, function(e:Event):void
{
 e.stopPropagation();
});


You can try to use capture phase and then call stopPropagation into it.

this.addEventListener( Event.EXIT_FRAME, function(e:Event):void
{
    e.stopPropagation();
}, true);

Note the true at the end of the addEventListener.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜