2 Replies Latest reply on Jun 1, 2006 1:56 PM by RobLively

    Problem with flash.net.URLLoader

    RobLively
      I apologize if this has already been asked and answered however after looking at the forums i cannot find anything related. I'm sure that I am missing something obvious but I cannot get the following code to compile. I get 2 errors on the line indicated saying that I am trying to access an undefined property when using a method of the URLLoader or URLRequest classes.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[

      import flash.net.*;

      var myRequest:URLRequest = new URLRequest("Example.txt");
      var myLoader:URLLoader = new URLLoader();

      myLoader.load(myRequest); <----LINE WITH ERRORS

      ]]>
      </mx:Script>
      </mx:Application>

      The 2 errors I get are:
      Access of undefined property myLoader
      Access of undefined property myRequest

      Any help would be greatly appreciated.

      ---
      Best regards,

      Rob
        • 1. Re: Problem with flash.net.URLLoader
          RobLively Level 1
          UPDATE: I did find within the documentation that the error thrown indicates that the object doesn't exist. Attempts to access properties or methods of an undefined object refer to undefined property.

          I have found 2 ways that makes the code work. One still throws an error but does compile and function properly. I'd think that it would be a warning versus an error in that case. The other works fine. I still am not sure exactly what the problem is that creates these conditions.

          The first method which still creates an error is to replace the offending line in the above code with:

          myLoaderFunc(); <--- STILL GIVES AN ERROR

          function myLoaderFunc():void {
          myLoader.load(myRequest);
          }

          The error associated with the line indicated is "Call to a posibly undefined method myLoaderFunc". I'm thinking that this may be a namespace issue but I'm not sure.

          The second is to use the code above without the function call line that generates the error and have an event within the app call the function. For example, in the application tag you can include: initialize="myLoaderFunc()" or you could have a button click="myLoaderFunc()" and in either case it works fine with no errors or warning generated.

          I will leave this open for a bit longer to see if I can determine the exact issue or someone can point out the error.

          ---
          Best regards,

          Rob
          • 2. Re: Problem with flash.net.URLLoader
            RobLively Level 1
            Well, the problem with the original code is actually quite simple. According to the Flex Developers Guide pg 54 "Statements and expressions are allowed only if they are wrapped in a function." when you place actionscript in a <mx:Script> block. So having the load method being called as a statement in the script block without being in a function statement is what caused the error.

            ---
            Best regards,

            Rob