A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Change color text

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    156

    Change color text

    Is there a clever way to change the color of text after it has been selected? I have a button and I want the text to change to black after it has been selected. I know that I could simply switch out the text but I would rather leave the same there and just change the color. I have explored formStyleFormat but have been unable to make it do anything.

    Thanks

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Do you mean once the text has been highlighted by the mouse?

    This is probably a little hacked together but it sets the colour of whatever text gets highlighted to black

    code:

    highligted = new TextFormat(); // a new textformat object
    highlighted.color = 0x000000; // black text

    this.createTextField("myText_txt", 1, 10, 10, 100, 20); // create the textfield
    myText_txt.text = "some text to test the highlighting";
    myText_txt.textColor = 0xff9900; // by default the text is orange
    myText_txt.autoSize = "left"; // fit the textbox to the text

    myText_txt.onMouseUp = function() { // when the mouse button is lifted do something
    this.setTextFormat(Selection.getBeginIndex(), Selection.getEndIndex, highlighted); // apply the highlighted text format object to the selected text
    };
    Mouse.addListener(myText_txt); // make the textfield listen for mouse events (so it knows what onMouseUp is)



    You could also add key events to the textfield (in the a similar way by making the textfield a listener for the Key object) for if the user highlighted text using the shift and arrow keys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center