views:

134

answers:

1

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 script 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.

A: 

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.

maxkar
Not sure your advice is correct. First, that rectangle had been converted to a symbol. Its class is displayed in the Properties windows as Movie Clip. Second, I just tried square1.parent.stop() and it gave me an error: "1061: Call to a possibly undefined method stop through a reference with static type flash.display:DisplayObjectContainer." What am I missing?
Doug
Just inspected the objects during the run-time. square1 is of type MovieClip. Its direct parent is an instance of Main class. The Main class simply extends Sprite. So, the only thing here with type of MovieClip is square1. I added more clips to the scene and all of them show totalFrames = 1. How can it be so?
Doug
Try to double-click on your square1 object (on the scene or in the librari) and look on it's timeline. How many frames there are? MovieClips may have only one frame.Also, make Main extends MovieClip and call MovieClip(square1.parent).stop();. Expcicit cast to MovieClip is required, because suare1.parent is a DisplayObject (it may be a sprite). Does now object stop moving?
maxkar
Thank you for helping me out. I didn't think it would work, but it did! Yes, square1 is a shape Symbol in the Library and its Timeline has 1 frame. When I did the explicit cast, it worked and stopped the movie. Now this is really weird. I thought when I added it to the scene and converted it to the MovieClip, it would become a movie clip. It is a movie clip, but with just 1 frame in it.Thanks again! Now I am going to change the code the way it intended to be, so that square1.stop() would work.
Doug