Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : static vars in class to keep track of instances


stephan.k
3/7/2006 10:32:46 PM
Hi Forum - my oop friends ---

So I have looked into the static vars to help all classes accessing movieClip
instances.

This is what I came up with:

The problem with my code is that when the movie starts the static variable
NAVIGATION_UI_PATH for example is undefined because the navigation has not been
attached to the root yet...

How can I circumvent this problem.

Thanks

stephan



class com.util.InstanceManager{
[...]

//mapnavigation user interface
public static var NAVIGATION_UI_LINKAGE:String = "mapnavinterface";
public static var NAVIGATION_UI_PARENT:MovieClip = _level0;
public static var NAVIGATION_UI_PATH:MovieClip =
NAVIGATION_UI_PARENT[NAVIGATION_UI_LINKAGE];
public static var NAVIGATION_UI_DEPTH:Number = 3;


}
GilFew
3/8/2006 12:24:00 AM
You've made the static properties public, so you can change them at any time.
Once you have instantiated the navigation clip, you can use something like

// replace myNavigatorMC with the instance name of your navigation movie clip
InstanceManager.NAVIGATION_UI_PATH = myNavigatorMC;

However, I'd recommend that you make your static properties private, and
provide get/set methods.

You could also create a single static method on InstanceManager called init(),
which takes arguments for each of your static properties and assigns them all
-- this has the advantage of not hardcoding values into your class, and lets
you control when the values are assigned as part of your application's
startup/initialise sequence.

Cheers,
Gil
AddThis Social Bookmark Button