Problem: Movie Clip contains just one frame
I'm a newbie at Flash, so started playing with a pretty standard code sample: one layer contains a movie clip with a flying rectangle, another layer has a button to control it. All scr开发者_开发知识库ipt code is in Main.as file. The rectangle was named square1 through the Property window.
Here is the problem: the constructor for Main has a line: square1.stop(); to prevent clip from playing, but it doesn't help - it plays. I know the constructor fires, because it has trace("stuff") in it. The code does check that the stage has been created.
What strange is that square1.currentFrame always returns 1, and square1.totalFrames returns 1 as well. The layer has 24 frames on the timeline. I tried a tween with just 2 keyframes, then converted whole tween into frames - same result. I mean, the thing is flying before my eyes, how can it be 1 frame???
I even added a listener: square1.addEventListener(Event.ENTER_FRAME, onFrameChange); The event fires all the time, i.e. the frames change, but currentFrame is still 1.
Also, tried to name individual frames and use square1.gotoAndStop("begin") and stuff like that. Nothing helps. I am really stuck with this stupid problem.
Your rectangle (square1) has only one frame. It is just a rectagnle (without modifications, twinning, etc...). Open it from the library and look on its timeline.
This object is placed onto the timeline of another MovieClip ("main", for example). And only that clip have several frames, but not the square1. You should stop "main" frame, like this.stop(), for example. Or you may create a new MovieClip ("movingSquare") with several frames which contains a moving square and place it on the "main" stage. You will have a folloing containment chanin: "main scene" (which may have only one frame) -> "movingSquare" (several frames with a square) -> "square1" (single-framed movie clip). And in that case you should call "movingSquare.stop()" to stop it from playing.
精彩评论