A
A
Alexander Sharomet2016-04-08 16:29:57
Programming
Alexander Sharomet, 2016-04-08 16:29:57

How to add a different class each time?

Hello.
I have multiple classes Box, Box1, Box2, Box3 ... Box10.
I want to add these classes to the stage randomly using a loop.

for(var i = 0; i < col; i++){
  generator = Math.floor(Math.random()*10);
  box[i]=new Box+generator();
  addChild(box[i]);
}

this design does not work. How can this be implemented?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2016-04-08
@sharomet

For example, make the CreateInstance(generator) method
And inside it, make a switch case returning objects of various types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question