Experimenting with F*CSS
- Wordpress category:
I've been spending some time using the open source F*CSS library. This is an excellant library designed for flash that lets you apply flash based properties as a css stylesheet. This may not seem like much but it paves the way for adding some very powerfull features to your flash applications.
In this app you'll see the mxml file we are using in the top left, the css file we are using in the top right, and the inflated container with no styles applied on the bottom. Click on any of the three CSS buttons on the far right to apply a different stylesheet to the mxml.
Flex Sample with source code viewer enabled
You will notice the data in the mxml file on the top left never changes, all we are doing is applying the new css file on the top right to the container pictured at the bottom (sorry I used some pretty ugly css layouts, but it's the thought that counts!).
Where this really shines is it turns actionscript (flash / flex code) properties and flex style properties into the same thing. What this means is we can now do html like css transforms on any of our objects in flash and keep all their properties in the same file.
To put it in a form that's easier to grasp, you can very easily create a flash version of : http://csszengarden.com/
The one hiccup I did notice was that this library was primarily designed for Flash without anything in mind for Flex style support. To get around this I implemented the following solution in my test app, which you will need to download the fcss source code in order to compile your project. While it may not be the most efficient solution, it quickly and easily brings in support to fcss for all of flex's native style support as well as the support for standard flash object properties, making the library extremely powerfull for replicating common html transformations.
package com.flashartofwar.fcss.applicators { import com.flashartofwar.fcss.objects.PropertyMapObject; import com.flashartofwar.fcss.utils.PropertyMapUtil; import mx.core.UIComponent; import mx.styles.CSSStyleDeclaration; import mx.styles.StyleManager; public class FlexStyleApplicator extends StyleApplicator { public function FlexStyleApplicator() { super(); } var propMap:PropertyMapObject = PropertyMapUtil.propertyMap(target); var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration(); for (prop in styleObject){ filteredProp = propertyFilter(prop); if(filteredProp == "styleName") { target[filteredProp] = styleObject[prop]; } else if (target.hasOwnProperty(filteredProp)){ target[filteredProp] = valueFilter(styleObject[prop], type); } else{ var value:* = valueFilter(styleObject[prop], type); if(is_numeric(value)) { } newStyleDeclaration.setStyle(filteredProp,value); } } StyleManager.setStyleDeclaration("."+styleObject["styleName"], newStyleDeclaration, true); } trace("Flex Style Applicator, property not set : "+ name); } return true; } return false; } } }
package com.flashartofwar.fcss.stylesheets { import mx.styles.CSSStyleDeclaration; import mx.styles.StyleManager; public class FlexStyleSheet extends FStyleSheet { { super(name); } override public function clear():void{ super.clear(); StyleManager.clearStyleDeclaration(stylesheet.name,false); } var styleSheet:IStyleSheet = super.parseCSS(cssText,useCSSTidy); var newStyleDeclaration:CSSStyleDeclaration = new CSSStyleDeclaration(); newStyleDeclaration.defaultFactory = function():void {} StyleManager.setStyleDeclaration(styleSheet.name, newStyleDeclaration, false); return styleSheet; } } }
The above code creates a FlexStyleApplicator that fcss can use to check for valid flex styles and apply them to flex object classes. you can view the source code in action from the link to the flex file above

Recent comments
25 weeks 5 days ago
27 weeks 13 hours ago
1 year 28 weeks ago
1 year 30 weeks ago
2 years 43 weeks ago
1 year 46 weeks ago
1 year 46 weeks ago
1 year 47 weeks ago
1 year 50 weeks ago
1 year 50 weeks ago