AS3.0 颜色渐变
package { import flash.display.*; import flash.display.Stage; import flash.display.Sprite; import flash.display.Graphics; import flash.display.GradientType; import flash.utils.Timer; import flash.events.TimerEvent; import flash.geom.*; //==此项目是半成品 public class ColorTest extends MovieClip { private var thisMc:MovieClip; private var stageMc:Stage; private var timer:Timer; private var sp:Sprite; private var colors:Array=[0x00FF00,0xFF0000]; private var alphas:Array=[1,1]; private var ratios:Array=[0,255]; private var dif1:uint; private var dif2:uint; public function ColorTest(_stageMc:Stage,_thisMc:MovieClip) { thisMc=_thisMc; stageMc=_stageMc; init(); timer=new Timer(25); timer.addEventListener(TimerEvent.TIMER,onTimer); //timer.start(); dif1=0xFFFF00-0xFF0000; dif2=0x00FF00-0xFFFF00; } private function onTimer(e:TimerEvent) { } private function upDate() { sp=new Sprite(); } private function changeSp(colors:Array,alphas:Array,ratios:Array,num:int) { sp=new Sprite(); var matrix:Matrix=new Matrix(); matrix.createGradientBox(10,200,Math.PI/2,0,0); //是弧度不是角度; sp.graphics.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,matrix); sp.graphics.drawRect(0, 0 ,10, 200); sp.graphics.endFill(); sp.x=400; sp.y=300; thisMc.addChild(sp); while (thisMc.numChildren>2) { thisMc.removeChildAt(0); } } private function init() { var sp:Sprite=new Sprite(); sp.rotation=180 var colors:Array=[0x00FF00,0xFFFF00,0xFF0000]; var alphas:Array=[1,1,1]; var ratios:Array=[0,127,255]; var matrix:Matrix=new Matrix(); matrix.createGradientBox(10,200,Math.PI/2,0,0); //Math.PI/2是弧度不是角度; sp.graphics.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,matrix); sp.graphics.drawRect(0, 0 ,10, 150); sp.graphics.endFill(); sp.x=400; sp.y=300; thisMc.addChild(sp); } } }
posted on 2022-08-04 16:42 zqiang0803 阅读(66) 评论(0) 编辑 收藏 举报