;

PDA

Click to See Complete Forum and Search --> : CS4, AS3 Buttons only work once


mgason
12-10-2008, 12:46 PM
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


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

sstalder
12-10-2008, 01:39 PM
Do you have this code on a single frame somewhere?

mgason
12-10-2008, 02:05 PM
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

sstalder
12-10-2008, 02:09 PM
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?

mgason
12-10-2008, 02:58 PM
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

mgason
12-11-2008, 05:46 PM
Bump
no answer yet
please check out the attached file

sstalder
12-11-2008, 09:32 PM
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.

mgason
12-12-2008, 11:54 AM
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

sstalder
12-12-2008, 12:32 PM
Yes there is, but you would have to take a complete different approach with your structure of the timeline.

UncleJezza
07-14-2009, 08:20 AM
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.

chalz
08-26-2009, 12:43 AM
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....

sstalder
08-26-2009, 08:06 AM
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?

chalz
08-27-2009, 02:47 PM
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...