Skip to main content
Known Participant
Jul 14, 2011 1:26 AM UTC
Answered

choose a instance name randomly

hey, i want to make a random item visible

how can i do that

can you give me a sample code



thanks

This topic is closed to new replies. Start a new post to keep the conversation going.
Manno_BultCorrect answer
Inspiring
Jul 14, 2011 4:51 PM UTC

Hi fastboy,

[Possibly better in general AS3 discussions]

If you want a random item, you need to know of what group/list.

Keep an array of the items you create in order to later pick a random item out of that list:

//

myArray[ Math.floor( Math.random() * myArray.length ) ]

Otherwise (if items are not placed with code) you could check how many items exists as child of the container and use something like:

container.getChildAt( Math.floor( Math.random() * container.numChildren ) )

Kind regards,

Manno

1 reply

Manno_BultCorrect answer
Inspiring
Jul 14, 2011 4:51 PM UTC

Hi fastboy,

[Possibly better in general AS3 discussions]

If you want a random item, you need to know of what group/list.

Keep an array of the items you create in order to later pick a random item out of that list:

//

myArray[ Math.floor( Math.random() * myArray.length ) ]

Otherwise (if items are not placed with code) you could check how many items exists as child of the container and use something like:

container.getChildAt( Math.floor( Math.random() * container.numChildren ) )

Kind regards,

Manno

Translate