dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: addChild in for loop

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    5

    addChild in for loop

    Hi, can someone tell me how to do it:
    [code=actionscript]

    private function init_mc(_container){
    _envir = new Enviroiment()
    for (var i=0;i<3;i++){
    var _newMC:MovieClip = new ball
    _container.addChild(_newMC)
    mcArray.push(_newMC)
    _newMC.x = 100*i

    _envir.init(mcArray[i],10-i*50,-100,0)
    }

    [/code]

    when i trace (_newMC) i have "instance5,instance7,instance9" but i want name of this mc,
    what i do wrong... only one mc is using _envir.init() why...

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to add:
    _newMC.name = "namehere"+i;

    Later you trace for _newMC.name.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Junior Member
    Join Date
    Jul 2007
    Posts
    5
    hi, i do it but it doesnt work

    _newMC.name = "ball"+i

    trace(_newMC.name)/// ball1,ball2,ball3

    but

    _envir.init(myArray[i]) /// only first index is known as [object ball]

    and only one ball is moving like it should... maybe put name of mc to array ?

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    trace (mcArray[i].name);
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Junior Member
    Join Date
    Jul 2007
    Posts
    5
    ok thx, and last thing

    _envir.init(mcArray[i].name,10 - i * 50,-100,0);

    and i want to put 3 different mc to this function

    TypeError: Error #1034: Type Coercion failed: cannot convert "ball0" to flash.display.MovieClip.

  6. #6
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You can try casting:

    MovieClip(mcArray[i].name)
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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