views:

314

answers:

1

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);

}

A: 

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";
Jason Miesionczek
OK, so heres what I added:createRows() - I added a name to the container.name="myContainer" and myTxt.name = "htmlTxtField";On testMouseOver() I am addingvar containerMC:MovieClip = getChildByName("myContainer");var txtField:TextField = containerMC.getChildByName("htmlTxtField");I am getting the Error -1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.text:TextField. What am I doing incorrectly?
Iris
i neglected to add the "as MovieClip" and "as TextField" to the ends of the getChildByName calls. See my edit.
Jason Miesionczek