Skip to main content
October 16, 2011
Answered

Generate dynamic objects in Flash

  • October 16, 2011
  • 1 reply
  • 598 views

I'd like to use a conditional loop to generate objects dinamically and i'd like to know if it is possible to do this in Flash.

I try to explain better what i want to do; i have to let users to choose a number of balls to display on the stage, something like this:

var balls; //it contains the numbers picked by the user

if ( balls == 0) display nothing on the stage;

if ( balls != 0){

for (n < balls){

plot a ball on the stage

}

}

How it is possible to generate objects by looking on user decisions?

At the moment, i just know how to add a given number of objects on the stage and how to arrange them, but i do not know how to generate them depending on the user choices.

Can you help me?

I tryed to search on google, but i found nothing: what kind of tutorial should i read to accomplish this task?

Thanks to all.

This topic has been closed for replies.
Correct answer Ned Murphy

Since you say you know how to add them, I assume you mean you are familiar with the attachMovie method.

To do it based on some user input, it depends on what form of input that is, but if the user defines there to be "n" objects added, then you would use something to the effect of...

for(i=1; i<=n; i++){

   this.attachMovie(...etc...)

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
October 16, 2011

Since you say you know how to add them, I assume you mean you are familiar with the attachMovie method.

To do it based on some user input, it depends on what form of input that is, but if the user defines there to be "n" objects added, then you would use something to the effect of...

for(i=1; i<=n; i++){

   this.attachMovie(...etc...)

}

October 16, 2011

Very simply solution! Thanks!

But what about the absolute position of each object?

With attachMovie I can display them on the stage, but what i have to do if i want to locate each object in a different position?

Ned Murphy
Legend
October 16, 2011

If you look at the help documents there is an example there showing one way to do it, as part of the attachMovie parameters.  Otherwise, you can assign the _x/_y prperties after yo have called attachMovie