A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Please help with multiple button set-up code in action script 3

  1. #1
    Junior Member
    Join Date
    Apr 2007
    Posts
    14

    Please help with multiple button set-up code in action script 3

    Hi,

    I had my websites coded in actionscript 2 and since I have upgraded my computer, system and programs I have now lost all my coding in my websites and have to redo in actionscript 3. i am trying to do something pretty simple but my inexperience in actionscript 3 is creating a road block, Please help!!

    I have set up a site with various images as square. when clicked they each link to a different .swf. I have the timeline set up with my actions as layer 1 and my buttons as layer 2. I have put all the buttons on the same layer "buttons" the action layer I began as...


    btn_1.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
    function onClick(e:MouseEvent):void{
    navigateToURL(new URLRequest("SwirlFlowerLarge.swf"), "_blank"); // change "_self" to "_blank" if want to it open in other tab or window. More info in the links I wrote below.
    }

    btn_2.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
    function onClick(e:MouseEvent):void{
    navigateToURL(new URLRequest("DecorativeDkBlue.swf"), "_blank"); // change "_self" to "_blank" if want to it open in other tab or window. More info in the links I wrote below.
    }


    I am just showing code for the first 2 buttons. I get an error saying the line
    "function onClick(e:MouseEvent):void{" is a repeat however when I take it out the test file does not link to the second button only the first. Can you tell me what is wrong with my code please. I have a total of about 20 button links.

    I appreciate any help. Thank you

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Change the 2nd function name and the call in the event listener...
    Code:
    btn_1.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
    function onClick(e:MouseEvent):void{
       navigateToURL(new URLRequest("SwirlFlowerLarge.swf"), "_blank");
    }
    
    btn_2.addEventListener(MouseEvent.CLICK, onClick2, false, 0, true);
    function onClick2(e:MouseEvent):void{
       navigateToURL(new URLRequest("DecorativeDkBlue.swf"), "_blank");
    }

  3. #3
    Junior Member
    Join Date
    Apr 2007
    Posts
    14
    Thank you very much for responding! I will try this tonight when I get home from work and check back in.

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