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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gotoAndStop (framelabel) not working correctly if label is a variable 1

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
Somebody please explain this to me. And quick, 'cause this needs to be done by 4pm today:) Or at least it did.

I have a scene with 9 keyframes. the last 8 have a frame label corresponding to a direction- NORTH, NORTHEAST, EAST, etc. The first one decides which direction to face.

I have the following code:
Code:
trace(directions[dir]);
gotoAndStop(directions[dir]);

the first line of code correctly prints out the name of the direction. the second line of code is supposed to bring me to the frame which has the corresponding frame label. Instead, it brings me to the frame IMMEDIATELY FOLLOWING that frame label. Let's say that frame 2 is NORTH (which has actionscript that traces the word "north"), and frame 4 is the next key frame, NORTHEAST, meaning that frame 3 will show whatever's in the NORTH framelabel as well. My movie goes to and stops at frame 3; it displays whatever's on the screen, but it doesn't display the trace from the actionscript in frame 2.

However, if I replace
Code:
gotoAndStop(directions[dir]);
with
Code:
gotoAndStop("NORTH");
everything works just fine; the movie goes to and stops on frame 2.

This is seriously whacked. Can anybody explain this to me? Can I get some flash experts to weigh in on this? I know I can work around this by accounting for this and having all the important stuff on the frame immediately following the framelabel, but any errors I leave in there now will be very hard to fix.. in a few days, there will be about 100 scenes just like this one, and I don't want to have to go through each scene to fix it.

Please, can I get a sanity check. Is this a flash bug, or is there a better way to do this?

I can't use frame numbers as I'm not sure which number will be where.. and of course if this is edited later on... eeek. That's a lot of updating of gotos. Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Using an array here?
Are you remembering that the first item of an array as the index of "0"?
What if you tried [dir-1]? Regards,

new.gif
 
Using an array here?
Are you remembering that the first item of an array has the index of "0"?
What if you tried [dir-1]? Regards,

new.gif
 
oldnewbie like I mentioned the trace is printing the correct string. and I'm aware that arrays start at 0.

this works:
Code:
gotoAndStop("NORTH");
this doesn't:
Code:
myLabel = "NORTH";
gotoAndStop(myLabel);

BigBadDave,
thanks for the thought but unfortunately I just tried a simple example like that. It works fine with one scene, but it screws up as soon as you add another scene which plays before it. If you still have a local copy of that, try the following:
1. add a second scene
2. have the scene come before "Scene 1"
3. give a non-random value to directions[dir] so you know what it's equal to beforehand
4. test

you should find that it's ending on the frame immediately following the frame it's supposed to end on. This happens regardless of whether there's a frame label there or not.

I've uploaded a very simple display of this at If you click on the swf, it's supposed to display "henry" and instead displays "james". Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
after a bit of testing, I found that the offset is equal to the number of scenes preceding it (where "it" is the scene where the actionscript is). if I have one scene in front of it, it goes to the frame immediately following the desired frame; if I have two, it goes to the frame which is two frames after it. if I have three.. you get the idea. surely this can't be desired correct behavior? Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
The offset seems to be the number of frames preceding your frame - I added a few frames to the example to check this.

For some reason the label is being converted into an absolute value from frame one of the root timeline instead of simply the scene it belongs to. I've scoured the technotes and there's no mention of this bug that I can find but it's definitely not the expected behaviour.

If you have the "goto" action in the first scene it does find the labelled frame correctly, maybe you can work around the problem that way? At least things would still be dynamic and not require huge re-editing if you change the file...

I tried this out and it works on your file.

Set up a custom function in frame one, scene one...

function goFrame(myLabel) {
_root.gotoAndStop(myLabel);
}

Then call this from anywhere in the movie sending it your target frame as a parameter like this:

goFrame("thomas");
 
I think the simple answer is :

add '_root' before your 'gotAndStop' eg :

_root.gotoAndStop (directions[dir]);

and it works fine Regards

David Byng

spider.gif


davidbyng@hotmail.com

while (Me < Drunk) {
Beer++
}
 
Thanks all, especially to wangbar and BigBadDave. wangbar, you get a star. Liam Morley
lmorley@gdc.wpi.edu
&quot;light the deep, and bring silence to the world.
light the world, and bring depth to the silence.&quot;
 
I forgot an important detail- first, the reason I couldn't execute the gotoAndStop from a different scene was because these aren't global frame labels, and I was relying on the fact that flash will check the current scene to see if the framelabel is there and then starts sequentially (or from the top, not sure). I could rename each NORTH label to NORTH1 and NORTH2 etc, or some scheme to keep them seperate, but there are over a hundred scenes and I don't want that much work for the person who's doing that section of it.

Is there any way to refer to it that might otherwise work, do you think?:) Liam Morley
lmorley@gdc.wpi.edu
&quot;light the deep, and bring silence to the world.
light the world, and bring depth to the silence.&quot;
 
I forgot an important detail- first, the reason I couldn't execute the gotoAndStop from a different scene was because these aren't global frame labels, and I was relying on the fact that flash will check the current scene to see if the framelabel is there and then starts sequentially (or from the top, not sure). I could rename each NORTH label to NORTH1 and NORTH2 etc, or some scheme to keep them seperate, but there are over a hundred scenes and I don't want that much work for the person who's doing that section of it.

Is there any way to refer to it that might otherwise work, do you think?:) Liam Morley
lmorley@gdc.wpi.edu
&quot;light the deep, and bring silence to the world.
light the world, and bring depth to the silence.&quot;
 
ak, posted twice. they actually don't have to be unique. you just get a warning if they're not. if there's a label called &quot;foo&quot; in scenes a, b, and c, and I'm currently in scene c, flash will bring me to &quot;foo&quot; in scene c. at least that's my experience, and I have yet to see flash documentation requiring frame labels to be unique across an entire movie. If there is such documentation, please lemme know, though.. I've looked through all the docs that come with flash, but I've hardly read everything there is to know. Liam Morley
lmorley@gdc.wpi.edu
&quot;light the deep, and bring silence to the world.
light the world, and bring depth to the silence.&quot;
 
Well, if you're not using unique labels, and your duplicate ones take you wherever you precisely want to go every time, then what's your problem? Regards,

new.gif
 
my problem is that there's a bug in flash. I think the title of the thread sums it up. The number of scenes (and frames in scenes) located before a given point should not affect what frame a frame label resolves to, nor should it matter if I use a string literal as opposed to a variable equal to that string. The problem is not, and has not been, with duplicate frame labels; they only limit the range of solutions.

I've come up with a work-around for the bug; thanks all for your assistance. Liam Morley
lmorley@gdc.wpi.edu
&quot;light the deep, and bring silence to the world.
light the world, and bring depth to the silence.&quot;
 
Great! Let's move on to discovering the next bug! Regards,

new.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top