PDA

View Full Version : Basic actionscript question



LeiaGraf
June 5th, 2007, 08:54 PM
Hi, sorry to be a pain, but during a rather steep learning curve with Flash there's still one probably simple thing that I can never seem to grasp. I'm trying to be a good girl and learn all the right ways to do things (which isn't easy when everyone has a different idea of what that is!) but my main problem is keeping code on the main timeline, preferably in one nice neat little frame.

This is because when the code occurs, some of the objects don't exist yet (for example a button on the second frame of a movieclip that is stopped on the first frame). I understand that bit. My problem is how to fix that.

I've been doing the dodgy on some recent projects involving hiding the button in the first frame of the MC with alpha, so it does exist, but that just seems messy to me. I've seen a few bits around about declaring variables at the start (ie var myMC:MovieClip), but that doesn't seem to do anything either. I'm sure that's probably where my answer lies, but I can't seem to get it to work for me. Or is it just hitting the checkbox for "Export at runtime" or something similar?

I'd really appreciate a bit of a leg-up with this. It's driving me nuts!

Thanks heaps.

efnx
June 5th, 2007, 10:42 PM
You could declare the variable -
var myMC:MovieClip = new MovieClip(); before adding it to the display list, then when the time comes, use
addChild(myMC); to add the movieclip to the display list. You can set all the movieclip's parameters and everything before you add it too, so that's nice. Does that help at all?