View Full Version : Go To Next Label: How to?
Hi,
I'm new to Flash and i'm struggling to achieve what i believe is a simple script. What i'm trying to do is the equivalent in Director's Lingo to this:
go next
(The movie jumps to the next labeled frame).
I want this kind of command because i have a finnished project, with many scenes and many keyframes (where the "action" of the movie is) on those scenes. Those keyframes are separated by different frames (sometimes 5 frames between them, sometimes 3, 2, 7...) and what i want is simple a way (like in Director) to make the user advance (and go back) to the next label with the same script applied to the buttons (instead of a unique script with the label name applied to each button).
So, in Director i use just that simple script to move to next label (marker in Director). What's the same thing in Flash?
Thanks.
xxneon
07-05-2007, 01:56 PM
you could create an array of labels.. and then just have a counter variable that is either incrimented or decrimented so it points to the right label on button press..
Thanks for the reply.
And how do i do that?
Can you give me an example of a script that could adreess the problem? I´m an actionscript-flash-newbie...
xxneon
07-05-2007, 06:41 PM
var labelArr:Array = ["label1","label2","label3"];
var currentLabel:Number = 0;
next_btn.onRelease = function() {
if (currentLabel < labelArr.length - 1) {
currentLabel++;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump back to the the beginning
currentLabel = 0;
gotoAndStop(labelArr[currentLabel]);
}
}
prev_btn.onRelease = function() {
if (currentLabel > 0) {
currentLabel--;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump to the end.
currentLabel = labelArr.length - 1;
gotoAndStop(labelArr[currentLabel]);
}
}
something like this would work if you have a next and a prev button on stage .. with instance names of next_btn and prev_btn .. it cycles through the array of frame labels .. and in my example if it reaches the last label .. it cycles back to the first label in array .. and visa versa for the previous button.. but you could have it pretty much do whatever you wanted it to do if you dont want it to loop back and forth ..
Thank you!
I'm gonna try that tomorrow with my project and i'll let you know if it worked (if not, it's for sure my ignorance...).
One more thing: My project has several Scenes (and timelines). Were do i place the code? On all timelines? And on every labeled frames?
Thanks again.
xxneon
07-06-2007, 01:28 PM
well... the 1st and 2nd line can go into frame 1.. but the button code might need to be adjusted depending on your layout and how your buttons are setup.
Hi,
I'm having trouble with this script. I placed the first 2 lines at the first frame of every scene and it gave me no errors when i checked the "Check Syntax" boutton in the script window.
Then i placed the code for the prev and next bouttons on the "prev_btn" and "next_btn" (the bouttons are placed in a single layer). When i hit the "Check Syntax" boutton, it came out this errors:
**Error** Scene=TÉCNICOS/Coloração, layer=Botões < >, frame=10:Line 2: Operator '=' must be followed by an operand
* * if (currentLabel < labelArr.length - 1) {
**Error** Scene=TÉCNICOS/Coloração, layer=Botões < >, frame=10:Line 1: Statement must appear within on handler
next_btn.onRelease = function() {
**Error** Scene=TÉCNICOS/Coloração, layer=Botões < >, frame=10:Line 3: Syntax error.
* * * * currentLabel++;
**Error** Scene=TÉCNICOS/Coloração, layer=Botões < >, frame=10:Line 2: Statement must appear within on handler
* * if (currentLabel < labelArr.length - 1) {
**Error** Scene=TÉCNICOS/Coloração, layer=Botões < >, frame=10:Line 4: Syntax error.
* * * * gotoAndStop(labelArr[currentLabel]);
Total ActionScript Errors: 5 Reported Errors: 5
I'm doing something wrong, for sure... Can you help me on this one?
Thanks
inhan
07-06-2007, 07:12 PM
xxneon's code goes to a layer in which next and previous buttons reside, not on any mc instances.
The entire code? With no changes (unless the label names)? And should i put it in the first frame were the bouttons start or on all frames of the timelines of the scenes?
(NOTE: the bouttons appear on several scenes. They should go prev/next through the scenes to the labeled frames).
inhan
07-06-2007, 08:57 PM
To the first frame where these 2 buttons exist. That is enough.
xxneon
07-07-2007, 12:47 AM
thx inhan for the assistance in this post :)
inhan
07-07-2007, 01:26 AM
Hope I haven't missed anything though :)
xxneon
07-07-2007, 01:31 AM
well i know in my previous posts i did say to him that the button code might need altering if he planned on adding the code onto the instance instead of in the timeline.. but hopefully what you helped him with helps..
Hi,
Thanks to both of you. I've been out for the weekend so i couldn't try the last tip.
So, i placed the code (as you typed it) in the first frame of the layer in which next and previous buttons reside, and into the first frame where these 2 buttons exist, as you both mention. The only thing that i changed was the name of the labels: instead of "label1","label2","label3"... i put the names of the labels in my .fla project.
It come up with this errors:
**Error** Scene=TÉCNICOS/Coloração, layer=Botões, frame=10:Line 4: Operator '=' must be followed by an operand
* * if (currentLabel < labelArr.length - 1) {
**Error** Scene=TÉCNICOS/Coloração, layer=Botões, frame=10:Line 5: Syntax error.
* * * * currentLabel++;
**Error** Scene=TÉCNICOS/Coloração, layer=Botões, frame=10:Line 6: Syntax error.
* * * * gotoAndStop(labelArr[currentLabel]);
Total ActionScript Errors: 3 Reported Errors: 3
What am i missing?
Hi,
Can you guys spot the errors? i dont know any way out except to put a single and unique code on every prev/next button pointing to the exact scene/frame label.
This one would save me a lot of pain...
Thanks.
xxneon
07-09-2007, 07:10 PM
if i cut and paste the code example i have in the thread into a blank new fla .. there is no errors ..
:eek: '=' ... does anyone see a '=' in that if statement .. why would you get an error for that if statement ... looks fine to me ..
maybe still the right side of the expression in ( )..
if (currentLabel < (labelArr.length - 1)) {
what version of flash are you using .. just curious?
I have Flash 8 (Mac OSX 10.3.9).
And when i paste the code into a blank new document, it still give those errors.
xxneon
07-09-2007, 07:34 PM
can you zip your fla and post?
I posted the empty .fla that still gives the errors.
(My original file is ±28MB. Its full of high quality images, a lot of scenes and its only intended to play from a computer. Its kind of a huge catalog and its only at this stage that the client wanted a slideshow option...)
xxneon
07-09-2007, 07:54 PM
var labelArr:Array = ["label1","label2","label3"];
var currentLabel:Number = 0;
next_btn.onRelease = function() {
if (currentLabel < labelArr.length - 1) {
currentLabel++;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump back to the the beginning
currentLabel = 0;
gotoAndStop(labelArr[currentLabel]);
}
}
prev_btn.onRelease = function() {
if (currentLabel > 0) {
currentLabel--;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump to the end.
currentLabel = labelArr.length - 1;
gotoAndStop(labelArr[currentLabel]);
}
}
strange.. well i took out the spaces before each line in the code and then formatted the code with tabs .. and now it works.. very strange.. just copy and paste the above .. and see if it works
xxneon
07-09-2007, 07:56 PM
very strange indeed .. like i said before if i copy and paste my original example .. no errors.. but the "exact code" in your fla generates errors.. and the only thing i can think of that might cause issues is when i posted my original example i just use 4 spaces for each indent for visual/formatting appearance.
No luck... It still gives the same errors. And all of them concerning de "next_btn" code, becuse the other part seems ok (in case i copy/paste all of it. If i just copy/paste the isolated btn code, the same errors are reported - even for the "prev_btn", if copied/pasted alone).
Is it possible for you to attach the .fla with the code? Maybe that way i can copy/paste the code without problems. But very strange, indeed.
:)
Finally, NO ERRORS!!!
As you mentioned the "spaces issue", i just removed all of the spaces at the beginning of the frases and it worked!
var labelArr:Array = ["label1","label2","label3"];
var currentLabel:Number = 0;
next_btn.onRelease = function() {
if (currentLabel < labelArr.length - 1) {
currentLabel++;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump back to the the beginning
currentLabel = 0;
gotoAndStop(labelArr[currentLabel]);
}
}
prev_btn.onRelease = function() {
if (currentLabel > 0) {
currentLabel--;
gotoAndStop(labelArr[currentLabel]);
}else{
//whatever you want .. like jump to the end.
currentLabel = labelArr.length - 1;
gotoAndStop(labelArr[currentLabel]);
}
}
Now i'm gonna try to apply this code to the actual project file and i let you know.
Thanks.
Hmm, now i'm having trouble with the code to make the project work.
I´ll try to explain as good as i can:
I have 12 scenes in the project; each scene with several frame labels. Not all frame labels are into the array code, because on those frame labels there are no prev/next buttons (they don't need to be in that "button-manual-slide-show"; they contain ambient photos, not products).
I only tested the project with the first 2 scenes (with buttons and code, obviously) and the entire code is applied to the buttons layer timeline.
What goes wrong:
When i test the .fla projector, the first frame label next button on scene1 goes to the first frame label on scene2 instead of going to the second frame label on scene1. The same with the first frame label next button on scene2 but on this one its even stranger: it goes to the first frame label on scene3 instead of going to the second frame label on scene2. The problem here is that the frame labels on scene3 ARE NOT yet on the array code; just the frame labels to scene1 and scene2.
Then, on frame labels 2, 3, 4, etc, (on scenes 1 and 2) sometimes the buttons just wont work (i couldn't find any logic relation between the "workable" and "non-workable" buttons). And the buttons that work wont go to the desired frame labels: sometimes they go to frame labels on scenes that are not at the array code and they don't follow the next/prev frame label order (i kept the scenes timeline frame labels order at the array code).
Any sugestions?
marsJ
07-10-2007, 12:11 PM
My advice would be don't use scenes. I have used them in the past and have found that they are very annoying to use and you will always run into problems with them. Try losing the scenes and amending your code accordingly...
At this point, with the project practicaly finnished, to get rid of scenes seems complicated. If i can't put that kind of solution to work, i think i rather "code" every single next/prev button to go to the specific scene/frame label.
What surprises me is the dificulty to achieve in Flash a very basic and simple thing that i used to do with Director with to words of code: "Go Next"...
xxneon
07-10-2007, 01:47 PM
any way i can see your file?
(My original file is ±28MB. Its full of high quality images, a lot of scenes and its only intended to play from a computer. Its kind of a huge catalog and its only at this stage that the client wanted a slideshow option...)
Its kind of huge! As you see, i didn't boder at all with file size and optimization (i didn't need that). Beside, i don't feel very confortable sharing a "internal" file from a client, if you know what i mean. And i feel very bad with it, because you guys are just trying to help me (and the rest of us) only for the sake of goodwill. But i'll check anyway if i can do it (if so, i believe i can't upload it through this forum, due to file size limitations. Should i up it to a file sharing service?).
In the meantime, i'll try to put/move scene2 into scene1 timeline to test the code as it is and to feel if its less trouble doing that or "coding" each individual button.
I tested with success and its not that trouble (well, it's much more trouble than the code presented here by xxneon but i was unnable to make it work) to code each button with this:
on(release){
gotoAndStop("SceneName", FrameNumber);
}
And a BIG THANK YOU for you people.
xxneon
07-11-2007, 01:22 PM
so did you finally get something to work then??? scenes are such a pain i think..
dompower
09-09-2007, 12:22 PM
I used the same script.
However, modifed, "gotoAndStop" into "gotoAndPlay", things work perfectly.
emersonb
06-04-2009, 10:15 PM
I have been following this post to try this code but I get the following error:
Location: Scene 1 Layer actions, frame 1, line 2 - Description: 1152: A conflict exists with inherited definition flash.display:MovieClip.currentLabel in namespace public.
I would like to animate a few frames and stop, animate a few frames and stop, etc... I would like pointer buttons on stage to go to prev or next LABEL.
Here is a snap shot of the file:
http://mydata.salve.edu/emersonb/post/next_label.gif
Here is the file (fla) I have been testing that does not work:
http://mydata.salve.edu/emersonb/post/prev_next_label.html
I am working with: Flash CS3, v9, action script 3, MacOS 10.4.
Thanks
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.