2010-03-24

Loading CSS at runtime

Just spent like 7 hours trying to debug a problem and finally found the solution by reading someone's blog. Basically was trying to load the CSS settings at runtime in my Flex 3 application. It didn't work at all, kept getting the following error:

Error #1034: Type Coercion failed: cannot convert bla to IFlexModule

Finally the problem was... the CSS filename (bla.css), was the same as the application MXML file (bla.mxml)! Changing the name of the CSS file to something different (app.css) basically solved the problem. Guess when you compile a CSS file to SWF, internally the generated ActionScript class is named the same as your CSS file and thus conflicts with the main application classname.

To learn how to load at runtime, read the "Loading style sheets at run time" in the Flex Livedocs.

1 comment:

Anonymous said...

Another weird thing, you can't name an Application mxml "prototype.mxml". It'll run locally w/i Flash/Flex Builder, but it won't via command line builds and you get this. Joys of Flex.

[ERROR] Type was not found or was not a compile-time constant: prototype. [Generated code (use -keep to save): Path: prototype-generated.as, Line: 682, Column: 14]