Flash 8 / Actionscript 2.0 – How do I draw dynamically in a custom class.
November 12, 2006 2:51 PM
Subscribe
Flash 8 / Actionscript 2.0 – How do I draw dynamically in a custom class.
First, I’m pretty new to Actionscript and I’m getting confused going between tutorials written for different versions.
I’d like to create a class that when instantiated draws a shape on the screen and tracks various properties. In an ordinary .fla file I can do something like:
this.createEmptyMovieClip('mybox',200);
mybox.lineStyle(0,0x00ff00);
mybox.lineTo(50,20);
mybox.lineTo(70,40);
So I’ve got the basics to drawing. So why can’t I do this:
class Thing extends MovieClip{
function Thing(){
this.createEmptyMovieClip("mything",200);
mything.lineTo(50,20);
mything.lineTo(70,40);
}
}
And instantiate it from my .fla movie. My understanding is that since Thing extends MovieClip it is a MovieClip, so I should be able to create an empty movie clip inside and then draw in that.
But it isn’t working. Can someone tell me what I’m doing wrong. I assume my problem is at a deeper level than just syntax, et cetera.
Note, I don’t want to create a symbol in the library and attach it. I want to do the whole thing programmatically.
posted by miniape to computers & internet (4 comments total)
class Thing extends MovieClip{
function Thing(){
var mc:MovieClip = new MovieClip();
mc = this.createEmptyMovieClip("mything",200);
mc.lineStyle(1);
mc.lineTo(50,20);
mc.lineTo(70,40);
}
}
Make sure you're remembering to set the Linkage... properties in the Library for the parent movieclip. Check export for actionscript and enter Thing as the AS 2.0 class.
The problem with your code was that you weren't specifying mything's container object. But this.mything won't work, since mything isn't created until runtime. When the file is compiled, it looks at the constructor function and can't figure out what mything is. But the createEmptyMovieClip method returns an instance of whatever movieclip it creates. My code catches that instance in a variable (mc).
posted by grumblebee at 3:10 PM on November 12, 2006