Skip navigation
Currently Being Moderated

Dynamic Text and changing Text in AS3

Sep 9, 2010 9:51 AM

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.

 
Replies
  • Currently Being Moderated
    Sep 9, 2010 9:59 AM   in reply to rolltr13

    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)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points