5 Replies Latest reply on May 21, 2010 7:50 AM by Tim Consolazio

    SWFLoader reload

    arieljake@yahoo.com
      Here is my code. It's just not working, it compiles but does not refresh the child SWF after I make changes. I want to be able to click a button and reload an SWF loaded by a SWFLoader:

      <?xml version="1.0" encoding="iso-8859-1"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="860" height="900"
      applicationComplete="appComplete();">

      <mx:Script>
      <![CDATA[
      import mx.controls.Alert;
      import flash.display.*;
      import flash.net.URLRequest;
      import flash.events.IOErrorEvent;

      public function appComplete ( ):void
      {
      // var ldrContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain,null);
      loadChild();
      }

      public function loadChild ():void
      {
      childLoader.load("foodTracker.swf");
      }
      ]]>
      </mx:Script>

      <mx:ApplicationControlBar dock="true">

      <mx:Button label="Reload Child App" click="loadChild();" />

      </mx:ApplicationControlBar>

      <mx:SWFLoader id="childLoader" />

      </mx:Application>
        • 1. Re: SWFLoader reload
          peterent Level 2
          The problem is that the browser is caching the SWF. You need to use a different URL so the browser is fooled into thinking you've got new content. There is probably a more elegant way to do this, but:

          childLoader.load("FoodTracker.swf?dummy="+(new Date()).time);

          works. That will tack on a new value each time you invoke the load function and supply a dummy request parameter.
          • 2. Re: SWFLoader reload
            arieljake@yahoo.com Level 1
            That makes good sense. but, i don't seem to be able to append a query string to the load url when it is a relative path. I get a broken image picture when I do.

            When I add the absolute web address, i.e. on localhost, I encounter sandbox security issues that don't seem to be resolved by the crossdomain.xml file, as "localhost" does not seem to be a valid domain.

            any thoughts?
            • 3. Re: SWFLoader reload
              peterent Level 2
              Ah, yes, the URL trick will only work when using a web server. There are some tricky sandbox issues here. Are you running this from within Flex Builder 2? My guess is that you are not. Flex Builder apps are automatically run with a local-trusted sandbox which means they can do anything. If you put your files onto a web server I'd be surprised you are getting security problems as the main swf and the FoodTracker.swf are all being loaded from the same domain. When you use a web server for testing, go back to using a relative path. When the request is made, the Flash Player will use http://<domain> automatically just as if you were using a <img src="image.jpg"> tag in HTML where the image.jpg was in the same directory as the HTML file.
              • 4. Re: SWFLoader reload
                arieljake@yahoo.com Level 1
                OK, yes, you are right, my last post was due to the fact that I was executing the parent swf in the standalone flash player and not within a browser. the change to running from the browser fixed the issue,

                unfortunately, the query string method is not causing the refresh as anticipated.

                any other ideas would be nice, but its not very important. thank you.

                • 5. Re: SWFLoader reload
                  Tim Consolazio Level 1

                  I just use (in the loaded swf)

                   

                  Application.application.loaderInfo.loaderURL

                   

                  Works every time (every time I've used it anyway), and just leaves the parsing of the querystring up to me, which is easy enough. Makes it braindead easy to pass in simple param data to swfs loaded with SWFLoader.