Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fast Forward button restarts movie

Status
Not open for further replies.

kdelacruz

Technical User
Oct 7, 2002
25
0
0
ES
In a Flash MX movie, I have a fast forward button with this On Release code
Code:
if ((_currentframe + 120) >= _totalframes)
{
	gotoandplay("exitscene","exit1");
}
else
{
	gotoAndPlay(_currentframe + 100);
}
I do not have my movie set to loop, and I have a stop(); in the "exit1" frame.
I put in the first part of the If statement because if I hit the ff button too close to the end of the movie, it would just restart the movie. But even with that code, if I click the ff button, say, 175 frames before the last frame, the movie still restarts. I don't think it's even getting to the exit frame I'm telling it to go to (I put a trace in that frame and got nothing)
If I click the ff button in the beginning or middle of the movie, or within 120 frames of the last frame, it works fine.

Can someone see the problem with my logic?

Thanks!
 
Is this code in a movie clip and are you actually targeting another scene ("exitscene") on the root level?

Regards,

cubalibre2.gif

I'm Bill Watson's biggest fan!
 
It's not in a movie clip -- everything in this .fla is on the same timeline. I do have 4 different scenes, though. The "exitscene" is its own scene, and directly follows the main scene where the fast forward button is.

 
Out of curiosity, have you tried labeling the first frame of your "exitscene" with an unique label such as exit1, targeting that labeled frame rather than the scene name itself, and adding _root to your path in your button's script?

Code:
if ((_currentframe + 120) >= _totalframes){
    _root.gotoAndPlay("exit1");
} else {
    gotoAndPlay(_currentframe + 100);
}

Also check your syntax, caps & all...

You might want to add some trace action to see if your first if statement is ever true...


Regards,

cubalibre2.gif

I'm Bill Watson's biggest fan!
 
Thanks for the ideas!
I went and put traces absolutely everywhere, and found out that the problem is where I say
Code:
gotoAndPlay(_currentframe + 100)

It's not adding the current frame number and the number 100, it's treating the frame number as a string.
If _currentframe = 473, _currentframe + 100 = 473100
Grrr.

Here is my code now
Code:
trace("frames before end: " + (_totalframes - _currentframe));
	
if ((_totalframes - _currentframe) < 120) {
	trace(&quot;currframe < 120 before end = &quot;+_currentframe);
	gotoAndPlay(&quot;exit1&quot;);
} else {
	trace(&quot;currframe > 120 before end = &quot;+_currentframe);
	trace(&quot;frame to goto: &quot; + _currentframe + 100);
	gotoAndPlay(_currentframe + 100);
}
In the trace statement where it subtracts the currentframes form totalframes, it treats them both as numbers and is correct.

Do you have any idea why it's treating them as strings elsewhere?
Know of any integer conversion functions? I see NumberToString in the Help, but not StringToNumber ... I'll keep looking tho.

Thanks!
 
Well you could probably use a variable, and that should work...

var my_var = _currentframe + 100;

And in your else...

gotoAndPlay(my_var);

Or use int(), Math.round() on your string...

Regards,

cubalibre2.gif

I'm Bill Watson's biggest fan!
 
Got it working... I will leave the solution here in case anyone else has this problem ...
I fixed the math problem. That actually didn't help. It tried to go to the correct frame number, but my original problem persisted -- sometimes having the movie restarted.

What it was doing was, if the target frame was 500, it was going to frame 500 OF SCENE 1 (the current scene), NOT of the overall movie.
In an swf file, all scenes are flattened onto one timeline, and any frame numbering is for the overall movie, so I assumed that the gotoAndPlay would work with this overall numbering scheme.

Then I saw a Macromedia technote at that explains the difference between gotoAndPlay and this.gotoAndPlay
So instead of using plain old gotoAndPlay, I tried
Code:
this.gotoAndPlay(mycurrframe + 100)

and it worked. It took into account the total number of frames in the movie, not just that scene.

The technote actually seems to state the opposite (that if you preface gotoAndPlay with &quot;this.&quot; that it should only take into account the frames in the current scene), but in my situation it worked the other way (?!?) I don't really understand it, but it works now!

I can't believe I've spent all day on a fast forward button!!

Thanks for all your help,
Kathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top