Results 1 to 4 of 4

Thread: Simple button navigation in actionscript 3

  1. #1
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Unhappy Simple button navigation in actionscript 3

    In Version two the code looked like this:

    stop();
    home_btnone.onRelease = function(){gotoAndStop("home");}
    home_btntwo.onRelease = function(){gotoAndStop("about");}
    home_btnthree.onRelease = function(){gotoAndStop("contact");}

    -this works.

    On another thread I saw this example given given to describe trigger mouse event using actionscript 3 -but to display text.

    It looks like this:

    function eventResponse(evt:MouseEvent):void {
    output_txt.text = “Button was clicked!”;
    }
    button_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse);

    I tried to do this with it:

    function eventResponse(evt:MouseEvent):void {

    gotoAndStop("contact");}
    contact_btn.addEventListener(MouseEvent.MOUSE_UP,eventResponse);

    -I get no errors but it just keeps playing without responding to my button.

    -Also How do I set this up with more than one button?

    -some help greatly appreciated(the tutorials I find seem to cover AS 2-bummer) .

  2. #2
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    THIS WORKS -yes - I answered my own question -I hope this aids someone else -putting NUMBERS at the end of the function names did it.

    stop();


    function eventResponse1(evt:MouseEvent):void {
    gotoAndStop("one");}
    btn_one.addEventListener(MouseEvent.MOUSE_UP,eventResponse1);

    function eventResponse2(evt:MouseEvent):void {
    gotoAndStop("two");}
    btn_two.addEventListener(MouseEvent.MOUSE_UP,eventResponse2);

    function eventResponse3(evt:MouseEvent):void {
    gotoAndStop("three");}
    btn_three.addEventListener(MouseEvent.MOUSE_UP,eventResponse3);
    Last edited by evan; 03-24-2008 at 09:25 PM. Reason: Found the answer myself

  3. #3
    Join Date
    Oct 2009
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks Evan - just wanted to thank you for posting your answer because it did help me : )

  4. #4
    Join Date
    Jan 2008
    Location
    Near Chicago
    Posts
    247
    Thanks
    105
    Thanked 2 Times in 2 Posts

    Default

    yeah that was an old post when I was just starting out Glad it could help But I have one further suggestion, The "numbered" functions were just changing the names otherwise the error would be a duplicate function error(though I didn't know it at the time).

    Also, I like to structure my listeners nice and neatly first and then write my functions, the code is cleaner.
    Code:
    btn_one.addEventListener(MouseEvent.MOUSE_UP,eventResponse1);
    btn_two.addEventListener(MouseEvent.MOUSE_UP,eventResponse2);
    btn_three.addEventListener(MouseEvent.MOUSE_UP,eventResponse3); 
    
    function eventResponse1(evt:MouseEvent):void
     {
    gotoAndStop("one");
    }
    
    
    function eventResponse2(evt:MouseEvent):void 
    {
    gotoAndStop("two");
    }
    
    
    function eventResponse3(evt:MouseEvent):void
    {
    gotoAndStop("three");
    }
    you can also of course use
    Code:
    btn_one.addEventListener(MouseEvent.CLICK,eventResponse1);
    in order to have the button repond to being clicked rather than a MouseUp if you want.
    Last edited by evan; 10-23-2009 at 09:46 PM. Reason: update

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •