views:

28

answers:

1

Hi

I had a custom MXML component, that I have converted to a pure AS3 component that extends Canvas. I took the stylings i.e. alpha, color etc. from the MXML and added them to a .css file under /src/assets/.

My question is, how do I apply these styles within the custom AS3 component i.e. constructor or init()?

I read that you declare the style source only in your MainApp.mxml using <mx:Style source="assets/css/swimlaneStyle.css"/>. If so, then how do I then apply it?

The .css example is below

/* CSS file */

Canvas.roundedCanvasYellow{ 
    backgroundColor:#ffffcc; 
    cornerRadius:5; 
    dropShadowEnabled:true;
    dropShadowColor:#2A2929;
    borderStyle:solid;
    borderThickness:0; 
    backgroundAlpha:0.9;    
}
+1  A: 

Should be as straight forward as doing: this.styleName = "roundedCanvasYellow" (I've use 'this.' in my example just to make it clear, you usually wouldn't include that in your real code). Or when you create in instance of your component programmatically do" instance.styleName = "roundedCanvasYellow", or if you create an instance in mxml just set the styleName attribute as normal.

Gavin Lauchlan
Spot on. That worked. It doesnt work if I leave in the Canvas keyword: this.styleName="Canvas.roundedCanvasYellow". I see now that once the styleSheet is registered in the MainApp, its then accessible to the other classes, sweet.
Brian Bishop