PDA

View Full Version : button to play next labeled frame--mmm?


esophagus
07-23-2004, 04:22 AM
I want two buttons. One that skips forward to the next labeled frame and plays. The other that skips back two labeled frames and starts playing (this way it won't keep skipping back and playing current labeled frame)
I played with some scripts...don't laugh--I know it won't work..but you can get the idea of what I am trying to do:

Forward label button:

on(release) {
xFrameName=this._parent.square._currentFrameName + NextFrameName;
this._parent.square.gotoAndPlay(xFrameName);

}

previous label button:

on(release) {
xFrameName=this._parent.square._currentFrameName - PreviousFrameName;
this._parent.square.gotoAndPlay(xFrameName);

}


Thanks!!!

esophagus
07-26-2004, 02:48 AM
Has anyone figured this out yet?

deadbeat
07-26-2004, 06:16 PM
You can't get a frame label dynamically like that...ie: _currentFrameName is not a property you can poll...

You would have to manually create an array of all your frame labels first, then iterate through the array to determine the next frame to go to...

K.

esophagus
07-28-2004, 05:47 PM
could you give me an example of what you are talking about. I am not quite sure what you mean.


thanks.

destr3
07-28-2004, 06:17 PM
hi esophagus,
like deadbeat said, you probably want to create an array of your labels and then move through them using an array index variable....

you have labels: "a","b","c","d","e" for instance...

you would make an array:

var labels:Array = new Array("a","b","c","d","e");


you want to keep track of what label you're on so you would make an index variable (since there isn't a way to get the array pointer in actionscript):


var labelIndex:Number = 0;


then you could have two buttons with instance names "prev" and "next"...they would have the following actions:


prev.onRelease = function()
{
if (labelIndex > 0){ //if we're not at the first label
labelIndex--; //move the array pointer backward
gotoAndStop(labels[labelIndex]); //go to the appropriate label
}
}

next.onRelease = function()
{
if (labelIndex < (labels.length-1)){ //if we're not at the last label
labelIndex++; //move the array pointer forward
gotoAndStop(labels[labelIndex]); //go to the appropriate label
}
}


Make sense?
I have attached an .fla for you if you need it

chris( )

esophagus
07-28-2004, 07:48 PM
thanks for taking the time to explain this...I will poke around with the .fla you provided. This should get me in the right direction--thanks.

esophagus
07-29-2004, 01:03 AM
woo wee! I tweaked it a little for my needs but the code totally worked! Yes!

I tried changing the label items from letters to number, like "1", "2", etc..but it didn't seem to work. I can work with the letters but I am just curious why that didn't work. Thanks again.

destr3
07-29-2004, 01:17 AM
Hi esophogus,
It is most likely because when you say "gotoAndStop(labels[labelIndex])" - and labels[labelIndex] is a number, Flash is reading it as such...you want Flash to go to the *string* "1", but it is instead going to the *numeric* "1". You probably want to strongly type your array variables if you want them to be numeric like that (varname:String instead of just 'varname'). Haven't tried it but give that a shot!

esophagus
07-29-2004, 07:46 PM
You know, it works with the letters..so I'm not going to mess with it--thanks!

I was excited when I was able to have the next and prev buttons play for different .swf loaded in a mc. That was a big deal for me. The only thing is...the next and prev buttons still remember where they were for last .swf that was played. Is there a way to make the next and prev buttons check current variable before the action? kind of like a check currrent.frame

Right now if previous movie stopped at "g"...when next movie is loaded and the next button is pressed, movie goes to "h" instead of "b" even if the movie has just started. Does this makes sense?

Thanks.

craig

destr3
07-29-2004, 07:58 PM
You could probably just reset 'labelIndex' to 0 when loading the movie?

esophagus
07-30-2004, 02:54 AM
is this something I can script in the beginning of each new movie that is loaded?

thanks.

craig

esophagus
08-01-2004, 10:24 PM
I am trying to resest the var label index

this was my attempt..but it isn't working:

on (release){
Array.length = 1;
}

esophagus
08-01-2004, 10:40 PM
okay..I tried this:

var = i

didn'twork either..

any hints?

destr3
08-02-2004, 06:09 AM
oh no, I just meant do this:
labelIndex = 0;

...this help? sorry i've been gone for a coupla days :)

esophagus
08-02-2004, 03:40 PM
great.

does this little ditty go at the beginning of new loaded movies?


thanks!

craig

esophagus
08-04-2004, 04:35 PM
so to reset the current variable in the array:

originalArrayName.length = 0;

so in my case

labelIndex.length = 0;

is this right?

Do I place this in the begining of new loaded movie or in button button that loads the new movie?

Thanks.

esophagus
08-04-2004, 04:45 PM
labelIndex.length = 0;

is this right?

do I put this in each new loaded movie? Or, in a button that loads the new movie?

thanks

destr3
08-05-2004, 12:00 AM
Prolly on just the button that loads the movie, so that you only write it in one place, instead of having to write it in each and every movie...be lazy! haha

deadbeat
08-05-2004, 12:03 AM
You just want to set labelIndex=0, not labelIndex.length=0 though...

K.

esophagus
08-05-2004, 04:23 AM
thanks!