-
adding actions to buttons
okay -- i know this is a newbie question.....
but when using actionscript3 (which i need for a flv palyer) i cannot add actions directly to the buttons.
can someone point me in the right direction of how to get actions on my buttons
i have 6 videos that i need to play and when i go to add actions it says"Current selection cannot have actions applied to it"
i an new to AS3 so any help would be great
thanks
cheers
-
Senior Member
Fortunately you cannot add actions any more directly, which gives headache to people who have to debug it.
Give your button a name and then add an eventlistener:
myButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
//function here
}
- The right of the People to create Flash movies shall not be infringed. -
-
okay -- i was going out of my mind thinking i was doing something wrong and couldnt figure out what. i got it to work now. something new to learn - again LOL.
thanks so much for your reply
cheers
-
So, say you have multiple buttons that lead to different places, would you need a different function for each one? Or is there a way to include parameters using EventListeners?
In other words, is there a way that multiple button objects can call the same function through their Eventlistener, but the function knows which object is calling it?
-
Senior Member
Inside the function you have
event.currentTarget
which will identify the the object which triggered the event.
- The right of the People to create Flash movies shall not be infringed. -
-
-
I seem to be a bit lost with Actionscript 3.0, I have searched and found how to add actions to a button,
btn1.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
gotoAndStop(1);
}
but need to add the action to multiple buttons, I tried this but it doesnt woork or look right, any help would be great.
btn1.addEventListener(MouseEvent.CLICK, clickHandler);
btn3.addEventListener(MouseEvent.CLICK, clickHandler);
btn3.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
btn1.gotoAndStop(1);
btn2.gotoAndStop(5);
btn3.gotoAndStop(10);
}
Thanks
Danny
-
Senior Member
You need to make an if statement or switch function inside the function:
PHP Code:
btn1.addEventListener (MouseEvent.CLICK, clickHandler); btn2.addEventListener (MouseEvent.CLICK, clickHandler); btn3.addEventListener (MouseEvent.CLICK, clickHandler); function clickHandler (event:MouseEvent):void { switch (event.currentTarget.name) { case "btn1" : trace ("button 1"); break; case "btn2" : trace ("button 2"); break; case "btn3" : trace ("button 3"); break; } }
- The right of the People to create Flash movies shall not be infringed. -
-
thanks for the help, so I need to change the trace to the goto action?
-
Yes.
Planning out functions using traces is just a good way to test that they've been written properly and will do what you want them to do. :P
-
great thanks guys, worked that out.
Danny
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
|