8 Replies Latest reply on May 29, 2009 4:46 PM by peterg2000

    Text read via public var loadertxt:URLLoader works only on 2nd pass

    peterg2000

      Hi ,

      I have this code that works great but unfortunatelt it only works on the second pass ! On the first pass it complains of ...

      TypeError: Error #1010: A term is undefined and has no properties. On the second pass it works fine !

       

      Here is the code !

       

      +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

       

      public class Main extends MovieClip
          {
             
              public var source:*;
              public var indexcount:Number;
              public var loader:Loader;
              public var loadertxt:URLLoader = new URLLoader();
              //loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;      << this, if left in, complains that object loadertxt doesn't exist !
              public var loaderIndex:Number = 1;
              public var mc_next:MovieClip = new next();
              public var mc_prev:MovieClip = new prev();
              public var imagetxt1:String;
              private var menu_array:Array;
              private var folder_array:Array;
              private var distance:int=100;
              private var id:int=0;
              private var isFirst:Boolean=true;
             
              public function getPath():String
              {
                  trace(" I pass here first OK");                                                   <<< This first trace works all the time
                  loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;     <<< error shows up here on first pass !
                  loadertxt.load(new URLRequest(folder_array[id]+"image.txt"));
                  pictxt.text=loadertxt.data["var_" + loaderIndex];
                  trace("folder array here=" + folder_array[id]);                               
                  trace("text=" + loadertxt.data["var_" + loaderIndex]);
                 
                  return (folder_array[id]+"image0"+loaderIndex+".jpg");
              }

      public function loadImage():void
              {
                  loader.load(new URLRequest(getPath()));      
                  setChildIndex(loader,numChildren-1);
                
              }

       

      If you need the entire code , I'll put it here later !

       

      Thanks

       

      Pete

        • 1. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
          kglad Adobe Community Professional & MVP

          click file/publish settings/flash and tick permit debugging. retest.

           

          you should see a line number that indicates the line with the error.

          • 2. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
            RossRitchey Level 4

            Add "loadertxt:URLLoader = new URLLoader();" just before the dataFormat line where the error is thrown and post back with result.

            • 3. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
              peterg2000 Level 1

              Hi Kglad !  The Output point to three error locations, which are really nested functions !

               

              first it points to a line that calls loadimage();

              then to get(path();

              finally it points to the actual error location , but its really the line above it  ( loadertxt.load(new URLRequest(folder_array[id]+"image.txt"));)

              that isn`t working on the first pass because if I hit the load image again everything works ! Its only on the first pass that the code gives an error.

               

              if you look at the line that starts with ** it gives an error that complains about the object loadertxt not existing ! I can`t get it to work with the

              line there because it ONLY gets executed once at startup . Which is why I moved it to the getpath() function , so I could call it a second time

              and it works !  I might have to upload the entire site as it is probably a bug elswhere that is causing the command execution to be out of sync somehow !

               

              Thanks

               

              Pete

               

              Ross Richey , I already have that line of code in the  -public class Main extends MovieClip-

               

               

              +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

               

              public class Main extends MovieClip
                  {
                     
                      public var source:*;
                      public var indexcount:Number;
                      public var loader:Loader;
                      public var loadertxt:URLLoader = new URLLoader();
              **      //loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;      << this, if left in, complains that object loadertxt doesn't exist !
                      public var loaderIndex:Number = 1;
                      public var mc_next:MovieClip = new next();
                      public var mc_prev:MovieClip = new prev();
                      public var imagetxt1:String;
                      private var menu_array:Array;
                      private var folder_array:Array;
                      private var distance:int=100;
                      private var id:int=0;
                      private var isFirst:Boolean=true;
                     
                      public function getPath():String
                      {
                          trace(" I pass here first OK");                                                   <<< This first trace works all the time
                          loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;     <<< error shows up here on first pass !
                          loadertxt.load(new URLRequest(folder_array[id]+"image.txt"));
                          pictxt.text=loadertxt.data["var_" + loaderIndex];
                          trace("folder array here=" + folder_array[id]);                               
                          trace("text=" + loadertxt.data["var_" + loaderIndex]);
                         
                          return (folder_array[id]+"image0"+loaderIndex+".jpg");
                      }

              public function loadImage():void
                      {
                          loader.load(new URLRequest(getPath()));      
                          setChildIndex(loader,numChildren-1);
                        
                      }

              Here is the code !

               

              +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

               

              public class Main extends MovieClip
                  {
                     
                      public var source:*;
                      public var indexcount:Number;
                      public var loader:Loader;
                      public var loadertxt:URLLoader = new URLLoader();
                      //loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;      << this, if left in, complains that object loadertxt doesn't exist !
                      public var loaderIndex:Number = 1;
                      public var mc_next:MovieClip = new next();
                      public var mc_prev:MovieClip = new prev();
                      public var imagetxt1:String;
                      private var menu_array:Array;
                      private var folder_array:Array;
                      private var distance:int=100;
                      private var id:int=0;
                      private var isFirst:Boolean=true;
                     
                      public function getPath():String
                      {
                          trace(" I pass here first OK");                                                   <<< This first trace works all the time
                          loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;     <<< error shows up here on first pass !
                          loadertxt.load(new URLRequest(folder_array[id]+"image.txt"));
                          pictxt.text=loadertxt.data["var_" + loaderIndex];
                          trace("folder array here=" + folder_array[id]);                               
                          trace("text=" + loadertxt.data["var_" + loaderIndex]);
                         
                          return (folder_array[id]+"image0"+loaderIndex+".jpg");
                      }

              public function loadImage():void
                      {
                          loader.load(new URLRequest(getPath()));      
                          setChildIndex(loader,numChildren-1);
                        
                      }

               

              +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

               

              public class Main extends MovieClip
                  {
                     
                      public var source:*;
                      public var indexcount:Number;
                      public var loader:Loader;
                      public var loadertxt:URLLoader = new URLLoader();                     +++
                      //loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;      << this, if left in, complains that object loadertxt doesn't exist !
                      public var loaderIndex:Number = 1;
                      public var mc_next:MovieClip = new next();
                      public var mc_prev:MovieClip = new prev();
                      public var imagetxt1:String;
                      private var menu_array:Array;
                      private var folder_array:Array;
                      private var distance:int=100;
                      private var id:int=0;
                      private var isFirst:Boolean=true;
                     
                      public function getPath():String
                      {
                          trace(" I pass here first OK");                                                   <<< This first trace works all the time
                          loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;     <<< error shows up here on first pass !

              Here is the code !

               

              +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

               

              public class Main extends MovieClip
                  {
                     
                      public var source:*;
                      public var indexcount:Number;
                      public var loader:Loader;
                      public var loadertxt:URLLoader = new URLLoader();
                      //loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;      << this, if left in, complains that object loadertxt doesn't exist !
                      public var loaderIndex:Number = 1;
                      public var mc_next:MovieClip = new next();
                      public var mc_prev:MovieClip = new prev();
                      public var imagetxt1:String;
                      private var menu_array:Array;
                      private var folder_array:Array;
                      private var distance:int=100;
                      private var id:int=0;
                      private var isFirst:Boolean=true;
                     
                      public function getPath():String
                      {
                          trace(" I pass here first OK");                                                   <<< This first trace works all the time
                          loadertxt.dataFormat = URLLoaderDataFormat.VARIABLES;     <<< error shows up here on first pass !
                          loadertxt.load(new URLRequest(folder_array[id]+"image.txt"));
                          pictxt.text=loadertxt.data["var_" + loaderIndex];
                          trace("folder array here=" + folder_array[id]);                               
                          trace("text=" + loadertxt.data["var_" + loaderIndex]);
                         
                          return (folder_array[id]+"image0"+loaderIndex+".jpg");
                      }

              public function loadImage():void
                      {
                          loader.load(new URLRequest(getPath()));      
                          setChildIndex(loader,numChildren-1);
                        
                      }

                          pictxt.text=loadertxt.data["var_" + loaderIndex];                          This is the third error line it points to but its because of the line above it ! 
                          trace("folder array here=" + folder_array[id]);                               
                          trace("text=" + loadertxt.data["var_" + loaderIndex]);
                         
                          return (folder_array[id]+"image0"+loaderIndex+".jpg");
                      }

              public function loadImage():void
                      {
                          loader.load(new URLRequest(getPath()));                     ###  second error here       
                          setChildIndex(loader,numChildren-1);
                        
                      }

              • 4. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
                RossRitchey Level 4

                And I repeat: Try initializing loadertxt inside of the getPath function, rather than in the main class definition and let me know if that fixes it.

                 

                IE:

                 

                outside of the function:

                 

                var loadertxt:URLLoader;

                 

                inside of the function:

                 

                loadertxt = new URLLoader();

                • 5. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
                  kglad Adobe Community Professional & MVP

                  what's trace(folder_array[id]+"image.txt") reveal when place just above the problematic line of code?

                  • 6. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
                    peterg2000 Level 1

                    folder_array[id]=images1/johna/image.txt    which is correct and functionally the same as the second pass when the code works !

                     

                     

                    Pete

                    • 7. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
                      peterg2000 Level 1

                      1067: Implicit coercion of a value of type flash.net:URLLoader to an unrelated type Class.

                      1188: Illegal assignment to class URLLoader.

                       

                      Pete

                      • 8. Re: Text read via public var loadertxt:URLLoader works only on 2nd pass
                        peterg2000 Level 1

                        Well , I either worked around the problem or fixed it !

                         

                        I noticed that may sites that talk about text importing used an addlistener and the COMPLETE event ,

                        which made me think that my problem was that I wasn`t giving the code time to load the text before

                        I tried to access it . Therefore I was getting a `term is undefined and has no properties` error !

                        Thats why it was working on the second pass! It had time to load !

                         

                        Thanks anyways guys , unless you see some other problem ! ( Apart from sloppy code ! )

                         

                        Pete