-
[CS3] if why when function ?
hi
I'll try to keep this simple as I'm sure for those that understand AS it is?!?
anyhow I've worked in flash the same way for tooooo long and am trying to figure something and it has me stumped
I have 5 buttons on the stage - when click any of the buttons it triggers the same animation before going to content1, content2, content3, content4 or content5. For ages I've just repeated the animation for each transition i.e. play animation 1 > at the end of the animation an action gotoAndPlay1.
What I want to do is have one animation and an action on the release that says something like
if button1 release - play animation and goto content1
if button2 release - play animation and goto content2
and so on
without having to duplicate the content.
If you can help great - if you can point me to other threads or tutorials - equally as great
ta
-
Senior Member
Im unclear.. are you saying you DUPLICATED the same transition/animation and added a new line of code to play/load the different content? or you have a unique transition animation you want to play then the desired content?
in your SAME transition animation, you could use ONLY 1 animation..and have it call/load/start/play something liek this:
contentVar.gotoAndPlay();
them on each button:
PHP Code:
button1.onPress = function(){
contentVar = content1;
animation.play();
}
button2.onPress = function(){
contentVar = content2;
animation.play();
}
button3.onPress = function(){
contentVar = content3;
animation.play();
}
Last edited by whispers; 07-08-2008 at 01:27 PM.
-
hi whispers
thanks for getting back
the animation is on the timeline say starting at frame10 finish at frame20
buttons on same timeline
contnet1 would be frame25 - content2 would be frame30 and so on
so in the AS
I want to be able to say if I press either of button 1-5 it will play the animation from frame 10 - 20 and then goto the correct content so
What I have been doing is creating five animations and on the final frame of each animation having a goto("conetnt1"); command and so on
so what I want to have is just one animation and something that I imagine is like this
on release{
if
press button1
play (animation frame 10-20)
then gotoAndPlay ("content1")
}
obviously this is very crass but should better illustrate what I mean
cheers
J
-
Senior Member
ok.. I see... but first let me give you some suggestions..
try to stay way form timeline stuff/animations... if you have to...wrap it up in its OWN movieClip...
so for example..in your situation, you would have the transition/animation be its OWN clip.. so you can just tell it to play()..without jumping to frames and what not..as you will loose code/data once you leave to another key frame.
now for YOUR specific project.. lets say on frame 20 (should be the LAST frame of yourtransition animation....yes?) you have this code:
gotoAndPlay(someVariable);
now in each of you buttons
PHP Code:
button1.onPress = function(){ someVariable = "content1"; gotoAndPlay(10); //should be start of animation frame(s) }
-
ok
hi Whispers
thanks for taking the time
I have changed the structure a little on your advice - so putting content in individual MCs
so now
my buttons are located at _level0.fluid
these are part of the animation and they sit on frame 45 of the 'fluid' mc
so when I click a button it goes Plays the OUT animation to the end of the 'fluid' mc. On the last frame of the 'fluid' mc is another MC called 'content'
so what needs to happen is you click the button and it says gotoAndPlay("out"); // it plays the animation gets to the end of the of the 'fluid' mc timeline and and then tells 'content' mc to play content1, content2 etc
I tried the code above but wasn't sure on the someVariable part ?
sorry
J
-
aaahhh
actually whispers I think I've figured it out well almost
this is the code I have on my button
on (rollOver) {
_root.x = 1;
_root.dragger.caption.gotoAndStop("f02");
}
on (rollOut) {
_root.x = 0;
_root.dragger.caption.gotoAndStop(1);
}
bt_a.onPress = function(){
someVariable = "_root.fluid.content.news";
gotoAndPlay(46); //should be start of animation frame(s)
}
---------
this is the code I have on the final frame of the animation
_level0.bg.gotoAndPlay("tint");
gotoAndPlay(someVariable);
stop();
---------
this is the error message I am getting
Statement must appear within on handler
-
could the problem be...
could the problem be which version of AS
I am using AS 2.0 is this 3.0 ?
ta
J
-
Senior Member
hi.. I dont know AS3.. so youre safe.. this is all AS2..
the error you are getting is when you mix (mistakenly) put certain code syntax ON and object or ON the time line.
on(press){
//do whatever;
}
is the syntax that needs to and can only be applied DIRECTLY to an object.. (ie; select the object on stage..buttons..movieClip, whatever.. and paste the code DIRECTLY on that object) this, however, is NOT recommended.. it IS recommended you put ALL code in the TIMELINE.. on the FIRST frame.
this is why all objects have INSTANCE names... so you can put all code in one frame.. keeping it organized and centralized for easier review/edits..
so you need to decide, if you wan to put/keep the code ON the button itself..and NOT in the timeline..it should be lie this I believe:
PHP Code:
on (rollOver) { _root.x = 1; _root.dragger.caption.gotoAndStop("f02"); } on (rollOut) { _root.x = 0; _root.dragger.caption.gotoAndStop(1); }
on(press) { someVariable = "_root.fluid.content.news"; gotoAndPlay(46); //should be start of animation frame(s) }
if you want to keep it all on the timeline..
PHP Code:
bt_a.onRollOver = function(){ _root.x = 1; _root.dragger.caption.gotoAndStop("f02"); } bt_a.onRollOut = function(){ _root.x = 0; _root.dragger.caption.gotoAndStop(1); }
bt_a.onPress = function(){ someVariable = "_root.fluid.content.news"; gotoAndPlay(46); //should be start of animation frame(s) }
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|