开发者

AS3 Using a variable with Transform

开发者 https://www.devze.com 2023-01-04 07:40 出处:网络
I have a text field and a background and want to apply color using myColorPicker.Either the text field or background can be selected using

I have a text field and a background and want to apply color using

myColorPicker. Either the text field or background can be selected using

radioGroup1. When either radio button is selected the trace statement

traces the variable obj2Clr exactly. However when I use that variable

with Transform, I can't apply color. If I hard code and use the actual

object then it works.

Can I not use a variable with Transform or is something else missing?

My code is below:

var radioGroup1:RadioButtonGroup = new RadioButtonGroup("selObj");
bkg_rb.label = "Background";
text_rb.label = "Text";
bkg_rb.group = radioGroup1;
text_rb.group = radioGroup1;

var obj2Clr;//which object to apply color to

radioGroup1.addEventListener(MouseEvent.CLICK, getObj);
function getObj(e:MouseEvent):void {

if (bkg_rb.selected == true) { obj2Clr = "MovieClip(parent).design_mc.bkg_mc"; trace(obj2Clr); } else if (text_rb.selected == true) { obj2Clr = "MovieClip(parent).design_mc.info_txt"; trace(obj2Clr); } }

var colorTrans:ColorTransform = new ColorTransform();

var trans:Transform = new Transform(obj2Clr);
//var trans:Transform = new Transform(Movi开发者_运维技巧eClip(parent).design_mc.info_txt);
myColorPicker.addEventListener(ColorPickerEvent.CHANGE, changeColor);

function changeColor(event:ColorPickerEvent):void {
var myColor = "0x" + event.target.hexValue;
colorTrans.color = myColor;
trans.colorTransform = colorTrans;
trace("color selected is " + myColor);

}

Thanks for your help in advance:)

Debbie D


According to this code, obj2Clr is being initialized with a string literal?

For example, shouldn't this snippet:

if (bkg_rb.selected == true) { 
   obj2Clr = "MovieClip(parent).design_mc.bkg_mc";
   trace(obj2Clr);
}

be:

if (bkg_rb.selected == true) { 
   obj2Clr = MovieClip(parent).design_mc.bkg_mc; 
   trace(obj2Clr);
}

?


Thanks, yes I thought I had to use a string literal with Transform because tracing out the variable without quotes that make it a literal resulted in [object MovieClip] and [object TextField].

So I removed the quotes and Transform still is not receiving the new Transform object. Yet when I hard code (which was commented out in the above example) everything is fine. Any other area I should check?

Debbie D :)

0

精彩评论

暂无评论...
验证码 换一张
取 消