3 Replies Latest reply on Dec 16, 2009 8:53 PM by Flex harUI

    Reloading CSS in SWFLoader loaded Flex app.




      I am having the following problem:


      I have a Main application with a SWFLoader that loads a child Flex application. When a button is pressed, SWFLoader loads a new child Flex application. Currently LoaderContext for SWFLoader is created as follows:


      var context:LoaderContext = new flash.system.LoaderContext(false, ApplicationDomain.currentDomain);


      Everything seems to work okay except that CSS style sheets definded in the first child application cannot be overwritten by the CSS style sheets in the second.


      After much research I see the following two options: 1. load style sheets externally using StyleManager.loadStyleDeclaration() method or 2. specify a different ApplicationDomain for the child Flex application.

      The problem with solution #1 is I would like to keep all style sheets embedded in either the main application or each child application. So, my question is, how do load/reset CSS styles while keeping the CSS (or CSS compiled to SWF) embedded when StyleManager.loadStyleDeclaration() only takes a URL as a parameter?


      The problem with solution #2 is as follows: when I change the ApplicationDomain property in the LoaderContext declaration to this:


      var context:LoaderContext = new flash.system.LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain));


      I get the following error when I load a second child application into the SWFLoader:


      TypeError: Error #1034: Type Coercion failed: cannot convert spark.components::VScrollBar@64d6851 to spark.components.VScrollBar.

      (See attached txt for full trace stack.)


      I'm using Flex 4.0 beta 2 and Flash Builder beta 2.


      Also, I found this article on per Module StyleManager which does not look like it has been implemented and is basically exactly what I'm trying to accomplish but with a SWFLoader instead ofModule.


      If someone could please explain or point me in the right direction on how to either 1. load Flex 4 beta 2 application as a sub application domain app without generating VScollBar error (and if that will even solve overwriting CSS styles issue). or 2. how to load StyleManager.loadStyleDeclaration() from an embedded css or swf, I would greatly appreciate it.


      Thank you in advance,

      Ilya Voloshin