4 Replies Latest reply on Oct 31, 2007 10:48 AM by Raz2er

    Textfield Formating Problems Action script 3

    Raz2er


      Apologies for a probably very basic question, but I am very new to flash and working alone.

      I am trying to write a script which reads text from a file and display it in the movie. It all works fine but I can not get the

      TextFormat object to do anything at all.

      function completeHandler(event:Event):void {
      var loader:URLLoader = URLLoader(event.target);
      var thistext = loader.data;
      var my_fmt:TextFormat = new TextFormat();
      my_fmt.bold = true;
      my_fmt.font = "Courier";
      my_fmt.size = 40;
      trace(thistext);
      tField = new TextField();
      tField.autoSize = "left";
      tField.background = false;
      tField.border = false;
      tField.x = 10;
      tField.y = 500;
      tField.alpha = 50
      tField.setTextFormat(my_fmt);
      tField.backgroundColor = 0x23169C;
      tField.textColor = 0xFF0000;
      tField.text = thistext;
      addChild(tField);
      }
      Most of the TextField properties work except the ALPHA, which I really need to set for my application.
      None of the TextFormat properties including font, bold etc are being applied. What have I failed to do?


      Thanks
        • 1. Re: Textfield Formating Problems Action script 3
          shrimusic
          hi
          first of all ......
          tField = new TextField();
          above statement must start with var keyword.
          ok anyway i made some changes to u r code. it is below, hope it helps u.
          (expect that i m not loading text from external file)

          import flash.display.*;

          var thistext = "aaaaaaaaaaaaaaaaaaaaaaaaaaaa";
          var tField:TextField = new TextField();
          tField.autoSize = "left";
          tField.background = false;
          tField.border = false;
          tField.x = 10;
          tField.y = 50;
          tField.alpha = 50

          tField.backgroundColor = 0x23169C;
          tField.textColor = 0xFF0000;

          var my_fmt:TextFormat = new TextFormat();
          my_fmt.bold = true;
          my_fmt.font = "Courier";
          my_fmt.size = 40;
          my_fmt.underline = true;

          trace(thistext);
          tField.text = thistext;
          tField.defaultTextFormat= my_fmt;

          addChild(tField);
          • 2. Re: Textfield Formating Problems Action script 3
            Raz2er Level 1
            Thanks for that.

            I have pasted this in as it was posted.

            However it still does not seem to apply the fonts or font sizing, bold etc when it displays. Is there something about the environment I am working in that needs to be set up (this movie is not intended to be run in a web browser)

            setting the background to false now seems to work and allows it to work over a rectangle with a 50% alpha value.

            Unfortunately this gives me another problem, the text may change from time to time and the text file is read every few seconds. How do I clear the old text before displaying the new?
            • 4. Re: Textfield Formating Problems Action script 3
              Raz2er Level 1
              OK got the text working with a little fiddling

              package {

              import flash.display.*;
              import flash.text.*;
              public class testas3 extends Sprite {
              function testas3(){


              var thistext = "Some test text";
              var tField:TextField = new TextField();
              tField.autoSize = "left";
              tField.background = false;
              tField.border = false;
              tField.x = 10;
              tField.y = 50;
              tField.alpha = 50

              tField.backgroundColor = 0x23169C;
              tField.textColor = 0x000000;

              var my_fmt:TextFormat = new TextFormat();
              my_fmt.bold = true;
              my_fmt.font = "Times New Roman";
              my_fmt.size = 40;
              //my_fmt.underline = true;

              trace(thistext);
              tField.text = thistext;
              // tField.defaultTextFormat= my_fmt; not like this but like next line
              tField.setTextFormat(my_fmt);
              addChild(tField);

              }
              }
              }

              Just in case anyone else is struggling with this