movieClip not stopping always looping

 ̄綄美尐妖づ 提交于 2019-12-24 14:03:16

问题


I have a class that gets a movieClip and then using addChild adds it to be displayed. Problem is that I cannot play or stop it at all. Basically I can't interact with the movieClip.

Here is the code:

public function Avatar(movieClip:DisplayObject) //class constructor
{   ...
    avatarSprite = MovieClip(movieClip)
    addChild(avatarSprite);
    avatarSprite.gotoAndStop(1); //this is not working
    trace(avatarSprite.currentFrame) //always returns 1
    trace(avatarSprite.isPlaying) // returns false
    ...
    }

When I run the code the movieClip plays in a loop and doesn't stop as I expect it to. I am not sure what's the problem. As you can see I didn't do anything too complicated. Any idea what I am missing here please?

Thanks in advance

EDIT: As miguelSantirso pointed out. The problem is with the nested animations in the movieClip and not the actual code itself. Does anyone know how to stop nested animations from playing?


回答1:


This function will stop all nested movieClips (or play them if you pass false to the useStop parameter)

function recursiveStop(parentClip:DisplayObjectContainer, useStop:Boolean = true, gotoFrame:Object = null):void {
    var tmpClip:MovieClip = parentClip as MovieClip;
    if (tmpClip) {
        if (useStop) {
            (gotoFrame != null) ? tmpClip.gotoAndStop(gotoFrame) : tmpClip.stop();
        }else {
            (gotoFrame != null) ? tmpClip.gotoAndPlay(gotoFrame) : tmpClip.play();
        }
    }

    var i:int = parentClip.numChildren;
    while(i--){
        if(parentClip.getChildAt(i) is DisplayObjectContainer){
            recursiveStop(parentClip.getChildAt(i) as DisplayObjectContainer, useStop, gotoFrame);
        }
    }
}



回答2:


Check that there are not nested animations inside your movieclip. Pausing a MovieClip does not stop the internal animations.




回答3:


Instead of casting it to a movieclip, try handling it AS a movieclip.

avatarSprite = movieClip as MovieClip;

(considering the incoming movieclip IS actually a movieclip ofcourse...)



来源:https://stackoverflow.com/questions/11035344/movieclip-not-stopping-always-looping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!