# Bars with random color

**URL:** https://forum.kirupa.com/t/bars-with-random-color/285531
**Category:** flash
**Created:** [April 1, 2009, 11:20pm UTC](https://forum.kirupa.com/t/bars-with-random-color/285531 "2009-04-01T23:20:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Hausnfranz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hausnfranz/32/2427_2.png) [@Hausnfranz](https://forum.kirupa.com/u/Hausnfranz)
#### Post date: [April 1, 2009, 11:20pm UTC](https://forum.kirupa.com/t/bars-with-random-color/285531/1 "2009-04-01T23:20:40Z")

</div>

Hey,

I am trying to sort out what is not working in my code that places bars across the screen with a random mix of pre-defined colors.

any help?

```auto

//pre-defined array to grab colors from
var myColors:Array = new Array();
myColors[0] = "0xec5b07";
myColors[1] = "0xd1c700";
myColors[2] = "0x3f93b3";
myColors[3] = "0xaf004e";

var i:Number = 0;

for (i=1; i <= 10; ++i) {
    
    trace("myColors.length "+myColors.length);
    trace("i is "+i);
    trace("color is "+myColors*);
    

//just placing creating empty MCs   
var containerMC:MovieClip = this.createEmptyMovieClip("container_mc"+i, this.getNextHighestDepth());

    //assigning each new MC with a color from the array
    this["container_mc" + i].colorTo(myColors[random(4)]);

    //giving each new MC some shape so you can see the color
    this["container_mc" + i]._width = 10
    this["container_mc" + i]._height = 50
    
    //moving each new MC over a bit to the right
    this["container_mc" + i]._x = this["container_mc" + i]._x + this["container_mc" + (i-1)]._x;

}

```
