如何获取组件的命名空间?
How do you get the namespace of a component?
我正在尝试动态编写 CSS 样式表,但 Flex 4 要求您在样式标记中声明名称空间。
如果我有一个 Spark Button 或 MX Button class 或 class 实例,我将如何获得该按钮的命名空间?
到目前为止我试过这个:
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>
我希望能够在运行时获取此信息,但设计时也可以接受。
与MXML代码中的命名空间格式相同。即,如果您在 com.xyzzy.components 中有组件,则 MXML 名称空间类似于
xmlns:components="com.xyzzy.components.*"
CSS 命名空间就像
@namespace components "com.xyzzy.components.*";
components|myButton {...}
看起来我无法在运行时获取它,但我可以从 SDK 目录中获取它的 XML 文件并创建 类 的 table 及其命名空间。
在 $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 文档为每个节点添加必要的命名空间。
我正在尝试动态编写 CSS 样式表,但 Flex 4 要求您在样式标记中声明名称空间。
如果我有一个 Spark Button 或 MX Button class 或 class 实例,我将如何获得该按钮的命名空间?
到目前为止我试过这个:
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>
我希望能够在运行时获取此信息,但设计时也可以接受。
与MXML代码中的命名空间格式相同。即,如果您在 com.xyzzy.components 中有组件,则 MXML 名称空间类似于
xmlns:components="com.xyzzy.components.*"
CSS 命名空间就像
@namespace components "com.xyzzy.components.*";
components|myButton {...}
看起来我无法在运行时获取它,但我可以从 SDK 目录中获取它的 XML 文件并创建 类 的 table 及其命名空间。
在 $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 文档为每个节点添加必要的命名空间。