I associate my AS2 classes to my library symbols through
Object.registerClass(LibraryID, ClassName).
Where:
LibraryID is an identifier in the FLA of a movie clip.
ClassName is a class that eventually extends a Movieclip.
I have a RegisterClasses singleton that is the first thing that is
called before I start my application manager. I
just change the code in RegisterClasses if I have a different version of
a particular class and if I compile with
MTASC I don't have to open up the FLA.
When attaching a movie clip I just use the attachMovie method and if I
wanted to pass arguments to the
constructor I would use the 4th argument and pass an object. The object
members are equivalent to
members of the class. For example passing {something:value} in the
method gives the class a member called
something when the constructor hits.
Just wanted to add my way too!
Ciao,
Rob.
Muzak wrote:
To be honest, I've always found that alot of hassle just to attach a movieclip.
I've never bought into the createClassObject/createObject-way used by the v2
component framework either.
If all you're after is the correct type when using attachMovie, do the
following.
private var customClip:CustomClip
private function onLoad() {
var mc:CustomClip = CustomClip(this.attachMovie("CustomClip", "customClip",
this.getNextHighestDepth()));
// calling non-existing method - throws error
mc.someMethod();
}
Doesn't get any easier than that if you ask me.
Of course, in AS3 attachMovie is gone and we can just use:
var mc:CustomClip = new CustomClip();
;-)
regards,
Muzak
----- Original Message -----
From: "Matthias Dittgen" <[EMAIL PROTECTED]>
To: <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, May 03, 2007 9:43 AM
Subject: Re: [Flashcoders] AS2: generating new instances dynamically?
This discussion is very interesting, so I would like to offer my
approach of attaching/construction of visual classes. I am open for
optimization hints.
I am using something like this:
1) THE CLASS EXTENDING MOVIECLIP
class com.path.MyVisual extends MovieClip
{
public static var _SYMBOL_NAME:String = "__Packages.com.path.MyVisual";
public static var _SYMBOL_OWNER:Function = MyVisual;
public static var _SYMBOL_LINKED =
Object.registerClass(_SYMBOL_NAME,_SYMBOL_OWNER);
private var __width:Number;
private var __text:String;
public static function create(target:MovieClip, initObject:Object,
depth:Number, name:String):MyVisual
{
depth = (depth!=undefined?depth:target.getNextHighestDepth());
name = (name!=undefined?name:"myVisual"+depth);
return MyVisual(target.attachMovie(MyVisual._SYMBOL_NAME, name,
depth, initObject));
}
public static function createInitObject(width:Number, text:String):Object
{
return {
__width: width,
__text: text};
}
private function MyVisual()
{
// I can use __width and __text here, if I like so.
}
}
2) THE "CONSTRUCTION" OF AN INSTANCE
I use the static create/createInitObject methods. The latter gives me
its signature when the editor supports code completion. This way, it
feels like a constructor and I get the correct type returned:
var mv:MyVisual = MyVisual.create(this, MyVisual.createInitObject(200,
"Hello World"));
Have fun,
Matthias
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com