Dirk
Dirk

Reputation: 3221

Adding to a stage in EaselJS. One works, one doesn't. Why?

The easiest way I can think of adding items to the stage is just to keep a list of items, and then add them all at once. But ...
This code works:

    stage.addChild(img1);
    stage.addChild(img2);
    stage.addChild(img3);
    stage.update();

This code does not. Why?

    var stageList = [img1, img2, img3];
    for (item in stageList){
        stage.addChild(item);
    }
    stage.update();

I gotta be doing something stupid, right?

Upvotes: 0

Views: 30

Answers (1)

Dhiraj
Dhiraj

Reputation: 33618

item will be index or property and not the value in the array. Access the value this way stageList[item] and the loop should look like this

for (item in stageList){
  stage.addChild(stageList[item]);
}

Read more about for...in loop

Upvotes: 1

Related Questions