3 Replies Latest reply on Sep 2, 2010 10:18 AM by theloogybear1

    Project with dynamic text...

    theloogybear1

      I have been working on a dynamic loading news ticker for a site and have been running into two seperate problems:

       

      The first, creating a movie clip, inserting the following code:

       

      var myTextLoader:URLLoader = new URLLoader();
      var myTextField_txt:TextField = new TextField();
      myTextField_txt.wordWrap = true;
      myTextField_txt.autoSize=TextFieldAutoSize.LEFT;
      myTextField_txt.width = 200;

       

      myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

       

      function onLoaded(e:Event):void {
      myTextField_txt.text = e.target.data;
      addChild(myTextField_txt);
      }

       

      myTextLoader.load(new URLRequest("myText.txt"));

       

      and having the clip load the text from the text file listed. In this version, everything is working fine except I don't have the ability to change the font, size, and color of the text using only flash and the text document, (to my understanding)

       

      The second, creating two .fla files, one with the embedded font I want to display named font.fla, and the other blank named fontloader.fla. Also create an .as file in the folder with the following code:

       

      package
      {
          import flash.display.Loader;
          import flash.display.MovieClip;
          import flash.events.Event;
          import flash.net.URLRequest;
          import flash.text.Font;
          import flash.text.TextField;
          import flash.text.TextFieldAutoSize;
          import flash.text.TextFormat;
         
          /**
           * ...
           * @author Logan Brasic  [LeMatic Inc.] - 2010
           */
          public class FontLoader extends MovieClip
          {
             
              var loader:Loader;
             
              public function FontLoader()
              {
                  loader = new Loader();
                  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
                  loader.load(new URLRequest("font.swf"))
              }
             
              private function onComplete(e:Event):void
              {
                  var fontLib:Class = e.target.applicationDomain.getDefinition("NormalFont") as Class;
                  var font:Font = new fontLib;
                 
                  Font.registerFont(fontLib);
                 
                  var temp_txt:TextField = new TextField();
                  addChild(temp_txt);
                 
                  temp_txt.x = stage.stageWidth = 0;
                  temp_txt.y = stage.stageHeight = 0;
                 
                  temp_txt.autoSize = TextFieldAutoSize.LEFT;
                 
                  temp_txt.width = 200
                 
                  temp_txt.wordWrap = true
                 
                  var tf:TextFormat = new TextFormat(font.fontName, 13);
                 
                  tf.color = 0xffffff;
                 
                  temp_txt.defaultTextFormat = tf;
                 
                  temp_txt.embedFonts = true;
                 
                  temp_txt.text = "Welcome to the new Website! Please feel free to contact us with any questions you may have, and don't forget to come check us out at the Trade show next month!"
              }
         
          }

       

      In this second scenario, the problem is that I can't figure out a way to make the dynamic text scroll vertically and loop, (Was trying to figure out a way to save the fontloader.fla as a movie clip, then importing it into a new .fla and just using a motion tween on the clip, but so far I'm confused by it). This second scenario is also not my first choice, because loading the text straight from a text file would make the news section very easy to update for those who don't have any design experience.

       

      If anyone has an answer to either of these problems, your ideas would be most appreciated!

       

      Thanks!

        • 1. Re: Project with dynamic text...
          kglad Adobe Community Professional & MVP

          why can't you apply a css or textformat in your first scenario?

           

          and why can't you scroll your text in your second scenario?

          • 2. Re: Project with dynamic text...
            theloogybear1 Level 1

            When I try to load the text from the text file and the font/color/size from an .as file:

             

            package 
            {
                import flash.display.Loader;
                import flash.display.MovieClip;
                import flash.events.Event;
                import flash.net.URLRequest;
                import flash.text.Font;
                import flash.text.TextField;
                import flash.text.TextFieldAutoSize;
                import flash.text.TextFormat;
                
                /**
                 * ...
                 * @author Logan Brasic  [LeMatic Inc.] - 2010
                 */
                public class FontLoader extends MovieClip 
                {
                    
                    
                    var loader:Loader;
                    
                    public function FontLoader() 
                    {
                        loader = new Loader();
                        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
                        loader.load(new URLRequest("font.swf"))
                    }
                    
                    private function onComplete(e:Event):void 
                    {
                        var fontLib:Class = e.target.applicationDomain.getDefinition("NormalFont") as Class;
                        var font:Font = new fontLib;
                        
                        Font.registerFont(fontLib);
                        
                        var temp_txt:TextField = new TextField();
                        addChild(temp_txt);
                        
                        temp_txt.x = stage.stageWidth = 0;
                        temp_txt.y = stage.stageHeight = 0;
                        
                        temp_txt.autoSize = TextFieldAutoSize.LEFT;
                        
                        temp_txt.width = 200
                        
                        temp_txt.wordWrap = true
                        
                        var tf:TextFormat = new TextFormat(font.fontName, 13);
                        
                        tf.color = 0xffffff;
                        
                        temp_txt.defaultTextFormat = tf;
                        
                        temp_txt.embedFonts = true;
                        
                        temp_txt.load(new URLRequest("myText.txt"));
                    }
                
            

             

            I get the following error:

            1061: Call to a possibly undefined method load through a reference with static type flash.text:TextField.

            • 3. Re: Project with dynamic text...
              kglad Adobe Community Professional & MVP

              you should be using a urlloader to load your text file.  you did that correctly in your first scenario.