Accessing a clip object out of scope
I have a clip that has a textbox and then a button inside. I need to change the color of the text when I hover over the text. Below is a code snippet. How to access the link to the "Text" field outside the function? Thanks in advance.
private function createRows () {var containerMc: MovieClip = string;
//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);
}
0
a source to share
2 answers
In testMouseOver, you can try this:
var containerMC:MovieClip = getChildByName("container movie clip name") as MovieClip;
var txtField:TextField = containerMC.getChildByName("htmlTxtField") as TextField;
You also need to set the name property of the textbox:
myTxt.name = "htmlTxtField";
0
a source to share