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);
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
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.
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
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!
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?
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...
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?
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
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.