6 Replies Latest reply on Mar 30, 2011 2:52 PM by Sandra D5

    .toString Issue

    Sandra D5

      I'm attempting to build a simple Flex 4 application but I keep running into issues when I attempt to use the .toString property on an array.

      can someone take a look and tell me if I'm doing something wrong I keep getting the error undefined property of file (file being the array)


      here is the line of offending code:


      static public var XML_PATH:String = file[1].toString() +'.xml';

        • 1. Re: .toString Issue
          UbuntuPenguin Level 4

          Something doesn't feel right about that line of code.  You are declaring it static, but you also have "var" in the same line.  Not saying something is wrong, but I have never seen that before.  From a program perspective, you are saying that "XML_PATH" won't change, but you are setting it to a variable ?  So when this class starts up and is initiated what is file ?  What is file[0].  I have a feeling that neither of those are declared and that is why you are having problems.

          1 person found this helpful
          • 2. Re: .toString Issue
            Sandra D5 Level 1

            Thanks for the quick reply UbuntuPenguin,

                                                                           I understand the statement may seem odd, I don't completely understand it myself as this was some code I inherited and am attempting to use in Flex4. I'll give you the rest of my source but file is declared as an array that I am getting from a string variable that I split from an external interface  call. File[1] in this case would be the file name that I am sending to the browser. here is the code in its entirety:


            private var pageURL:String = ExternalInterface.call('window.location.href.toString');

            private var file:Array = pageURL.split("?")

            static public var providerXML:XML = new XML(); 

            static public var XML_PATH:String = file[1].toString() + '.xml';

            static public var XMLPAGE:URLRequest = new URLRequest(XML_PATH);

            static public var pathLoader:URLLoader = new URLLoader(XMLPAGE);

            pathLoader.addEventListener("complete", xmlLoaded);



            public static function xmlLoaded(evtObj:Event):void


                    providerXML = XML(pathLoader.data);






            if you have any suggestions on how to make this cleaner I would most definitely appreciate it. I have tried to remove the static from these vars only to receive errors.

            • 3. Re: .toString Issue
              UbuntuPenguin Level 4

              I would try to figure out the INTENT of the code first.  It looks like someone was trying to run logic in their instance variable declarations.  Everything other than the pageURL declaration I would run in a function, scratch that, I would run it all in a function.  They way that code is put together gives me the creeps.  Try something like this.


              private var _pageURL:String;
              private var _urlRequest:URLRequest;
              private var _urlLoader:URLLoader;

              public function mrClean()
                   pageURL = ExternalInterface.call('window.location.href.toString');
                   var xmlPath:String = file[1].toString().xml; // Where does this come from ?
                   _urlRequest = new URLRequest(xmlPath);
                  _urlLoader = new URLLoader( _urlRequest  );
                  _urlLoader.addEventListenter( Event.COMPLETE , someFunction );

              • 4. Re: .toString Issue
                Sandra D5 Level 1

                I don't know what is going on. I tried the code you posted and I ran into another issue. It tells me that 1) that addListener is an undefined property of flash.util.net and 2) that _urlloader.data is another undefined property. I'm really at a loss here and any suggestions you have would be useful. Thanks in advance.

                • 5. Re: .toString Issue
                  _spoboyle Level 4

                  just to clarify there is no issue with decalring something static var


                  static does not imply the variable won't change (that's what const is for)


                  static just indicates the variable belongs to the class not an instance of the class


                  a typical demonstration for using static var would be to have a counter within a class to count how many times the class has been instantiated.


                  although i agree that the code its not very well written

                  1 person found this helpful
                  • 6. Re: .toString Issue
                    Sandra D5 Level 1

                    Thanks for the help.  Just ended up rewriting the code.  Thanks.