Is using Flex CSS stylesheets a waste of time?
I'm quite new to Flex and wondered if other developers actually use its stylesheet capabilities? The reason I'm asking is that to my inexperienced eye it seems like a complete waste of time.
The things that Flex calls CSS clearly isn't, it's some other beast altogether with css like syntax. As many dimension properties can't be set in the stylesheet the main reason for using CSS i.e separation of content from presentation is missing. This is compounded by the countless other missing features.
This has made me think it's probably a far more sensible move to just keep all of my style declaration right there in the mxml just to keep it all in one place.
Is this the best way or a开发者_开发问答m I totally missing something?
In Flex the stylesheets are used to define the style properties of objects. If you wanted to write a component where the layout and positions were defined by styles you could. On the other hand, if you wanted to avoid using CSS and styles completely, you could also write a component that did that (though not likely without using x.setStyle(...) calls on library components).
That being said, they're as useful as you want to make them. I can give you a few examples as to when they're useful:
Themes. It's more convenient to change your themes (fonts, colors, etc...) in one file than to find all places in the code where a particular font or color is used and make those changes. Plus how would you create alternative themes without compiler directives splattered throughout code?
Cleaner code. Rather than having 5 or 10 lines of "setStyle" calls in each of your AS3 components, or having to pollute your mxml tags with repetitive style declarations, you can just assign the "stylename" property and make the changes when you need inside the css.
I thought I was going to have more, but these pretty much cover any other scenarios I was thinking of. e.g., overriding Flex default styles, setting system-wide fonts, etc...
All this being said, I'm not a huge fan of CSS anywhere (browser or flash) as it exists today. Good intentions, bad execution. But c'est la vie. A broken hammer is still better than nothing.
The best thing it is used for is consistant branding appearance across different apps. Just move your CSS file and get the same styles as all your other apps. Takes more work to do that if it is all hard coded.
You also might want to check this. It's about the next version of flex, but it has a lot of improvements in designer/developer workflow.
精彩评论