Category Archives: script

flash as3 random colour

import flash.display.Sprite;
import flash.events.MouseEvent;

var _num:Number = 0 ;
var j:Number = 0 ;
var _vlak:Sprite = new Sprite();
addChild(_vlak);

var collorArray:Array= [0x0182C1,0xA08853, 0x877342, 0xffffff,0x48851E,0x392C1C,0xEBF197,0x113F8C,0xF18D05,0xffffff,0xffffff,0xE54028,0xF18D05, 0x61AE24,0xE54028,
0xE54028,0xF18D05, 0xE54028, 0x660000, 0xCC0000, 0x839C86, 0x39C69E,0x21D630, 0xDDA947,0xB18675, 0x8B5A53, 0xD5E052];

changeBeeld();
function changeBeeld():void{

for (var i:Number = 0; i<400; i++){

var a:Sprite = new Sprite();
a.graphics.beginFill(collorArray[Number(Math.floor(Math.random()*collorArray.length))],1);
a.graphics.drawRect(_num*40,j*40,40,40);
a.graphics.endFill();
_vlak.addChild(a);

_num++;

if (_num > 19){

_num = 0 ;
j++;
}

}
}

_vlak.addEventListener(MouseEvent.CLICK, mouseClickHandler);

function changeColour():void{
for (var i:uint = 0; i < _vlak.numChildren; i++){
var my_color:ColorTransform = new ColorTransform();
my_color.color = collorArray[Number(Math.floor(Math.random()*collorArray.length))];
_vlak.getChildAt(i).transform.colorTransform = my_color;
}

}

function mouseClickHandler(e:MouseEvent):void{

changeColour();

}