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

Reply via email to