Actionscript 3 如何获取组件的名称空间?
我试图动态地编写CSS样式表,但Flex4要求您在样式标记中声明名称空间 如果我有一个Spark Button或MX Button类或类实例,我将如何获得该按钮的名称空间 到目前为止,我已经尝试过:Actionscript 3 如何获取组件的名称空间?,actionscript-3,flash,apache-flex,flex4,flex4.6,Actionscript 3,Flash,Apache Flex,Flex4,Flex4.6,我试图动态地编写CSS样式表,但Flex4要求您在样式标记中声明名称空间 如果我有一个Spark Button或MX Button类或类实例,我将如何获得该按钮的名称空间 到目前为止,我已经尝试过: var className:Object = getQualifiedClassName(myButton); var ButtonClass:Object = ApplicationDomain.currentDomain.getDefinition(className); var button:
var className:Object = getQualifiedClassName(myButton);
var ButtonClass:Object = ApplicationDomain.currentDomain.getDefinition(className);
var button:Object = new ButtonClass();
有了这些信息,我可以写下:
<fx:Style>
myButton {
color: red;
}
</fx:Style>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
s|Button {
color: red;
}
</fx:Style>
我需要创建以下内容:
<fx:Style>
myButton {
color: red;
}
</fx:Style>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
s|Button {
color: red;
}
</fx:Style>
我希望能够在运行时获得这些信息,但设计时也可以接受 它的格式与MXML代码中的名称空间相同。也就是说,如果com.xyzy.components中有组件,那么MXML名称空间类似于
xmlns:components="com.xyzzy.components.*"
CSS名称空间如下所示
@namespace components "com.xyzzy.components.*";
components|myButton {...}
看起来我无法在运行时获取它,但我可以从SDK目录获取它的XML文件,并创建一个类及其命名空间的表
<!-- Specify a URI to associate with a manifest of components for use as MXML -->
<!-- elements. -->
<namespace>
<uri>http://ns.adobe.com/mxml/2009</uri>
<manifest>mxml-2009-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/spark</uri>
<manifest>spark-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/mx</uri>
<manifest>mx-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://www.adobe.com/2006/mxml</uri>
<manifest>mxml-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/ns</uri>
<manifest>apache-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/experimental/ns</uri>
<manifest>experimental-manifest.xml</manifest>
</namespace>
</namespaces>
在$FlashBuilder/sdks/4.6.0/frameworks/flex-config.xml中,有一个名为namespaces的节点,该节点包含名称空间的URI,然后是对xml文件的引用,该文件包含该名称空间中的类列表
<!-- Specify a URI to associate with a manifest of components for use as MXML -->
<!-- elements. -->
<namespace>
<uri>http://ns.adobe.com/mxml/2009</uri>
<manifest>mxml-2009-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/spark</uri>
<manifest>spark-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/mx</uri>
<manifest>mx-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://www.adobe.com/2006/mxml</uri>
<manifest>mxml-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/ns</uri>
<manifest>apache-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/experimental/ns</uri>
<manifest>experimental-manifest.xml</manifest>
</namespace>
</namespaces>
我可以使用这些信息和MXML文档向每个节点添加必要的名称空间 但OP的问题是如何使用代码编写这种CSS,而不是在MXML中手动声明。