19 Replies Latest reply on Mar 3, 2008 7:09 AM by GerryIsHere

    Selected text, highlighting color

    GerryIsHere Level 1
      Hi there!

      When I select text entered in an Input Field, highlighting color is always Black.
      How can I change it for another color like, for example, a light Green (#66ff99)?

      Many thanks in advance for your answers!

      Best regards,

      Gerry
        • 1. Re: Selected text, highlighting color
          Rothrock Level 5
          As far as I know there is no way. The classes you have to work with are pretty much Selection and TextField and neither seems to have anything that would allow for that.

          Perhaps there is some fancy way that you could fake it by actually having some kind of "hidden" input field and use it as a model for your displayed "input text field" that would actually just be a regular dynamic text field using getTextExtent to draw the background. Sounds complicated, but maybe it would be easier than I think?
          • 2. Re: Selected text, highlighting color
            GerryIsHere Level 1
            Thank you for your reply, Rothrock!

            I think you are right.
            But maybe some geeks at Adobe could explain the following behavior:

            On the same page where the Input Fields are located, I have two ComboBoxes for selecting various items. The highlighting of the selected item in these ComboBoxes is the same I set up for my Mac : light green !!!!

            This is a very interesting problem... Don't you think ?
            It's a pity that developers of Flash had never thought about such an aesthetic feature...
            • 3. Re: Selected text, highlighting color
              Rothrock Level 5
              Well the comboBox styling is pretty primative and all so I wouldn't hold that up as a good example!

              It does seem like something that should be under the programmers control, but evidently it isn't. I've been interested in this problem for a while. I'll see what I can come up with tonight.
              • 4. Re: Selected text, highlighting color
                GerryIsHere Level 1
                Wow!!! Thank you for the time you dedicate to this problem...
                • 5. Re: Selected text, highlighting color
                  Rothrock Level 5
                  I've tried a few things this evening. Nothing is working particularly well, but I think I might have settled on a path. I'll keep trying and post back if I get anywhere -- or if not I'll let you know that too.
                  • 6. Re: Highlighting text
                    Level 7
                    There's a couple of ways I've seen. An old one, that still works but is a
                    pain to get right is to use the (now deprecated) Color class, and it's
                    setTransform method.

                    If you have a field with an instance name of 'theText' - this will get you
                    started:

                    var myColorTransform:Object = new Object();
                    myColorTransform.ra = 0;
                    myColorTransform.rb = 0;
                    myColorTransform.ga = 100;
                    myColorTransform.gb = 100;
                    myColorTransform.ba = 100;
                    myColorTransform.bb = 0;
                    myColorTransform.aa = 0;
                    myColorTransform.ab = 0;

                    var a = new Color(theText);
                    a.setTransform(myColorTransform);



                    --
                    Dave -
                    Head Developer
                    http://www.blurredistinction.com
                    Adobe Community Expert
                    http://www.adobe.com/communities/experts/


                    • 7. Re: Selected text, highlighting color
                      GerryIsHere Level 1
                      Thank you for this solution !!!
                      Wow! Sounds a little tricky for me... :-)

                      Some parts are like Hebrew:
                      What the h... are ra, rb, ga, gb, etc ???

                      Is r for red, g for green, and b for blue ?
                      If yes I don't understand at all the combinations aa, ab, etc...

                      If you can dedicate some time to elaborate, I'll be very grateful!
                      • 8. Re: Selected text, highlighting color
                        Rothrock Level 5
                        It is an interesting idea, but I'm not seeing how it could work. This will change the color transform for the entire text field. Perhaps there is something I'm missing?

                        To learn more about the ColorTransform class, check out the help files. Yes you are correct the r,g,b and a (when it is in the first position) stand for reg, green, blue, and alpha.

                        The second letters are a percentage and an offset. The percentages run from -100 to 100 and the offsets from -255 to 255.

                        I've used it a fair amount, but it is really pretty opaque to me too. What I've found is that the numbers mirror the numbers found in the Color: Advanced dialog you get for MovieClip items in the Properties panel during author time. So if I'm trying to get a specific effect, I will usually experiment on stage with those values and then write them down.
                        • 9. Re: Selected text, highlighting color
                          Rothrock Level 5
                          All I can say is "Bleh!" I'm not really having much luck. It is a terribly complicated problem. First I haven't been able to really turn off the current highlighting. I thought perhaps just resetting the Selection everytime the beginIndex and endIndex wasn't the same. It worked to a point, but if you drug quickly it would flicker one letter with black highlighting and then disappear.

                          So I thought I'd try a different approach. Just to see if I could find where every letter is and it works to a point, but it gets really complex really fast.

                          To try this out. Put a dynamic text box on your stage called myText and add the following code to the first frame. Put a few words into your textfield – only one line – and make sure it is selectable. It should draw red boxes around each letter. As you select the text you should notice that it is basically filling in the boxes. So this would be part of if.

                          The complexity comes in if you put characters of different sizes on the same line or once you go to multiple lines. Bascially you would have to break up the text for each line. Look through and find the tallest character and use that for the height of all your boxes. And repeat for each line.

                          I think if I ever had to make a different selection color I could. But I don't think I'm going to do it just for fun.

                          PS: I also used ASSetPropFlags to poke around in the TextField and Selection classes to see if I could reveal any hidden selection color and I didn't find anything. Sorry.
                          • 10. Selected text, highlighting color
                            GerryIsHere Level 1
                            I gave a try to the method DMennenoh suggests.
                            I strictly applied the code to my TextField and it only changed the color of the text but the highlight still remains black...

                            Thanks Rothrock for the explanation about the pairs...
                            I understood.


                            This post written before refreshing the page! Didn't see the last posting of Rothrock...
                            • 11. Re: Selected text, highlighting color
                              GerryIsHere Level 1
                              quote:

                              Originally posted by: Rothrock
                              All I can say is "Bleh!" I'm not really having much luck. It is a terribly complicated problem. ...


                              Yes it is!
                              And many thanks for this dedicated time!
                              I unsuccessfully tried the method you suggest (which I understood, it's a miracle!).

                              As I wrote in my second post: "It's a pity that developers of Flash had never thought about such an aesthetic feature..."
                              Does anybody knows how to contact the Developers Team?

                              • 12. Re: Selected text, highlighting color
                                Level 7
                                Odd - the code I sent you changes the text color and highlight color for me.
                                But I can't work out how you get specific colors - the highlight color seems
                                to work off the text color.

                                Try this - start a fresh document - make a dynamic text field - give it an
                                instance name of 'theText' - make sure it's selectable, the font is
                                embedded.

                                Add this code to frame 1:

                                var myColorTransform:Object = new Object();
                                myColorTransform.ra = 0
                                myColorTransform.rb = 255;
                                myColorTransform.ga = 100;
                                myColorTransform.gb = 80;
                                myColorTransform.ba = 100;
                                myColorTransform.bb = 0;
                                myColorTransform.aa = 100;
                                myColorTransform.ab = 0;

                                var a = new Color(theText);
                                a.setTransform(myColorTransform);


                                I get orange text, and when selected the text turns white, with an orange
                                selection bg.

                                --
                                Dave -
                                Head Developer
                                http://www.blurredistinction.com
                                Adobe Community Expert
                                http://www.adobe.com/communities/experts/


                                • 13. Re: Selected text, highlighting color
                                  Rothrock Level 5
                                  Yeah I found a tutorial about using this technique that was fairly advanced, but it only works for certain combinations and as far as I can tell it doesn't allow you to specify just any color for the selection color, but requires that certain colors get swapped.

                                  Additionally it doesn't seem to work on a Mac. So that adds an extra bit of confusion to it.
                                  • 14. Re: Selected text, highlighting color
                                    Level 7
                                    Ahh - maybe Gerry is on a Mac, and that's why it doesn't work for him.
                                    Gerry? I see it's doable in AS3, and I found a method using BitmapData but I
                                    haven't had enough time to experiment with it yet.

                                    --
                                    Dave -
                                    Head Developer
                                    http://www.blurredistinction.com
                                    Adobe Community Expert
                                    http://www.adobe.com/communities/experts/


                                    • 15. Selected text, highlighting color
                                      GerryIsHere Level 1
                                      quote:

                                      Originally posted by: DMennenoh
                                      Newsgroup User

                                      ...maybe Gerry is on a Mac...
                                      ... it's doable in AS3...


                                      Thank you for all these efforts and... the time !!!

                                      DMennenoh, I tried it and , following your specs, it works.
                                      But this is not what I was looking for.
                                      The field border is orange: I don't want it this way...
                                      The text is orange: I don't want it this way...
                                      I need a highlight color light and sweet, completely independent of text color and other parameters of the input field.
                                      With your method, text will be unreadeable... (color too light)

                                      I am Mac based BUT can't use AS3 anyway... (I run Flash 8 Pro)

                                      Bis repetitas : Does anybody knows how to contact the Developers Team? :-)

                                      Best regards,

                                      Gerry
                                      • 16. Re: Selected text, highlighting color
                                        GerryIsHere Level 1
                                        I've found this tutorial (a quite complex one...):
                                        http://ericlin2.tripod.com/select/selectt.html

                                        Just in case it could help somebody else...

                                        Cheers!
                                        Gerry
                                        • 17. Re: Selected text, highlighting color
                                          luciewong
                                          Hi,
                                          You must work with >Text Selections<
                                          Catch the Starting point of the Selection with >.onMouseDown<;
                                          When the text is selected, you will have then also an >.onMouseUp< event.

                                          Both actions > MouseUp< and >MouseDown< will give you the length of the Text String and the Text String itself(substring());.
                                          Then give the command on MouseUp > StartBegin - StartEnd < Selection your TextFormat as you like.
                                          Read in Help under Text Selections.
                                          You could also then store the selected Text String for ex. in a DataSet, so next time on Display it could come up with the highlighted effect.

                                          Hope, this gives you an idea where to start
                                          regards,
                                          Luciewong
                                          • 18. Re: Selected text, highlighting color
                                            pallav_theGreat
                                            Hi,
                                            You can use this code:

                                            //--------------------------- New Text Format --------------------------//
                                            var overFmt:TextFormat = new TextFormat();
                                            overFmt.color = 0x66ff99;
                                            //--------------------------- End Text Format --------------------------//

                                            TextField_Instance.setTextFormat(overFmt);

                                            Cheers
                                            Pallav Samaddar
                                            CNN IBN (Network18)
                                            pallav.samaddar@gmail.com
                                            • 19. Re: Selected text, highlighting color
                                              GerryIsHere Level 1
                                              quote:

                                              Originally posted by: pallav_theGreat

                                              quote:

                                              Originally posted by: luciewong


                                              I thank you for your replies.

                                              I tried what you both suggest.
                                              And it doesn't solve my problem.

                                              I think there's some confusion here.
                                              Did you read my post with great attention?
                                              What I intend to do is changing the background highlighting color and NOT THE TEXT COLOR...

                                              Best regards,
                                              Gerry