访问函数作用域之外的影片剪辑对象

发布于 2024-07-19 18:28:18 字数 1254 浏览 11 评论 0原文

我有一个影片剪辑,其中有一个文本字段,然后里面有一个按钮。 当用户鼠标悬停在文本上时,我需要能够更改文本的颜色。 下面是代码片段。 如何从函数外部访问对文本字段的引用? 提前致谢。

私有函数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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城之時有危險 2024-07-26 18:28:18

您知道,如果文本是一个按钮,您所要做的就是进入按钮内部,在悬停下创建一个关键帧......并更改文本的颜色。 您不需要任何动作脚本

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

三寸金莲 2024-07-26 18:28:18

在 testMouseOver 中,您可以尝试以下操作:

var containerMC:MovieClip = getChildByName("container movie clip name") as MovieClip;
var txtField:TextField = containerMC.getChildByName("htmlTxtField") as TextField;

您还必须设置文本字段的 name 属性:

myTxt.name = "htmlTxtField";

In testMouseOver you could try this:

var containerMC:MovieClip = getChildByName("container movie clip name") as MovieClip;
var txtField:TextField = containerMC.getChildByName("htmlTxtField") as TextField;

You also have to set the name property of the text field:

myTxt.name = "htmlTxtField";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文