2 Replies Latest reply on Mar 4, 2010 1:30 AM by EricJ32

    Check if style exists before loading

    EricJ32

      Hi,

       

      I have a load of styles that are CSS compiled to SWF. When the application loads, it looks in a database to see which of these styles it should use and uses the following code to load it:

       

      public function set currentStyle(val:String):void

      {

          if (val != _currentStyle)

          {

              var isOK:Boolean=true;

       

              if (val.length > 0)

              {

                 

                  try

                  {

                      StyleManager.loadStyleDeclarations("styles/" + val + ".swf");

       

                      if (_currentStyle.length > 0)

                          StyleManager.unloadStyleDeclarations("styles/" + _currentStyle + ".swf");

       

                      _currentStyle=val;

                  }

                  catch (errObj:Error)

                  {

                      isOK=false;

                  }

              }

          }

      }

       

       

      This works fine when the style exists, but there are styles in the database which don't have equivalents in the Flex application. In this case, it uses a default style.

      If I try to use this code with a style that doesn't exist, I get a runtime error in the debugger version of Flash Player saying it can't find the URL. The try...catch does not catch the error, as it seems to happen within an event handler.

       

      Is there any way of checking for the existence of the style before loading it, or catching the failure?

       

      I can't create a style for each entry in the database, because the list changes on a regular basis.

       

      Thanks for your help.