import flash.utils.getDefinitionByName; for (var i:uint = 0; i < 30; ++i) { var sym:MovieClip = new (getDefinitionByName("sym" + i) as Class)();
// rest } On 3/4/08, jonathan howe <[EMAIL PROTECTED]> wrote: > Sorry - somehow triggered the send mail hotkey before I was finished: > > On Tue, Mar 4, 2008 at 3:25 PM, jonathan howe <[EMAIL PROTECTED]> > wrote: > > > > > > > > Imagine I have in my library a series of MovieClips with linkage > > identifiers like so: > > > > sym0 > > sym1 > > sym2 > > ... > > sym29 > > > > In AS2, if I wanted to create instances of each one (or perhaps decide > > which symbol to use based on XML data, for example), I could use a for > loop: > > > > for (var i:Number = 0; i < 30; i ++) { > > var new_mc:MovieClip = parent_mc.attachMovie("sym" + i, "sym" + i, i); > > // do stuff with clip > > } > > > > and create each symbol via passing a concatenated string as symbolName. > > > > Now, in AS3, I can't think of a way to do this efficiently. In our simple > > example, I can only think of the following: > > > > for (var i:int = 0; i < 30; i ++) { > > var sym:MovieClip; > > switch (i) { > > case 0: sym = new sym0(); > > > case 1:sym = new sym1(); > > case 2: sym =new sym2(); > > > ... > > } > > // do stuff with clip > > } > > > > > > Is there a more efficient way to do this in AS3? You can't really > > instantiate a class based on a stringname, can you? > > > > Was I doing myself a disservice by using this technique in AS2 anyway? > > > > Thanks, > > -jonathan > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- Cory Petosky : Lead Developer : PUNY 1618 Central Ave NE Suite 130 Minneapolis, MN 55413 Office: 612.216.3924 Mobile: 240.422.9652 Fax: 612.605.9216 http://www.punyentertainment.com _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders