-
CS3 action script 3 for buttons
Hi,
I am using Flash CS3/ action script 3. I am trying to put action script on a button to move you to a different frame on the timeline. In MX 2004 I would have put
onPress{
gotoAndPlay("frame-name");
}
But this no longer works!
Some help would be much appreciated.
-
AS3 syntax is different from AS1 and 2. Let's say your movie clip is called "mc". Put the following code on a frame.
Code:
mc.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
function onMouseDownHandler(e:MouseEvent):void {
e.target.gotoAndPlay("frame-name");
}
-
im getting a similar problem....ive got a button instance name home_btn so i thought puttin this in your code would take me to frame 59 when i press the button
home_btn.addEventListener(MouseEvent.MOUSE_DOWN,on MouseDownHandler);
function onMouseDownHandler(e:MouseEvent):void {
e.target.gotoAndPlay(59);
}
im new to flash n cant work out why this wont work?....i get this error when i press the button in my movie
ReferenceError: Error #1069: Property gotoAndPlay not found on flash.display.SimpleButton and there is no default value.
at smokeshopnew_fla::MainTimeline/onMouseDownHandler()
ive got no idea wat that means..haha...any help would be appreciated tho
-
Senior Member
I have no expereince with AS3 yet.. but it seems that you are trying to move to frame 59 of the BUTTON (e's target)...
try to change the time line of something else instead..
-
you havent put the frame number in quotations ("59")
-
Hi,
I just want to ask for a code for actionscript3 in making a button that's ON CLICK, ANIMATES ONE OF THE OTHER BUTTONS ON STAGE ON CLICK AGAIN, STOPS THE ANIMATION OF THE BUTTON BEING ANIMATED.
tnx
-
One easier solution is to put the other button in a movieclip so you can fire the animation in the movieclip when you press the original button. It won't be in the button you want but it appears as if the button itself is being animated
-
Senior Member
Originally Posted by midas123
Hi,
I am using Flash CS3/ action script 3. I am trying to put action script on a button to move you to a different frame on the timeline. In MX 2004 I would have put
onPress{
gotoAndPlay("frame-name");
}
But this no longer works!
Some help would be much appreciated.
its not the program thats changed. its the actionscript level your using thats changed. allow me to explain.
see in flash mx you had actionscript 1 and 2. in actionscript 2 you didn't need to give buttons instance names you could just click it when it was on the stage and apply code directly to it.
but when adobe brought macromedia that all changed. because they soon released the "Creative Suite". your using the third program in that series hense the name "CS3". when they released this series they introduced Actionscript 3.
there were many changes but the one that matters in this case is the fact you can no longer apply code to buttons directly. instead you must write all code from the main timeline. if you want to write code the way you've described goto file > publish settings. then press swf and change to actionscript 2.
if you intend to keep using actionscript 3 this is how you fix your problem. click on the button and give it an instance name of say "btn". now press on the frame this button is on press F9 and write this code:
Actionscript Code:
/* this is how we write events now. MOUSE_DOWN is the same as saying onPress.
we must also link each eventListener to a function. we do this by writing the name of the function, which in this case is "pressed". and then in that function we link it to the event type of that listener which is in this case "MouseEvent". */
btn.addEventListener(MouseEvent.MOUSE_DOWN,pressed);
/* were i wrote "evt" it doesn't matter wrate you call it. its the event object. in some cases you may need to refer to it for your code. so you need to name it something.
people find it easier to name it after what it is. which is an "Event". so for that reason you'll see people write "e", "evt" and "event". */ function pressed(evt:MouseEvent){ /* do something.... evt.target.gotoAndStop("frame-name"); */ }
has this helped at all?
Last edited by x-death; 03-08-2012 at 07:14 PM.
-
Prid - Outing
Hi,
I just want to ask for a code for actionscript3 in making a button that's ON CLICK, ANIMATES ONE OF THE OTHER BUTTONS ON STAGE ON CLICK AGAIN, STOPS THE ANIMATION OF THE BUTTON BEING ANIMATED.
tnx
That's actually pretty easy. You just use a Boolean Variable, toggle its value, and execute codes accordingly [my_btn = your button | animation_mc = movieclip with animation]:
Actionscript Code:
import flash.events.MouseEvent;
var playVar:Boolean = false; animation_mc.stop();
my_btn.addEventListener(MouseEvent.CLICK, toggleAnimation);
function toggleAnimation(e:MouseEvent){ playVar = !playVar; if(playVar == true){ animation_mc.play(); } else { animation_mc.stop(); } }
Hope this helps
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
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
|