2 Replies Latest reply on Sep 9, 2010 10:28 AM by rolltr13

    Dynamic Text and changing Text in AS3


      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

      //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.






        • 1. Re: Dynamic Text and changing Text in AS3
          FlashGodThe2nd Level 1


          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

          • 2. Re: Dynamic Text and changing Text in AS3
            rolltr13 Level 1

            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 !