views:

707

answers:

3

In frame 1 of a very simple flash file, I have the following code:

stop();
this.addEventListener(MouseEvent.CLICK, function(e) { gotoAndStop(5); });
gotoAndStop(10);

When I run the flash file, I expect that it would automatically step to frame 5 (ED. we think he means frame 10), but it does not. However, clicking anywhere does cause it to step to frame 5. The question is, why does gotoAndStop work from within the event handler, but not on its own on the main timeline?

Furthermore, if I put the exact same code on any other frame, gotoAndStop fires in that frame without having to be clicked. It appears gotoAndStop only fails to work on frame 1.

Edit / Answer: The answer to this one is really stupid, but I'll put it here in case anyone comes across it in the future. The resulting flash file was 500k, which was just big enough, even locally, to cause the gotoAndStop command to fire before the file was completely loaded. As a result, it couldn't possibly go to frame 5 or 10 because they didn't exist yet.

I knew I had to put in a preloader, but it was last on the list of things to do, and apparently, that came back to bite me in the ass. I added the gotoAndStop to an Event.COMPLETE handler and it works perfectly. Problem solved.

A: 

Could it be that you don't actually have a frame 10?

Iain
I have the frames specified. This is not an issue with missing frames or typos.
Chris
Accepted this answer because it's the closest to my problem, even if not exact. :)
Chris
A: 

You could try moving everthing along one frame? so don't put any code on frame 1, start from frame 2.

If you really want better control over Flash them I recomend coding in an external class file.

Iain
A: 

For me, after just copying and pasting the above mentioned code in a blank flash file, the click was not working at all but the 'gotoAndStop (10)' was working .. However, when i assigned click listener to 'stage' instead of 'this', the click started to work.

the code i used was below:

  • stop();
  • stage.addEventListener(MouseEvent.CLICK, function(e) { gotoAndStop(5); });
  • gotoAndStop(10);

But since you are having problems with the 3rd line (i.e. gotoAndStop(10)), and you are not facing problems on clicking, you might want to try this.

  • stop();
  • var reference :MovieClip = this as MovieClip;
  • reference.addEventListener(MouseEvent.CLICK, function(e) { reference.gotoAndStop(5); });
  • reference.gotoAndStop (10);

Tahir.