2 Replies Latest reply on Sep 9, 2010 8:40 AM by Budkin76

    Using external stylesheets on generated MXML components in AS3




      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:


      <fx:Style source="myStyles.css"/>


      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.