2 Replies Latest reply on May 21, 2008 12:54 PM by Snarfblat

    Stupid Newbie Question

    Snarfblat
      I'm trying to get my first non-tutorial AIR code working. I'm using Aptana/AIR plugin. I've gotten to do the various tutorial things, like the desktop file list and stuff, but this one isn't working. Here's my code:

      function getData()
      {
      var request = new air.URLRequest("example.com?my.cfc&method=methodname&value=6");
      var loader = new air.URLLoader();
      loader.dataFormat = air.URLLoaderDataFormat.TEXT;
      loader.load(request);

      return loader.data;
      }

      Running the URL in the browser works fine; I get the data back from my CFC. But in AIR, it always comes back as UNDEFINED. I've even dumped the output inside the CFC to ensure that it's returning data when called by AIR, and it is.

      I've used the Introspector to look at the "loader" object, and it does come back intact, but again, the data property is undefined. What am I missing, or doing wrong?

      Thanks!

      Rob
        • 1. Re: Stupid Newbie Question
          Level 1
          Try adding Event.COMPLETE event listener to loader and get the data in the event handler.

          In AS3, you can do it like this. Don't know the JS syntax handy.

          loader.addEventListener(Event.COMPLETE,
          function (event:Event):void {
          trace(event.target as URLLoader).data;
          });

          • 2. Re: Stupid Newbie Question
            Snarfblat Level 1
            Thanks! That pretty much did it. I added this:

            loader.addEventListener(air.Event.COMPLETE, completeHandler);

            Before my loader.load(request) line, then added a completeHandler function that displayed the results in the Introspector.

            Now to figure out how to get only the data I wanted, and not the entire page document... :)

            Rob