View Full Version : Multiple actions with Buttons?
kejman
01-31-2005, 12:33 AM
Hey,
I am currently building a website for a school project using Macromedia MX 2004 Professional (my dad got it from work). I'm not a total newbie, but I'm not exactly advanced either. I've figure everything out so far, and it works well, but I have one problem. I want the button to link to a frame at the end of the scene (which is a scrollpane fading out), and then go to another scene. Here is an example of what I tried to do.
on (release) {gotoAndPlay(71);gotoAndPlay("Scene 1",40);}
I wasn't really expecting to succeed, but I figured I might as well try. So is there any way to have a button perform consecutive actions?
Any help would be greatly appreciated.
Duffman
01-31-2005, 12:50 AM
you could put the gotoAndPlay("Scene 1",40) in frame 71, so after the button goes there, its goes to "Scene 1",40.
but why are you going to one frame, then immediatly leaving to go to another?
godzilla
01-31-2005, 12:50 AM
It is possible to add multiple events to a single button, but it sounds like it would probably be easier if you added the gotoAndPlay("Scene 1",40) in the last frame of your scrollpane fading scene.
gotoAndPlay("Scene 1", 40);
Just put it in the frame. That should work.
kejman
01-31-2005, 12:55 AM
well what happens when I have multiple buttons, and I want each one to go to different scenes, but start out with the scrollpane fading out and then go to a new scene with that scrollpane fading in?
I was thinking about adding a bunch of different fading out sequences for each button and have that action at the end of each button, but that would increase file size and be a real pain. I was wondering if there was any way for buttons to do that.
Duffman
01-31-2005, 12:58 AM
i'd say make a variable in _root that holds the next scene information, then when you click a button, write the info to that variable, then when it finishes its fading, it reads the variable and goes to the repective scene.
kejman
01-31-2005, 01:40 AM
Sorry, but I didn't really understand what you just said.
Duffman
01-31-2005, 01:45 AM
ok, put a varibale in your main frame, which is the _root. you could actually make it easier with two variables if you want. lets call them gotoScene:String and gotoFrame:Number. so now when you click a button, have code in it that is similar to this: on (release){
_root.gotoScene = "Scene 1";
_root.gotoFrame = 40;
gotoAndPlay(71);
}
then in the frame at the end of your fading, have this:
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
kejman
01-31-2005, 01:53 AM
OK, I got that.
Thanks a lot for your help.
kejman
01-31-2005, 02:03 AM
Ok, I have a totaly unrelated and newbie question, but here it goes anyway. Now I want to insert a scene but I want it to go first (before my first scene).
Duffman
01-31-2005, 02:12 AM
i think you can just drag it up
kejman
01-31-2005, 02:16 AM
ok thanks, sorry for the newbie question.
kejman
01-31-2005, 03:12 AM
Now its not working. When I try to test the movie it gives me this error message.
**Error** Scene=Scene 1, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
**Error** Scene=Scene 2, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
**Error** Scene=Scene 3, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
**Error** Scene=Scene 4, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
**Error** Scene=Scene 5, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(_root.gotoScene, _root.gotoFrame);
Total ActionScript Errors: 5 Reported Errors: 5
and when you click on the buttons, no matter which button you click on, it just goes to the next scene. I can't figure out how to fix that error so it doesn't just go to the next scene. I don't understand why also.
**EDIT** Well, I fixed the error messages, and now no matter what button I click it takes me to the home page
Duffman
01-31-2005, 03:51 AM
whats in your button code?
hari-kj
01-31-2005, 03:53 AM
The problem is that you have to give the scene name in quotes. You can't store the scene name in a variable and pass it to the gotoAndPlay command. Pity !!
kejman
01-31-2005, 04:11 AM
whats in your button code?
on (release){
_root.gotoScene = "Scene 1";
_root.gotoFrame = 1;
gotoAndPlay(31);
}
and then the code at the end of the fading sequence at frame 31 is
gotoAndPlay("_root.gotoScene", _root.gotoFrame);
It goes to the home page because when the _root.gotoScene is in quotes, it doesn't read it as a variable, so it skips it and just goes to frame 1. It has to be in quotes though or else the syntax is wrong. I can't figure out how to fix it.
Duffman
01-31-2005, 04:36 AM
ahh ha! i just figured out how to do it. gotoAndStop(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
whats happening here is eval takes everything and smashes it together. so first i put a " in "'s. you need the \ so its the charctor " and not an actual ". (haha that was confusing). then you add the scene string, then another quote
kejman
01-31-2005, 12:14 PM
That almost works, but it gives me this error message and just goes to the next scene no matter what button you click again. Also, it doesn't matter if its gotoAndPlay instead of gotoAndStop right? Or does it?
**Error** Scene=Scene 1, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 2, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 3, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 4, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 5, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
Total ActionScript Errors: 5 Reported Errors: 5
CyanBlue
01-31-2005, 12:29 PM
You cannot use a variable for the scene name... Use a frame label instead... ;)
Dang... Forgot to add the file...
sceneNav1.fla -- normal Scene name
sceneNav2.fla -- scene name with the variable -- does not work
sceneNav3.fla -- label name
Duffman
01-31-2005, 04:57 PM
That almost works, but it gives me this error message and just goes to the next scene no matter what button you click again. Also, it doesn't matter if its gotoAndPlay instead of gotoAndStop right? Or does it?
**Error** Scene=Scene 1, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 2, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 3, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 4, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
**Error** Scene=Scene 5, layer=actions, frame=61:Line 1: Wrong number of parameters; eval requires exactly 1.
gotoAndPlay(eval("\"" + _root.gotoScene + "\"", _root.gotoFrame);
Total ActionScript Errors: 5 Reported Errors: 5
theres a missing ) gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
Duffman
01-31-2005, 05:03 PM
You cannot use a variable for the scene name... Use a frame label instead... ;)
Dang... Forgot to add the file...
sceneNav1.fla -- normal Scene name
sceneNav2.fla -- scene name with the variable -- does not work
sceneNav3.fla -- label name
i don't get 3. how is sceneA = "Scene 1"; not just a string?
also, how is _root.gotoAndStop("sceneC"); not trying to go to a scene named sceneC?
CyanBlue
01-31-2005, 06:56 PM
I am not going to the scene "Scene 3"... I am trying to go to the frame label "sceneC"... ;)
Duffman
01-31-2005, 07:12 PM
on (release){
_root.gotoScene = "Scene 1";
_root.gotoFrame = 1;
gotoAndPlay(31);
}
and then the code at the end of the fading sequence at frame 31 is
gotoAndPlay("_root.gotoScene", _root.gotoFrame);
so did that not work because of the _root?
kejman
01-31-2005, 09:24 PM
theres a missing ) gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
sorry, but it still doesn't work.
**Error** Scene=Scene 1, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
**Error** Scene=Scene 2, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
**Error** Scene=Scene 3, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
**Error** Scene=Scene 4, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
**Error** Scene=Scene 5, layer=actions, frame=61:Line 1: Scene name must be quoted string
gotoAndPlay(eval("\"" + _root.gotoScene + "\""), _root.gotoFrame);
Total ActionScript Errors: 5 Reported Errors: 5
I'm going to try the frame label thing and see if it works.
kejman
01-31-2005, 10:00 PM
no, the frame label thing doesn't work. Here's the code I was using.
On the button for scene A
on (release){var frameLabel:String="Scene A"
gotoAndPlay(31);
}
on the last frame of the fading out sequence.
gotoAndStop(frameLabel);
I've tried gotoandplay, it just sends the whole thing into a loop (it ignores all of the stop commands) until it goes back to the home page where it magically stops again, I've tried pretty much anything. It will go to the right scene, but it will only partially fade in. Then when I click a button it will become brighter. Then when I click another button the same thing happens except the text gets all switched around between scenes. It's really screwed up.
I have a feeling that its not the syntax, but its the way I used to frame label. I would attach it but it won't let me. Is there any place that you know of that I could upload it? Wait, I think I have a place.
*EDIT*: http://www.pb-addict.com/~modaccess/Kejman/flash/
there is the file, I uploaded it because it's hard to explain in words. Ignore all of the extra layers and play and stop commands. I was experimenting and I was too lazy to delete them.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.