For my project, I've got an ActionScript class that is instantiating an MXML component... namely mx.controls.Menu. Now, I know that if I instantiate that component in an MXML file, I can import a stylesheet using this syntax:
and then I can just say myMenu.styleName = "menuStyle" and the style will be applied.
My problem is that I'm not sure how to import that same stylesheet into my AS class and then apply that style to the instance of myMenu. I tried loading the stylesheet in using a URLRequest and Loader and then parsing the CSS with a Stylesheet object. The file loaded and parsed fine but then I didn't know what property to use on myMenu to style it. I tried myMenu.styleName like in the other case but that didn't work.
I know that you can set the stylesheet property of things like text fields that you generate in AS, but that doesn't apply to this MXML component. My only alternative at this point seems to be to use .setStyle but then I have to use inline styles, defeating the purpose of an external CSS file. Do I need to use a metadata tag or something to import the css file?
Any help would be greatly appreciated. Thanks.
In Flex 4, put the component in a SWC with a defaults.css file.
The solution I ended up using was just to reference the CSS file at the root MXML application. Then I could just use .styleName on the Menu component and voila, it worked.