Skip navigation
Currently Being Moderated

Trying to dynamically load CSS for project at compile time via config XML file to select CSS file.

May 22, 2013 2:43 PM

Tags: #flex #css #stylemanager

I'm using the same code base to compile different versions of a project. Each project has different base fonts. I've created multiple css files that use the same style names. The idea being that in the code I reference the style names, then the loaded CSS determines which font (and size, color, etc) is used for each style name.


The CSS files are compiling to SWFs, and those SWFs are referenced in config.xml files. Before compiling, I select the config file to use.


I am loading the CSS SWF files via the StyleManager in the Application.mxml, like so:

  styleManager.loadStyleDeclarations( _contentData.elements( 'cssPath' ).@path )


The path traces out correctly as:



For some reasone I must include an fx:Style line in the Application.mxml file or no fonts are recognized. Example:

  <fx:Style source="assets_embed/styles/project1.css"/>


If I reference the css for project one (as done above) then most, but not all, styles work. Some styles reference the fonts from the project 1 css, others properly use fonts from project 2 swf. If I point to the CSS for the project I'm compiling in the <fx:Style > tag then all fonts work, but that defeats the goal of using XML rather than code to identify the styles.


So, why do I need the fx:Style line if the css is being loaded via StyleManager?


Why is there "cross talk" between style definitions?


Is there a better way to select styles at compile time?

  • Currently Being Moderated
    May 22, 2013 9:21 PM   in reply to RickAW

    I read this quickly so I might have missed a detail.  I think your describing an issue with recent Flex releases that is described in the fine print somewhere.  If you don't have any fonts embedded in the main app and are only bringing in fonts embedded in CSS SWFs, you have to force-link the EmbeddedFontRegistry by adding something like this to the main app's script block.


     import mx.core.EmbeddedFontRegistry; EmbeddedFontRegistry;


    (Yes, "EmbeddedFontRegistry" is in there twice, once to define the fully qualified name, the other to create a class dependency to force the linking).

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points