访问函数作用域之外的影片剪辑对象
我有一个影片剪辑,其中有一个文本字段,然后里面有一个按钮。 当用户鼠标悬停在文本上时,我需要能够更改文本的颜色。 下面是代码片段。 如何从函数外部访问对文本字段的引用? 提前致谢。
私有函数createRows() { var containerMc:MovieClip = 行;
//Create Text
var myTxt:TextField = new TextField();
myTxt.htmlText = labelName;
myTxt.antiAliasType = AntiAliasType.ADVANCED;
myTxt.selectable = false;
//Create Symbol Format Text
var myTxtFormat:TextFormat = new TextFormat();
myTxtFormat.color = 0x000000;
myTxtFormat.font = font;
myTxtFormat.bold = "bold";
myTxtFormat.size = fontSize;
//Format text
myTxt.setTextFormat(myTxtFormat);
containerMc.addChild(myTxt);
//Create button
var btn:Sprite = new Sprite();
btn.graphics.beginFill(rowColor);
btn.graphics.drawRect(0, 0, width, height);
btn.graphics.endFill();
btn.alpha = 0;
btn.name = someName;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.MOUSE_OVER,testMouseOver);
containerMc.addChild(btn);
}
私有函数 testMouseOver(e:MouseEvent) { var myTxtFormat:TextFormat = new TextFormat(); myTxtFormat.color = 0xccff00;
var myText:TextField = new TextField;
myText.htmlText = e.currentTarget.name;
myText.setTextFormat(symTxtFormat);
}
I have a movie clip that has a text field and then a button inside that. I need to be able to change the color of the text when user mouse hovers over the text. Below is the code snippet. How do I access a reference to the Text field from outside the function? Thanks in advance.
private function createRows()
{
var containerMc:MovieClip = row;
//Create Text
var myTxt:TextField = new TextField();
myTxt.htmlText = labelName;
myTxt.antiAliasType = AntiAliasType.ADVANCED;
myTxt.selectable = false;
//Create Symbol Format Text
var myTxtFormat:TextFormat = new TextFormat();
myTxtFormat.color = 0x000000;
myTxtFormat.font = font;
myTxtFormat.bold = "bold";
myTxtFormat.size = fontSize;
//Format text
myTxt.setTextFormat(myTxtFormat);
containerMc.addChild(myTxt);
//Create button
var btn:Sprite = new Sprite();
btn.graphics.beginFill(rowColor);
btn.graphics.drawRect(0, 0, width, height);
btn.graphics.endFill();
btn.alpha = 0;
btn.name = someName;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.MOUSE_OVER,testMouseOver);
containerMc.addChild(btn);
}
private function testMouseOver(e:MouseEvent)
{
var myTxtFormat:TextFormat = new TextFormat();
myTxtFormat.color = 0xccff00;
var myText:TextField = new TextField;
myText.htmlText = e.currentTarget.name;
myText.setTextFormat(symTxtFormat);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您知道,如果文本是一个按钮,您所要做的就是进入按钮内部,在悬停下创建一个关键帧......并更改文本的颜色。 您不需要任何动作脚本
You know, if the text is a button, all you have to do is go inside of the button, create a key frame under hover...and change the color of the text. You dont need any action script
在 testMouseOver 中,您可以尝试以下操作:
您还必须设置文本字段的 name 属性:
In testMouseOver you could try this:
You also have to set the name property of the text field: