A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: CS4, AS3 Buttons only work once

  1. #1
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127

    CS4, AS3 Buttons only work once

    Hi,
    I am trying to be good and move to AS3.
    I had all of my code working, then I moved all of my main movie timeline into a movie clip (body_mc)

    Main movie now has 1 frame.

    My body_mc has a navigation menu, one button is portfolio_bttn which takes you to that frame label. It persists through all frames of body_mc. This button works fine.

    I seem to have everything working except 4 buttons on the first frame of body_mc. They should all perform exactly the same function as portfolio_bttn. They exist only in frame 1.

    They work the first time you click one (any one).
    Navigate back to frame one of body_mc and all 4 buttons will no longer work. What am I doing wrong??


    here is my code which is in frame 1 of the main timeline
    Code:
    body_mc.portfolio_bttn.addEventListener(MouseEvent.CLICK, clickPortfolio);
    
    function clickPortfolio(event:MouseEvent):void {
      	body_mc.gotoAndStop("portfolio");    
    }
    //the 4 buttons making trouble
    body_mc.homeVid1_bttn.addEventListener(MouseEvent.CLICK, clickPortfolio);
    body_mc.homeVid2_bttn.addEventListener(MouseEvent.CLICK, clickPortfolio);
    body_mc.homeVid3_bttn.addEventListener(MouseEvent.CLICK, clickPortfolio);
    body_mc.homeVid4_bttn.addEventListener(MouseEvent.CLICK, clickPortfolio);
    thanks for any help
    mark

  2. #2

  3. #3
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Yes all of my code is on frame 1 of the main timeline, which is only 1 frame long.
    The only other thing in frame 1 at the moment is body_mc, which contains everything esle.
    thanks

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Would you be able to post your FLA file? Or an example FLA that does the same thing so we can see what your doing?

  5. #5
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    it is a layout mockup to show a client. So it consisted of png's from photoshop with minimal functionality.

    made for a nasty file size to post. so I stripped it down to just the smallest number of buttons and some comments.

    saved it back to CS3 just in case, far back as I can go.

    thanks heaps
    mark
    Last edited by mgason; 01-15-2009 at 03:14 PM.

  6. #6
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Bump
    no answer yet
    please check out the attached file

  7. #7
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Whats happening is when your body_mc goes to frame 2, it clears out those listeners because the objects are removed from the stage at that point, then re-added when you back to frame 1 in body_mc. One frame 1 though, you are not re-adding the listeners.

    I made the proper change for you.

  8. #8
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Hi,
    thanks!!
    I understand your explanation and solution and it works for me.

    I was wondering though, there is a movement to the idea of having all of your actionscript in 1 place. Is there a way this could be achieved from frame 1 of the main timeline?
    Thanks again
    Mark

  9. #9
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Yes there is, but you would have to take a complete different approach with your structure of the timeline.

  10. #10
    Junior Member
    Join Date
    Jul 2009
    Posts
    2

    Drop-down menu link only works once?

    Quote Originally Posted by sstalder View Post
    Whats happening is when your body_mc goes to frame 2, it clears out those listeners because the objects are removed from the stage at that point, then re-added when you back to frame 1 in body_mc. One frame 1 though, you are not re-adding the listeners.

    I made the proper change for you.
    Hey guys,

    I realise this thread is a wee bit old but it's the only one I could find that pertains to my problem! I seem to be having the exact same issue. The solution to the above problem wasn't actually written here (bummer for me!) but I'm hoping someone can provide me with it.

    I have a simple website with a menu bar containing 6 links. One of the links is a drop-down menu with another link inside. Everything displays properly (the drop-down animation etc.) but the link inside the drop-down only works if you click it:

    1) first
    2) directly after the home button (first link in the timeline) having first clicked another link in the menu - hope that makes sense?

    I'm sure the problem is only a small AS3 error but because I'm very new to it, I need help to fix it!

    Please help me if you can! (.fla attached)


    Many thanks,


    Jez.
    Attached Files Attached Files

  11. #11
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    Ya- I'm having issue with my buttons only working once. How about that example file that sstalder fixed up. I would like to get a look at that....

  12. #12
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    I probably removed the sample to free up space on my profile. Chalz are you able to post your own sample that is not working then I can take a look at it?

  13. #13
    Junior Member
    Join Date
    Aug 2009
    Posts
    2
    Thanks sstadler- I figured it out. I was trying to put all my script code on one keyframe as this seems like the recommended way to go. The movie had the ability to skip that keyframe and I was trying to load instances that were not set in the movie yet at the first frame. Once I distributed my scripts out over the time line so they showed up when they were being used it all worked fine. It seems messy, but it works...

  14. #14
    Junior Member
    Join Date
    Mar 2010
    Posts
    6
    hi guys i realise this thread is pretty old but I am having the same problem with the buttons only working once and I cannot understand how to fix it. As above I have all of the actionscript for the homepage on the first frame, and all of the buttons work fine the first time, but once I have navigated back they stop working. The strangest thing about this is that when i replace the buttons with ones drawn with the paintbrush they work continuously. How do I go about changing where my actionscript is to fix this?

    thanks in advance,

  15. #15
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    can you post a simple file with just the problem stuff for us to look at?

  16. #16
    Junior Member
    Join Date
    Mar 2010
    Posts
    6
    it wont let me upload it to here for some reason so ive hosted it here

  17. #17
    Junior Member
    Join Date
    Mar 2010
    Posts
    6
    This is a recreaton of what is going wrong with one of the buttons
    Attached Files Attached Files

  18. #18
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    Got your file from the link,
    have to go out to see client for a bit
    I will check it out and fix it in a few hours, so just forget it and move on to something else.
    Reason it would not let you upload here is size, I think the limit is 300k
    Mark

  19. #19
    Junior Member
    Join Date
    Mar 2010
    Posts
    6
    i really appreciate that man

  20. #20
    Senior Member
    Join Date
    Apr 2000
    Location
    Minneapolis
    Posts
    2,127
    This is a little goofy, but the error shows up because Other_btn gets removed in the timeline. When you click it, you go to a later frame (and other_btn ceases to exist).
    When a different button takes you back to frame 1, the first line in the actions layer adds an event listener to Other_btn. Other_btn doesn’t have time to initialize since it was deleted from the timeline. (basically the code executes faster than flash can add the button back to the stage)

    Yes, it’s a strange thing, but that’s why timeline code can get dicey.

    A better solution is to set the visible property. Like Other_btn.visible = false; Hide and show the navigation when it’s appropriate.

    if you plan on having a lot of buttons this could get a bit unwieldy. You could add and remove buttons with the code. If you need a slicker solution for more buttons let me know and we can plan something.

    file is attached using visible
    Attached Files Attached Files

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