Skip to main content
September 9, 2010
Answered

Dynamic Text and changing Text in AS3

  • September 9, 2010
  • 1 reply
  • 68278 views

I have a Dynamic Text box in my Library.  I drag it to my main stage and give it a name..it is now a movieclip. The name is 'mcAdmin'.  I added an event listener for MOUSE_OVER.  I want the text to change color, but for now I'm just trying to change the text; however, it's not displaying the change in text I want.  I do a trace, and the change is in there on the output window, but it is not displayed as such.  How can I :

1) use AS3 to change the font color of the text

2) use AS3 to change the text and have it display?

function onMouseOver_txtAdmin(e:MouseEvent):void
{
Mouse.cursor="button";

//Current mcAdmin text is 'Administration'

//I want to change the color of Administartion on Mouse_Over

//but to test if I can get to anything, I'm just trying to change the text.


mcAdmin.text="Hello";
trace(mcAdmin.text);


mcPPMB.alpha=.5;
mcASB.alpha=.5;
mcISO.alpha=.5;
mcEA.alpha=.5;
mcAdmin.alpha=1;

mcAdmin.scaleX=1.25;
mcAdmin.scaleY=1.25;
}

Thanks.

This topic has been closed for replies.
Correct answer

1st

give the textfield a name, if it hasn't already (sounds like you put it in a movieclip).

to change the text set the text property of your text field

like this

myTextField_txt.text = "here is the text";

or if it is inside a movieclip

myClip_mc.myTextField_txt.text = "here is the text";


To change the color you would need to put a TextFormat on it. To keep the same fontsize, font etc. you could first get the TextFormat from your existing Textfield, change the color of the TextFormat and set it on the TextField.

// get the Textformat of the first character

            var TF:TextFormat = myTextField.getTextFormat(0,1)

// set the font color
            TF.color = 0xff0000;

// put it on the whole text
            myTextField.setTextFormat(TF)

1 reply

Correct answer
September 9, 2010

1st

give the textfield a name, if it hasn't already (sounds like you put it in a movieclip).

to change the text set the text property of your text field

like this

myTextField_txt.text = "here is the text";

or if it is inside a movieclip

myClip_mc.myTextField_txt.text = "here is the text";


To change the color you would need to put a TextFormat on it. To keep the same fontsize, font etc. you could first get the TextFormat from your existing Textfield, change the color of the TextFormat and set it on the TextField.

// get the Textformat of the first character

            var TF:TextFormat = myTextField.getTextFormat(0,1)

// set the font color
            TF.color = 0xff0000;

// put it on the whole text
            myTextField.setTextFormat(TF)

September 9, 2010

Dealing with the TextArea component, I was use to something like myTextArea.textField.text="Hello"...but I remembered to get to the library, I had to do as you suggested, mcStageText.txtLibraryText.text="Hello"  worked great.

I didn't use your Format way, I was able to do this: mcStageText.txtLibraryText.textColor=0xFFFFFF;   So far, works just like I wanted.

Thanks !