# Random objects using math.random

**URL:** <https://forum.kirupa.com/t/random-objects-using-math-random/321919>\
**Category:** flash\
**Created:** [May 4, 2011, 9:54pm UTC](https://forum.kirupa.com/t/random-objects-using-math-random/321919 "2011-05-04T21:54:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pake](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@pake](https://forum.kirupa.com/u/pake)\
**Post date:** [May 4, 2011, 9:54pm UTC](https://forum.kirupa.com/t/random-objects-using-math-random/321919/1 "2011-05-04T21:54:41Z")

</div>

Hi, basically I want my engine to display one out of three objects at random.  
I thought I had figured it out but apparently not. A familiar error message appears, “A term is undefined and has no properties”. I’m sure it refers to the object I’m trying to spawn, however it rejects every object I refer to.  
Is my approach reasonable or should I scarp what I’ve got?

```auto

var spawnObject:Array = new Array("Object1", "Object2", "Object3");
                    var randomNumber:Number = Math.round(Math.random() * (spawnObject.length - 1));
                    if(spawnObject[randomNumber] == "Object1")
                    {
                    var newMC:MovieClip = new Object1();
                    }

```

Thanks in advance
