寻找CSS解析器写在AS3 [英] Looking for CSS parser written in AS3
问题描述
我需要<一个href="http://stackoverflow.com/questions/204924/how-do-you-dynamically-load-a-css-file-into-a-flex-application">load并应用CSS在运行时在我的Flex应用。我知道的Adobe文档说,你需要编译加载的,但我想发现身边工作之前,CSS。
I need to load and apply CSS at runtime in my Flex app. I know that the adobe docs say that you need to compile the CSS before loading it but I would like to find a work around.
我知道,你可以设置单独的样式是这样的:
I know that you can set individual styles like this:
cssStyle = new CSSStyleDeclaration();
cssStyle.setStyle("color", "<valid color>);
FlexGlobals.topLevelApplication.styleManager.setStyleDeclaration("Button", cssStyle, true);
我打算解析CSS文件和appling如上每个属性。
I was planning on parsing a CSS file and appling each attribute as above.
我在想,如果:
- 的Adobe有这样我可以使用CSS解析库
- 在别人有,我可以使用CSS语法分析器
- 如果我写我自己的CSS解析器,我应该注意
我知道土坯flex.text.StyleSheet类有一个CSS解析器,但我无法找到一个方法来利用这一点。 (有没有一种方法来获取源$ C $ C?)
I know that the adobe flex.text.StyleSheet class has a CSS parser but I could not find a way to harness that. (Is there a way to get that source code?)
推荐答案
编辑:此解决方案不起作用。被取出解析器的所有选择都转换为小写。这可能对您的应用程序,但它可能会无法... 的
我要离开这个答案在这里,因为它可以帮助一些人寻找一个解决方案,并警告其他人的这种方法的局限性。的
虽然它不用于这有可能使用样式表
类来分析CSS。我目前正在研究如何强劲,这是当前但在大多数情况下它似乎是工作。
Although it was not intended for this it is possible to use the StyleSheet
class to parse the CSS. I am currently investigating how robust this is currently but for the most part it appears to be working.
public function extractFromStyleSheet(css:String):void {
// Create a StyleSheet Object
var styleSheet:StyleSheet = new StyleSheet();
styleSheet.parseCSS(css);
// Iterate through the selector objects
var selectorNames:Array = styleSheet.styleNames;
for(var i:int=0; i<selectorNames.length; i++){
// Do something with each selector
trace("Selector: "+selelectorNames[i];
var properties:Object = styleSheet.getStyle(selectorNames[i]);
for (var property:String in properties){
// Do something with each property in the selector
trace("\t"+property+" -> "+properties[property]+"\n");
}
}
}
这篇关于寻找CSS解析器写在AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!