views:

104

answers:

2

It's really long to type in all the nesting objects in actionscript and it makes it difficult to rename objects.

Within Flash if I don't use external actionscript files, I can type in gunmovie.play(); and it works. Where gunmovie is the instance name of a MovieClip.

In an external actionscript file I have implemented the class MegaWeapon, but within its code I would have to know the entire object path to access things within the flash UI. Example:

// works
_root.menu.level1.toppanel.megaweapon.gunmovie.play();

// doesn't work
this.gunmovie.play();

// works, but not in external actionscript files
gunmovie.play();

In objective C there is: IBOutlet. I really hope Flash 9 has something similar. Absolute paths is not good.

I don't have my work computer beside me, so code is from memory.

Any simple way to access nested element?

+1  A: 

Well, you can create a reference to one of the lower clips in one place so if you do have to rename symbols it is less painful..

for example

var someClip:MovieClip = __root.menu.level1.toppanel.megaweapon;

So then you could do

someClip.gunmovie.play()

that should be the same exact thing as the first line in your code block but at least your object path can be defined in a single place instead of every time you use it.

Jasconius
+1  A: 

I recommend creating a function in MegaWeapon.as which points to the gunmovie.play(), this way you can call that instead.

As to hard coded paths, you could also have the MegaWeapon class register itself on the _root so your code would read:

_root.megaWeapon1 = this;

// On _root
_root.megaWeapon1.gunmovie.play();

You will need to watch out for collisions, though.

Christopher W. Allen-Poole
This will work. Typing it in in the builtin action editor, and then being able refer to it from outside. Does this trick have a name?
neoneye
Not that I know of. It's something I've done to get around some rather nasty Flash memory issues though.
Christopher W. Allen-Poole