PDA

View Full Version : My first post ever on kirupa (finally)...please be nice (AS3 question)



pix|xiq
July 21st, 2008, 02:53 PM
Hi everyone, I've browsed this site off and on for quite a while and finally making what I believe is my first post (unless i'm forgetting).

I've searched and searched and googled before finally deciding to pose this question, but I just can't figure this out.

What is the best way to get 3 buttons that are nested inside a movieclip to control the main timeline?

I know this MUST have been covered before and i'm just not doing a good job with my search, but there it is. Asked once again for you all lol

nortago
July 21st, 2008, 03:25 PM
Use your parent... ie parent.gotoandPlay(1); - but ideally, you'd have all your code on the first frame of your timeline on the main stage...

Enebreus
July 21st, 2008, 04:35 PM
Ok, you're going to hate me for this, but read this:
http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html

The Event Model is probably the most critical thing you NEED to learn in AS3. Once you understand it you'll be able to have a button announce that it's been clicked.

Seriously pix|xiq, look into it. Bang your head against it for a while, come back and talk about it. But you have to know the ins and outs of AS3 events if you're ever going to be proficient.

It took me a few weeks to really get REALLY comfortable, but it was well worth it.

The quick answer to your question is:
Your button should dispatch an event when it's clicked. Your parent clip should listen for that event, when it hears it it should go ahead and do it's sinful business.
Simple as that :D (sort of )

pix|xiq
July 21st, 2008, 04:59 PM
Use your parent... ie parent.gotoandPlay(1); - but ideally, you'd have all your code on the first frame of your timeline on the main stage...

oh yeah, well that's what the plan is (all the code on the main timeline's "code" layer).

pix|xiq
July 21st, 2008, 05:01 PM
Ok, you're going to hate me for this, but read this:
http://www.adobe.com/devnet/actionscript/articles/event_handling_as3.html

The Event Model is probably the most critical thing you NEED to learn in AS3. Once you understand it you'll be able to have a button announce that it's been clicked.

Seriously pix|xiq, look into it. Bang your head against it for a while, come back and talk about it. But you have to know the ins and outs of AS3 events if you're ever going to be proficient.

It took me a few weeks to really get REALLY comfortable, but it was well worth it.

The quick answer to your question is:
Your button should dispatch an event when it's clicked. Your parent clip should listen for that event, when it hears it it should go ahead and do it's sinful business.
Simple as that :D (sort of )

no seriously, i appreciate this. i'm going to read this entire thing (and hope it actually sticks for once). maybe the trick is reading it 3 times lol i donno.

nortago
July 21st, 2008, 07:05 PM
Agreed.. the event model is a pain in the ***, but it's such a huge part of as3

pix|xiq
July 22nd, 2008, 02:59 PM
Ok guys, I've read the Event Handling article at Adobe, I've experimented some, I get some of it (actually have taken 4 flash college courses and still find myself mystified too often) I've banged my head (and plan to continue doing so until i really grasp this stuff), and I'm also on a looming deadline.

Something is still being lost in translation for me, concerning this main issue (and I thought i had it answered for me about 2 thirds through that article).

i'd pull what's left of my hair out trying explain it to yall in type only, so i've uploaded the fla in its current form.

http://www.sendspace.com/file/tsls3i
(had to use sendspace because the file is 608 KB -- tisk tisk i know)

the code in question is on frame 500 ("home") of the top layer ("code Tre").
(note: i realize i eventually need to figure out how to get all my code onto 1 single frame, etc, etc, and that's what my plan is. at the moment though, i'm just trying to sort out one thing at a time and at least get it working in a rudimentary sense for the boss)

i commented it all out so you could test and see what the intro/home is supposed to sort of look like...when the code is active, things go HAYWIRE BABY!!!

it tells me "treLogo" is an undefined property, yet it has an instance name and i'm not sure what else it's looking for. aye

bless you folks for helping me

Enebreus
July 22nd, 2008, 03:52 PM
Ok, downloaded the .fla and got the code working.

BTW I'd never tried deep linking event Listeners like this:
treLogo.uWaste.addEventListener(MouseEvent.CLICK, clickHandler);
It might be useful in the future! Thanks.

Ok, ultimately your problem comes down to movie clip naming on the timeline.
Your treLogo movieClip is only being given an instance name on frame 500, but it's actually on the stage since Frame 1. So, to solve your current problem all you have to do is make sure that the treLogo has the same instance name every time it's on a keyframe. That'll get rid of your error! I got it working on my end so I don't think you should have too much trouble with it.

Now in terms of playing with it in the future: you might consider a more OOP approach to this. Your treLogo could have it's own .AS class. When a button inside of treLogo is clicked you could dispatch an event that bubbles up to your root. Then your main class would listen for that event and do something about it.
Or at least that's how I would do it, when it comes to OOP there are millions of ways to skin a cat... or pull the bark off a tree in this case :D

AS 3 is built to be based around classes and OOP. Although you can hack out timeline solutions to problems they're rarely elegant.

pix|xiq
July 23rd, 2008, 11:32 AM
first of all...THANKS! to both of you

2nd of all..."ARGHHH!!!" to the solution, since that's what i tried FIRST! (before i took the instance names back OFF some of the frames lol)...when i went "all frames" i must have missed one or something...all this time. lol figures. thanks

3rd: i TOTALLY agree with you about preferring an OOP approach. i'm just not *there* yet with my skills (and this is due asap). you're right though. i have to get past this learning curve.