我有一个电影剪辑,它有一个文本字段,然后是一个按钮。当用户鼠标悬停在文本上时,我需要能够更改文本的颜色。下面是代码片段。如何从函数外部访问对 Text 字段的引用?提前致谢。
私有函数 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);
}
私有函数 testMouseOver(e:MouseEvent) { var myTxtFormat:TextFormat = new TextFormat(); myTxtFormat.color = 0xccff00;
var myText:TextField = new TextField;
myText.htmlText = e.currentTarget.name;
myText.setTextFormat(symTxtFormat);
}