PlayerTemplets.txt

AS3随机改变颜色代码

第一种方法:
var dow:Boolean;
stage.addEventListener(MouseEvent.MOUSE_DOWN,down);
stage.addEventListener(MouseEvent.MOUSE_MOVE,Move);
stage.addEventListener(MouseEvent.MOUSE_UP,up);
function down(evt) {
dow=true;
this.graphics.lineStyle(2,rgb(),1);
this.graphics.moveTo(mouseX,mouseY);
}
function up(evt) {
dow=false;
}
function Move(evt) {
if (dow) {
this.graphics.lineTo(mouseX,mouseY);
}
}
function rgb():uint {
return (Math.random() * 0xffffff + 0xff000000);
}

第二种方法:
package com{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
public class ColorRanomChg extends Sprite{
private var sp:CircleSprite = new CircleSprite(50,0x0099ff,"");
public function ColorRanomChg(){
addChild(sp);
sp.x=stage.stageWidth/2;
sp.y=stage.stageHeight/2; //舞台中央显示
sp.addEventListener("click",funColorChg); //执行单击变换颜色
}
private function funColorChg(me:MouseEvent):void{
var trans:ColorTransform = RandomColor(); //定义随机颜色转换
sp.transform.colorTransform = trans;
}
private function RandomColor():ColorTransform {
var red:Number = Math.random()*512-255;
var blue:Number = Math.random()*512-255;
var green:Number = Math.random()*512-255;
//使用随机颜色创建并返回ColorTransform对象
return new ColorTransform(1,1,1,1,red,green,blue);
}
}
}

你可能感兴趣的:(play)