Archive for May, 2008

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);
}
}

Advertisements

access MovieClips Recursively

access MovieClips inside layers Recursively, the below is example to stop all movieclips recursively 🙂

private function stopMCRecursively(mc:MovieClip) : void
{
var ind:uint;
if (!mc)
{
return;
}
if (mc != this)
{
mc.stop();
}
ind = 0;
while (ind++ < mc.numChildren)
{
if (mc.getChildAt(ind) is MovieClip)
{
stopMCRecursively(mc.getChildAt(ind) as MovieClip);
}
}
return;
}