1 Reply Latest reply on Jul 9, 2010 7:03 AM by Scottae031

    Flex 4 styleManager loadStyleDeclarations fail

    Scottae031

      I am starting to tinker with Flex 4 and I am having trouble trying to load a style swf file.  I have a css file that looks like this

       

       

      @namespace s "library://ns.adobe.com/flex/spark";


      s|Application {
          background-color: red;
      }

       


      which I compiled to a css-based swf file.  The code I am using to load the swf is like this:

       

       

       

      // Called within a function

      var dispatcher : IEventDispatcher = FlexGlobals.topLevelApplication.styleManager.loadStyleDeclarations(themeSwfUrl);
      dispatcher.addEventListener(StyleEvent.ERROR, onStyleError);
      dispatcher.addEventListener(StyleEvent.PROGRESS, onStyleProgress);
      dispatcher.addEventListener(StyleEvent.COMPLETE, onStyleComplete);

       

       

       

      private function onStyleError(event : StyleEvent) : void {
          trace("\tLoadThemeCommand.onIOError(event)");
          trace(event.errorText);
          Alert.show(event.errorText, "Theme Load Failure");
      }


      private function onStyleProgress(event : StyleEvent) : void {
          trace("\tLoadThemeCommand.onStyleProgress(event) " + event.bytesLoaded + " / " + event.bytesTotal);
      }


      private function onStyleComplete(event : StyleEvent) : void {
          trace("\tLoadThemeCommand.onLoadComplete(event)");
          trace('event.target: ' + (event.target));
          var dispatcher : IEventDispatcher = event.target as IEventDispatcher;
          trace('dispatcher: ' + (dispatcher));
          dispatcher.removeEventListener(StyleEvent.ERROR, onStyleError);
          dispatcher.removeEventListener(StyleEvent.PROGRESS, onStyleProgress);
          dispatcher.removeEventListener(StyleEvent.COMPLETE, onStyleComplete);
      }

       


      I see the following traces:

       


      LoadThemeCommand.execute(pNotification)
      LoadThemeCommand.onStyleProgress(event) 0 / 24042
      LoadThemeCommand.onStyleProgress(event) 8192 / 24042
      LoadThemeCommand.onStyleProgress(event) 16384 / 24042
      LoadThemeCommand.onStyleProgress(event) 24042 / 24042

       


      But I am getting this error:

       


      Error: Compatibility version has already been read.

          at mx.core::FlexVersion$/set compatibilityVersion()
          at mx.core::FlexVersion$/set compatibilityVersionString()
          at TestTheme_mx_core_FlexModuleFactory()

       


      I've looked around but can't find anything to help me.