Alternative way of instanciating a class without a library and without the __Package hack either.
Create a class with this function: function attachClassMovie(parentmc:MovieClip, className:Function, instanceName:String, depth:Number, argv:Array):MovieClip { // Create emptyMovieClip var new_mc:MovieClip = parentmc.createEmptyMovieClip(instanceName, depth); // Save classe prototype new_mc.__proto__ = className.prototype; // apply the constructor className.apply(new_mc, argv); // return new clip return new_mc; } var mc = attachClassMovie(parent_mc, com.Class, "child", 10, ["param1", "param2"]); 2006/7/7, Julian Bleecker <[EMAIL PROTECTED]>:
Ian, Those casting gymnastics definitely help — thanks a lot. Julian On Jul 7, 2006, at 9:27 PDT, Ian Thomas wrote: > On 7/7/06, Julian Bleecker <[EMAIL PROTECTED]> wrote: >> One other thing occurred to me on this topic, that might actually >> save the trouble of using a hash table, which AS direly needs. >> >> Is there a way to summon forth a class that's been instantiated in >> any of the ways described below, by name? >> >> In other words, if I've done this: >> >> for(var i:Number = 0; i < 12; i++) { >> Object.registerClass(symbolName,FooA); >> var clip:FooA=FooA(myMovie.attachMovie >> (symbolName,"anInstanceName_"+i,depth)); >> } >> >> And elsewhere, I want to summon forth these dynamically in another >> loop or otherwise (something I might normally do by stuffing the >> instances in a hash or map somewhere and using the name as the key) - >> can I do that in some fashion? Is there an AS idiom for obtaining a >> reference to a MovieClip (or other runtime object) by name? >> >> Julian > > Firstly, Actionscript does have the equivalent of a HashMap. > Everything derived from Object can be treated like so: > > var obj:Object=new Object(); > obj["someKey"]="Hello"; > trace(obj["someKey"]); // traces "Hello" > > The bracket access on an object actually accesses the properties and > methods of that object. > Hence: > var myClip:MovieClip = ...some movieclip... > trace(myClip._visible); > trace(myClip["_visible"]); // equivalent to the last line > myClip.doSomething(1,2,3); > myClip["doSomething"](1,2,3); // equivalent to last line. > myClip._y=20; > myClip["_y"]=20; // again, equivalent > > When you create/attach an instance of a MovieClip to a parent > movieclip, you are actually creating new properties on that parent > clip. > > So: > var myClip:MovieClip=someClip.attachMovie("Symbol","aNewClip",1); > trace(myClip==this["aNewClip"); // traces 'true' > > To get back to your original question, this means you can type: > var myClip:MovieClip=myMovie["anInstanceName_0"]; > > to retrieve your clip. > > HTH, > Ian > _______________________________________________ > 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
_______________________________________________ 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