補充用程式來控制
自己寫一個轉換16進制的函式SetColorValue(r, g, b)可以將r,g,b代入0-255的值,在處理上較為方便....
影格1:
var tempcolor:Color; //顏色物件
var tempR:Number = 255; //暫存R值
var tempG:Number = 0; //暫存G值
var tempB:Number = 0; //暫存B值
var Gstate:Boolean = false; //控制按鈕變數
var Bstate:Boolean = false; //控制按鈕變數
tempcolor = new Color("m1_mc");
tempcolor.setRGB(0xff0000);
影格2:
stop();
s1_btn.onPress = function() {
Gstate = true;
};
s2_btn.onPress = function() {
Bstate = true;
};
//利用變數累加與累減造成漸變
_root.onEnterFrame = function() {
if (Gstate == true) {
tempG = tempG+5;
tempR = tempR-5;
tempB = tempB-5;
if (tempG>=255) {
tempG = 255;
Gstate = false;
}
if (tempR<=0) {
tempR = 0;
}
if (tempB<=0) {
tempB = 0;
}
tempcolor = new Color("m1_mc");
tempcolor.setRGB(SetColorValue(tempR, tempG, tempB));
}
if (Bstate == true) {
tempB = tempB+5;
tempG = tempG-5;
tempR = tempR-5;
if (tempB>=255) {
tempB = 255;
Bstate = false;
}
if (tempR<=0) {
tempR = 0;
}
if (tempG<=0) {
tempG = 0;
}
tempcolor = new Color("m1_mc");
tempcolor.setRGB(SetColorValue(tempR, tempG, tempB));
}
};
//自訂設定顏色函式
function SetColorValue(r, g, b) {
var RGB = (r << 16) | (g << 8) | b;
return RGB;
}