Quick Tips:StatedMovieClip

From CASA Framework

Jump to: navigation, search

The StatedMovieClip class is extremely useful when you are needing to switch and (re)store MovieClip and Button EventHandlers.

After you attach a stated MovieClip:

MovieClipUtil.attachMovieRegisterClass(this, 'box', 'stated_mc', this.getNextHighestDepth(), org.casa.movieclip.StatedMovieClip);

You can define event handlers like normal:

this.stated_mc.onRelease = function():Void {
	trace('this is example one');
}

When you have a state you want to store just call:

this.stated_mc.createState('exampleOne');

Your state is stored and you can return to at any point! It records all MovieClip and Button event handlers (onEnterFrame, onMouseDown, etc, etc).

Now you can make another state:

this.stated_mc.onRelease = function():Void {
	trace('this is example two');
}

this.stated_mc.onRollOver = function():Void {
	trace('this state also has a roll over');
}

this.stated_mc.createState('exampleTwo');

Now you can switch between the states by calling:

this.stated_mc.switchState('myStateName');

If you ever want a blank slate or to remove event handlers call:

this.stated_mc.switchState('default');

For more information see the documentation in the StatedMovieClip class. There are also many classes that build on to this like LockingMovieClip (removes and restores all event handlers). This class is really useful for buttons that toggle.

Personal tools