【问题标题】:How do you get the namespace of a component?如何获取组件的命名空间?
【发布时间】:2015-08-29 12:09:35
【问题描述】:

我正在尝试动态编写 CSS 样式表,但 Flex 4 要求您在样式标记中声明命名空间。

如果我有一个 Spark Button 或 MX 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>

我希望能够在运行时获取此信息,但设计时也可以接受。

【问题讨论】:

    标签: actionscript-3 flash apache-flex flex4 flex4.6


    【解决方案1】:

    与 MXML 代码中的命名空间格式相同。即,如果您在 com.xyzzy.components 中有组件,则 MXML 命名空间类似于

    xmlns:components="com.xyzzy.components.*"
    

    CSS 命名空间是这样的

    @namespace components "com.xyzzy.components.*";
    components|myButton {...}
    

    【讨论】:

    • 但是 OP 的问题是关于编写这种 CSS 使用代码,而不是在 MXML 中手动声明它。
    【解决方案2】:

    看起来我无法在运行时获取它,但我可以从 SDK 目录获取 XML 文件并创建一个类表及其命名空间。

    在 $FlashBuilder/sdks/4.6.0/frameworks/flex-config.xml 中有一个名为命名空间的节点,其中包含命名空间的 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 文档将必要的名称空间添加到每个节点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多