-
extend MovieClip class
I would like to write some clips, but it seems do not work.
my test.as file:
class test extends MovieClip {
function test() {
this.lineStyle(1, 0xff0000, 100);
this.moveTo(50,50);
this.lineTo(111,111);
}
}
code in first frame script:
var aline;
aline = new test();
stop();
Why the clip does not draw anything!?
But if i modify the class definition as follows:
class test extends MovieClip {
var mc;
function test() {
this.mc = _root.createEmptyMovieClip( "mc1", 10);
this.mc.lineStyle(1, 0xff0000, 100);
this.mc.moveTo(50,50);
this.mc.lineTo(111,111);
}
}
evrything is ok.
So, must be create a property and assign a new mc to it,
or it possible to use simply the this. object for drawing ?
Thanks if someone could help.
-
Hi,
create a new movie clip and from the linkage options select export for actionscript. Give the clip a linkage identifier and fill in the name of your class in the AS2 class name field.
now you can create an instance of your class using attachMovie,
this.attachMovie("linkage_identifer", "newName", depth);
-
yes, you all right
with this method you should make a symbol in the library for every clips
i would prefer to maintain it only in actionscript code, if possible
-
you dont have to make movie clips for every class. You can use Object.registerClass to associate classes with library items dynamically as needed. Also, if you are simply using empty clips, an empty movie clip is automatically created for your class in your library with the linkage id __Packages.[full class name]. So you could just use that without defining any symbols yourself.
-
Dear Senocular !
It is interesting, seems to be a good idea.
A read the Object.registerClass docs before, but the workaround is not fully clear.
Should you write a short example, or reference an example source.
thanks: newbye
-
Using Object.registerClass isn't a workaround. It's the purpose of the function. What about it don't you understand?