AS3 在 Transform 中使用变量
我有一个文本字段和一个背景,想要使用
myColorPicker 应用颜色。可以使用
radioGroup1 选择文本字段或背景。当选择任一单选按钮时,跟踪语句
将准确跟踪变量 obj2Clr。但是,当我将该变量
与变换一起使用时,我无法应用颜色。如果我硬编码并使用实际
对象,那么它就可以工作。
我不能在 Transform 中使用变量还是缺少其他内容?
我的代码如下:
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(父).design_mc.bkg_mc"; 跟踪(obj2Clr); } else if (text_rb.selected == true) { obj2Clr = "MovieClip(父).design_mc.info_txt"; 跟踪(obj2Clr); } 提前
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(obj2Clr);
//var trans:Transform = new Transform(MovieClip(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);
}
感谢您的帮助:)
Debbie D
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(MovieClip(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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据这段代码,obj2Clr 正在用字符串文字初始化?
例如,这个片段不应该
是:
?
According to this code, obj2Clr is being initialized with a string literal?
For example, shouldn't this snippet:
be:
?
谢谢,是的,我认为我必须在 Transform 中使用字符串文字,因为跟踪不带引号的变量使其成为文字,结果是 [object MovieClip] 和 [object TextField]。
所以我删除了引号,Transform 仍然没有收到新的 Transform 对象。然而,当我硬编码(在上面的示例中已注释掉)时,一切都很好。我还应该检查其他区域吗?
黛比 D:)
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 :)