0

for some reason in one instance i can't get goToAndStop(2) to go to and stop on the second frame of a movie clip, that has two frames, and it's loaded!

I'm adding the movieclip to the stage on the constructor function of a class. and then on the click of the button1 i am changing the frame to frame 2. and then back to frame 1 on the click of button2..

None of them work.....

But.. if set the movieclip to goto frame 2 on the constructor function then it starts up on frame 2, when i click the button1 it stays on frame 2 (as im telling it to goto frame 2) and then clicking on the button2 successfully changes it to the first frame. and then i can click on button1 again and it changes it to the second frame fine.

Remove the _movie.gotoAndStop(2) from the constructor function and none of it works again.

public function changeBackground($frame:int):void
{
    trace('gotoFrame', $frame);
    _movie.gotoAndStop($frame);
    trace('currentFrame',_movie.currentFrame);
}

button1 click output

gotoFrame 2
currentFrame 2

button2 click output

gotoFrame 1
currentFrame 1

So it says it is on the correct frame, but is displaying otherwise!

there is definatly only one instance of this class on the stage

rorypicko
  • 4,194
  • 3
  • 26
  • 43

3 Answers3

1

Ok first a little rant...

I have also found some seriously frustrating issues with gotoAndStop in AS3. It seems to have problems rendering the correct frame of a movie clip if there are more than a couple of instances of that movie clip on the stage. I can understand that sometimes the frame may not be rendered in time for code to reference objects on that frame, but surely after flash renders the next frame, all clips should show what is on the frame!!? I find it hard to believe that one of the fundamental concepts of flash - the timeline movie clip - seems to not work 100% in as3.

Now I hope a useful answer...

The only way I have managed to get round this is by using a source image movie clip class, (either hidden on the stage or just created in code from the library). I can then use gotoAndStop on only one movie clip, draw it using the BitmapData class as many times as required, and add these images to the display objects I need.

Ed Guertin
  • 21
  • 5
0

First, please remove the $ in your variables. They are not needed for readability and only slow you down.

Second, do not assume there is a bug in gotoAndStop. While it's possible, there are thousands, perhaps millions, of Flash games that use this method without issue. I don't say this to scold, but I want you to remember this as many programmers chase ghosts... thinking a bug is a language issue.

Since you say that the constructor changes the frame just find, I think that your _movie is not the same as the button. Try also changing the position of _movie to see if you're talking to the correct object.

Also, this problem might because stage isn't invalidating fast enough: AS3 - gotoAndStop with immediate action

Community
  • 1
  • 1
Jonathan Dunlap
  • 2,581
  • 3
  • 19
  • 22
  • `-1` For your first two paragraphs which aren't relevant. As for the first sentence, there's no disadvantage in using `$` and is the OP's own style which is perfectly fine (unless of course the project is to be released as a foundation for Flash Games or similar in which case everyone will be tearing their hair out). – Marty Jan 18 '12 at 02:20
  • @Marty, I disagree. Formatting is very important as it's the language of the expression being analyzed. The code is public as it has been shared here. It is important in any field to express one's problem correctly to your peers. – Jonathan Dunlap Jan 18 '12 at 02:30
  • i tend to usually use '$' prefix for vars being passed to a function, '_' for vars private to a function or class and no prefix for public vars, personal preference, im not sharing my code so it doesn't matter. and it turns out it was a problem with the particular version of the flex i was using to complile with FlashDevelop.. and quick update and it all worked fine, it was hit and miss on different objects whether it would actually gotoAndStop on frames or not..... – rorypicko Jan 19 '12 at 17:33
-2

i tend to usually use $ prefix for vars being passed to a function, _ for vars private to a function or class and no prefix for public vars, personal preference, im not sharing my code so it doesn't matter. and it turns out it was a problem with the particular version of the flex i was using to complile with FlashDevelop.. and quick update and it all worked fine, it was hit and miss on different objects whether it would actually gotoAndStop on frames or not....

axel22
  • 32,045
  • 9
  • 125
  • 137
rorypicko
  • 4,194
  • 3
  • 26
  • 43