Reputation: 11
I want to randomly set the color for a MovieClip in ActionScript 3. How would I go about doing so?
Upvotes: 1
Views: 2665
Reputation: 1
I know your post is old, but i just figured this out. You don't need to create your own color array, you can steal it from the colorpicker.
import fl.controls.*;
var _lineWeight:Number = 20;
var cp:ColorPicker = new ColorPicker();
var randomNumber:Number = Math.random() * cp.colors.length;
var drawing:Shape = new Shape();
drawing.graphics.lineStyle(_lineWeight,cp.colors[randomNumber]);
Upvotes: 0
Reputation: 1927
Example with some colors in a array:
var colorArray:Array = new Array(0xFFFF33, 0xFFFFFF, 0x79DCF4, 0xFF3333, 0xFFCC33, 0x99CC33);
var randomColorID:Number = Math.floor(Math.random()*colorArray.length);
var myColor:ColorTransform = this.transform.colorTransform;
myColor.color=colorArray[randomColorID];
myMovieClip.transform.colorTransform = myColor;
Change the myMovieClip to the instance name oof your movie clip, if you want you could add a click event to change the random colors.
Upvotes: 1