A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: adding actions to buttons

  1. #1
    Junior Member
    Join Date
    May 2003
    Posts
    3

    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

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  3. #3
    Junior Member
    Join Date
    May 2003
    Posts
    3
    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

  4. #4
    Member
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    82
    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?

  5. #5
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    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. -

  6. #6
    Member
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    82
    awesome!
    Thanks

  7. #7
    Junior Member
    Join Date
    Jun 2000
    Posts
    14
    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

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to make an if statement or switch function inside the function:
    PHP Code:
    btn1.addEventListener (MouseEvent.CLICKclickHandler);
    btn2.addEventListener (MouseEvent.CLICKclickHandler);
    btn3.addEventListener (MouseEvent.CLICKclickHandler);
    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. -

  9. #9
    Junior Member
    Join Date
    Jun 2000
    Posts
    14
    thanks for the help, so I need to change the trace to the goto action?

  10. #10
    Member
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    82
    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

  11. #11
    Junior Member
    Join Date
    Jun 2000
    Posts
    14
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center