Random color event Random color event... Pelisalinet forked:0favorite:0lines:61license : MIT License modified : 2010-12-16 04:38:55 Embed Tweet package { import flash.events.Event; import flash.text.TextField; import flash.display.*; import com.bit101.components.*; public class ColorRandomEventTest extends Sprite { private var colorRandom:ColorRandom; public var square:Sprite; public var topString:TextField; public function ColorRandomEventTest() { square = new Sprite(); addChild(square); colorRandom = new ColorRandom(1,999); square.graphics.lineStyle(3,colorRandom._uintColor); colorRandom = new ColorRandom(1,999); square.graphics.beginFill(colorRandom._uintColor); square.graphics.drawRect(0,0,100,100); square.graphics.endFill(); square.x = 30 square.y = stage.stageHeight/2-square.height/2; topString = new TextField(); topString.text = "The color is: " + colorRandom._color; topString.width = stage.stageWidth; stage.addChild(topString); new PushButton(this,0,stage.stageHeight-20,"Change",changeColor_fun); } public function changeColor_fun(e:Event):void{ square = new Sprite(); addChild(square); colorRandom = new ColorRandom(1,999); square.graphics.lineStyle(3,colorRandom._uintColor); colorRandom = new ColorRandom(1,999); square.graphics.beginFill(colorRandom._uintColor); square.graphics.drawRect(0,0,100,100); square.graphics.endFill(); topString.text = "The color is: " + colorRandom._color; square.x = 30 square.y = stage.stageHeight/2-square.height/2; } } } import flash.display.*; class ColorRandom { public var _min:int = new int(1); public var _max:int = new int(999); public var _color:String = new String("0x"); public var _uintColor:uint = new uint(0x0); public function ColorRandom(min:int=1,max:int=999){ _min = min; _max = max; _color += rand(min,max); _color += rand(min,max); _color += rand(min,max); _uintColor = uint(_color); return; } public function rand(low:Number=0, high:Number=1):Number { return Math.floor(Math.random() * (1+high-low)) + low; } } Code Fullscreen Preview Fullscreen box color, event, graphics, int, random, string uint, Math.max Math.min height drawRect endFill stageHeight beginFill lineStyle width text addChild TextField Math.floor stageWidth String Event Math.random uint Sprite Number