Random color event
Random color event...
♥0 |
Line 58 |
Modified 2013-08-18 15:37:31 |
MIT License
archived:2017-03-10 04:18:33
ActionScript3 source code
/**
* Copyright Pelisalinet ( http://wonderfl.net/user/Pelisalinet )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/48sZ
*/
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 = 1;
public var _max:int = 999;
public var _color:String = "0x";
public var _uintColor: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);
}
public function rand(low:Number=0, high:Number=1):Number {
return Math.floor(Math.random() * (1+high-low)) + low;
}
}