PDA

View Full Version : Variable scope and movie clips


SCook
12-24-2006, 12:28 PM
Hi all, Merry Christmas,

Is there a way to register variables created in a movie clip that then can be accessed directly by any clips that are children of that main one? Without using _global?

Here's the situation. I've created a custom combobox component. Not in the component developer, but just usihng As and mc's. The part of the combo that you click on an item when it's opened is four levels deep. And because I'd like to use multiple instances of this object, I'd like a way to make the variables scoped within it, but I can't seem to get child movie clips to gain access without making them global or by referencing them like: _parent._parent._parent. etc.

Hee is a visual of my structure.

Main Combo MC - id and text arrays crated
|
menu MC
|
Menu panel MC
|
content MC - where you click the item you want

I hope this makes sense, and I hope there might be a solution. Thanks gang.

inhan
12-24-2006, 12:42 PM
I'm not sure if whatI suggest would work unless you have a global variable, but rather than addressing it like _parent._parent... wouldn't it be possible o use _level0 / _level1 etc? (never tried though)

inhan
12-24-2006, 12:47 PM
I tried using _parent and _level0 for the variable and it does work, but I tried that while I have 1 frame both in the main timeline and the child timeline. I thing _global is there to make it more practical, that's all.

SCook
12-24-2006, 12:59 PM
Well, it's possible to get them to work, yes. That's not the issue. The issue is I want the whole combobox object and it's children to be treated as a single object, with all objects and variables within accessing from anywhere within. But I fear this is not possible :-)

inhan
12-24-2006, 01:41 PM
Sorry it seems I misunderstood your question. By the way, merry xmas to you too :)

pkny
12-26-2006, 06:39 AM
if i remember properly - as long as any variable you declare in the timeline that does not start with "var variableName" then the variable is "global" to all timelines.. with "var variableName" you're declaring the variable at that instance in time.. so therefore anything that tries to access it before that point in the timeline it will be returned as undefined object..

as for using _global / levels - i stronglu suggest using _parent. - you'll find that its less confusing later on.. or use _root.["mc_name"].["mc_name] if you must..