[Flashcoders] AS2 vs. AS3: instantiate library symbols with a loop string concatenation
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: new sym1(); case 2: 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? -- -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS2 vs. AS3: instantiate library symbols with a loop string concatenation
for( var i:uint = 0; i30; i++ ) { var sym:MovieClip = new Item(); sym.name = sym+i; someContainer.addChild( sym ); } ... someContainer.getChildAt( nIndex ); etc. 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: new sym1(); case 2: 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? -- -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101 ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS2 vs. AS3: instantiate library symbols with a loop string concatenation
for(var i:uint = 0; i30; i++){ var sym:MovieClip = new (getDefinitionByName(Sym + i) as Class)(); parent_mc.addChild(sym); } Kenneth Kawamoto http://www.materiaprima.co.uk/ jonathan howe 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: new sym1(); case 2: 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? ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders