3 Replies Latest reply: Jul 4, 2010 10:00 PM by Andrei1 RSS

    URLloader with different file formats

    Petteri_Paananen Community Member

      Hi!

       

      I´m loading external logo into my SWF with following code:

       

      var request:URLRequest = new URLRequest("logo.swf");
      var logoloader:Loader = new Loader();
      logoloader.load(request);
      addChild(logoloader);
      logoloader.x = 5;
      logoloader.y = 5;

       

      Everything works fine as long as I have logo.swf in right place. Is there an easy way to improve that code so that it wouldn´t matter if there is logo.swf, logo.png or logo.jpg as long as one of those files exists in right place?

       

      I just would like to give my clients change to use other formats than SWF if they like, because some of them doesn´t have flash or any other software with SWF exporting capability.... all of them have Photoshop or some other Image software....

       

      Thanks!

        • 1. Re: URLloader with different file formats
          Andrei1 Community Member

          If I understood you correctly, these kind of things are accomplished via passing configuration values into Flash at runtime. Flash has no way to to read directories. If you don't want to make you clients configure your application by pointing to the right image to load, one of the ways (which will not be an improvement but rather a hack) is to attempt loading all the possible variations in some predefine logical sequence and load only images/swfs that don't return IOError.

           

          But, again, this is an ugly hack and it cannot possibly cover all the unfoseeable scenarios. For instance, what if the name is not logo but logo1?

           

          Just a word of caution. Basically, in any case, there are rules of engagement. Clients should be aware that by breaking these rules they will not have a properly working application. If you promise clients this kind of automation - you may subject yourself to unpleasant surprises down the road.

          • 2. Re: URLloader with different file formats
            Petteri_Paananen Community Member

            Thanks for you answer.

             

            Naming is not a problem, it has worked so far with logo.swf so I think adding couple of choises for file extensions will not be too hard for my clients either....=)

             

            How that IOError thing would work... do you mean that my URLloader first tries to load logo.swf, if there is none, it would continue to try load logo.png, and if theres no such file either, it finally tries to load logo.jpeg?

             

            Do I need some kind of event listener for those tries?

            • 3. Re: URLloader with different file formats
              Andrei1 Community Member

              Yes, you will need to listen to IOErrorEvent to figure if file exists.