adding and removing Enterframe handler on runtime

on initialize call :addEnterFrameCatcher()

removeEnterFrameCatcher() to stop enterframe actions on runtime

relistenEnterFrameCatcher() to resume enterframe actions on runtime

private var enterFrameCatcher:MovieClip;
private function enterFrameHandler(param1:Event) : void
{
// enterframe script
}
private function addEnterFrameCatcher(): void
{
enterFrameCatcher = new MovieClip();
if (enterFrameCatcher)
{
enterFrameCatcher.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}
private function removeEnterFrameCatcher() : void
{
if (enterFrameCatcher && enterFrameCatcher.hasEventListener(Event.ENTER_FRAME))
{
enterFrameCatcher.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
return;
}
private function relistenEnterFrameCatcher() : void
{
if (enterFrameCatcher && !enterFrameCatcher.hasEventListener(Event.ENTER_FRAME))
{
enterFrameCatcher.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
}

  1. Make sure you use Event.ENTER_FRAME and not FlexEvent.ENTER_FRAME. Im not sure what the difference is but I wasted about 2 hours on that one :@

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: