A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: What's wrong with my simple For loop?

  1. #1
    Member Mofo SwirlyKing's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    476

    What's wrong with my simple For loop?

    PHP Code:
    for (var i:int=1i<18i++){
        var 
    tFish = new "tiny"+i+"_mc()";
        
    tinyHolder.addChild(tFish);


  2. #2
    Senior Member Kirill M.'s Avatar
    Join Date
    May 2002
    Location
    Toronto, Canada
    Posts
    711
    I'm assuming that you have clips in your library with linkage class names set to tiny1_mc, tiny2_mc, and so on up to 18. The way you attach a clip from the library is:

    var libClip : Sprite = new MyLibraryClipsLinkageClassName();

    Since you have these things numbered and want to dynamically add them you gotta do something a bit tricky:

    PHP Code:

    import flash
    .utils.getDefinitionByName;

    ...

    for (var 
    i:int=1i<18i++){

        var 
    libClass : Class = getDefinitionByName"tiny"+i+"_mc" ) as Class;
        var 
    tFish Sprite = ( new libClass() ) as Sprite
        
    tinyHolder.addChild(tFish); 

    Last edited by Kirill M.; 11-21-2008 at 10:23 PM.

  3. #3
    Member Mofo SwirlyKing's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    476
    That worked perfectly! thank you so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center