Flash actionscript 3.0: if you want to get the color randomly using actionscritp 3.0

if you want to get the color randomly using actionscritp 3.0

Posted by Sankar.G | Posted in | Posted on 12:45 PM

you can get the different color randomly using action script 3.0 & 2.0 also

AS 2.0:
var r:Number=random(256);
var b:Number=random(256);
var g:Number=random(256);
var box1:String=r.toString(16)+b.toString(16)+g.toString(16);
var box2:Number=parseInt(box1,16);
var box3:Color=new Color(movie_mc);

colors will always comes in alpha numeric & main color is red,green & blue so first we declare 3 variables and store the random number to that variable and we want to add the number and convert it to string using .tostring() funtion and base of the number is 16 because it is alphanumeric number and again we want to convert total string to a number using parseInt() function and store it in another variable now declare a new variable for the movie clip and set the color to the new variable
so if you press the button color will generate randomly


import flash.geom.ColorTransform;
var a:ColorTransform=movie_mc.transform.colorTransform;
function fun(e:Event)
var r:Number=Math.random()*256;
var b:Number=Math.random()*256;
var g:Number=Math.random()*256;
var total:String=r.toString(16)+b.toString(16)+g.toString(16);
var t1:Number=parseInt(total,16);

Comments (0)