9 Replies Latest reply on Aug 26, 2010 2:50 AM by Ron Colmen

    Bold and Normal

    Ron Colmen Level 2

      textAB is a dynamic textfield. How to make a[0] bold and to keep a[1] normal?

       

      receiveLoad.onData = function(src) {

         var a:Array=src.split(",,");

        textAB.text=a[0]+newline+a[1];

        • 1. Re: Bold and Normal
          Ned Murphy Adobe Community Professional & MVP

          If the intention is that the textfield is set up to show the normal text by default, then you just need to format the first line (a[0]) to be bold...

           

          var format1:TextFormat = new TextFormat();
          format1.bold = true;

           

          receiveLoad.onData = function(src) {

             var a:Array=src.split(",,");

            textAB.text=a[0]+newline+a[1];

            textAB.setTextFormat(0, a[0].length, format1);

           

          Look up the setTextFormat method in the help documentation if you want to understand what is being specified in the event you want to adjust formatting in different portions of the text.

          • 2. Re: Bold and Normal
            Ron Colmen Level 2

            Thank you Ned.

            • 3. Re: Bold and Normal
              Ned Murphy Adobe Community Professional & MVP

              You're welcome

              • 4. Re: Bold and Normal
                Ron Colmen Level 2

                How can I do this to an Array? (not working)

                 

                receiveLoad.onData = function(src) {

                var messageA:Array = src.split(",,,");

                for(var i:Number=0;i<messageA.length;i++){

                var msgA:Array = messageA[i].split(",,");

                if(i==0){

                notice.text = msgA[0]+"\n"+msgA[1]+"\n"+msgA[2]+"\n\n";

                } else {

                notice.text += msgA[0]+"\n"+msgA[1]+"\n"+msgA[2]+"\n\n";

                }

                notice.setTextFormat(0, msgA[0].length, format1);

                }

                }

                • 5. Re: Bold and Normal
                  Ned Murphy Adobe Community Professional & MVP

                  Below is one way that works.  I tried applying the format in the first loop, but for some reason that I have yet to understand, only the last set's format stuck...  So this approach waits 'til all the text is assigned, storing the indices where formatting needs to be done while the text is being built, and then applying the format afterwards using the stored indices.

                   

                  receiveLoad.onData = function(src) {

                       var messageA:Array = src.split(",,,");

                       var charCount = 0;
                       var formatIndices = new Array();

                       notice.text = "";

                   

                       for(var i:Number=0; i<messageA.length; i++){
                             var msgA:Array = messageA[i].split(",,");
                             notice.text += msgA[0]+"\n"+msgA[1]+"\n"+msgA[2]+"\n\n";
                             formatIndices[i] = {startAt: charCount, endAt: charCount+msgA[0].length};
                             charCount = notice.text.length;
                       }

                   

                       for(var j:Number=0; j<formatIndices.length; j++){
                             notice.setTextFormat(formatIndices[j].startAt, formatIndices[j].endAt, format1);
                       }

                  }

                  1 person found this helpful
                  • 6. Re: Bold and Normal
                    Ron Colmen Level 2

                    That works! Thank you Ned!

                    • 7. Re: Bold and Normal
                      Ron Colmen Level 2

                       

                      • 8. Re: Bold and Normal
                        Ned Murphy Adobe Community Professional & MVP

                        You're welcome

                        • 9. Re: Bold and Normal
                          Ron Colmen Level 2

                          How to get msgA[3] and msgA[0] both in the same format (format1)?