Skip to main content
Known Participant
July 14, 2011
Answered

choose a instance name randomly

  • July 14, 2011
  • 1 reply
  • 374 views

hey, i want to make a random item visible

how can i do that

can you give me a sample code



thanks

This topic has been closed for replies.
Correct answer Manno_Bult

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
July 14, 2011

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