Quick Tips:Dynamic Class Linkage

From CASA Framework

Jump to: navigation, search

Instead of assigning classes to MovieClips in the IDE linkage settings you can use the attachMovieRegisterClass method in the MovieClipUtil class. This allows a single MovieClip to be used with multiple classes. There is also a great benefit when compiling with MTASC, because you no longer need to switch to the IDE to change or assign classes to MovieClips as long as they have identifiers.

Here is an example on how to use:

import org.casa.util.MovieClipUtil;
import com.example.MyClass;

var myMc:MyClass = MyClass(MovieClipUtil.attachMovieRegisterClass(MyClass, this, "libraryIdentifier", "myMovieClip_mc", 100, {_x:100, _alpha:75});

It’s a tad cumbersome but the flexibility and speed it allows is pretty powerful. The code behind it is the dead simple, but often unknown Object.registerClass method.

Personal tools