Frage

I had a Menu MovieClip with tweens running all the time and when the user clicks to start the game and when they do i add menu.visible = true; does this stop the menu from running in the background or does it just make it invisible and it will continue to run in the background and decrease performance?

War es hilfreich?

Lösung

All instances of MovieClip in memory (that is there are references to them or they haven't been collected by GC yet) are playing and consume some processor time for firing EnterFrame event or executing frame scripts. But it's still matter to set visible=false or remove them from stage to prevent their rendering, that can lead to consume even more resources.

And small bonus, I use this utility method that stops all animations before removing them from the display list, hope it helps:

/**
 * Stops all animations in the MovieClip and all its chilrend recursivly
 *
 * @param   target
 * @param   self stop animation in target or not
 * @param   isGoToAndStopFirstFrame move all clips to the first frame
 *
 */
public static function stopAll(target:DisplayObject, self:Boolean = true, isGoToAndStopFirstFrame:Boolean = false):void
{
    if (!target)
        return;

    var t:int = getTimer();
    var targetMovieClip:MovieClip = (target as MovieClip);
    if (self && targetMovieClip)
    {
        if(isGoToAndStopFirstFrame)
        {
            targetMovieClip.gotoAndStop(1);
        }else
        {
            targetMovieClip.stop();
        }
    }

    //stops all children in DisplayObjectContainer
    var targetContainer:DisplayObjectContainer = (target as DisplayObjectContainer);
    if(targetContainer)
    {
        for (var i:int=0; i<targetContainer.numChildren; i++)
        {
            var child:DisplayObject = targetContainer.getChildAt(i);
            if (child)
            {
                stopAll(child, true, isGoToAndStopFirstFrame);
            }
        }
    }

    // stops all states in SimpleButton
    var targetSimpleButton:SimpleButton = (target as SimpleButton);
    if(targetSimpleButton)
    {
        stopAll(targetSimpleButton.overState, true, isGoToAndStopFirstFrame);
        stopAll(targetSimpleButton.upState, true, isGoToAndStopFirstFrame);
        stopAll(targetSimpleButton.downState, true, isGoToAndStopFirstFrame);
        stopAll(targetSimpleButton.hitTestState, true, isGoToAndStopFirstFrame);
    }

    return;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top