如何让 FlashBuilder 使用自定义命名空间前缀
我有一个组件库。它有一个如下所示的清单文件:
<?xml version="1.0"?>
<componentPackage>
<component id="AutoComplete" class="be.edge.components.AutoComplete" />
<!-- more components left out for brevity -->
</componentPackage>
我使用以下编译器设置通过 FlashBuilder 编译该库:
当我在其他 FlashBuilder 项目中使用编译后的库时,一切都按预期工作。我获得了代码完成,当我从代码完成中选择建议时,名称空间属性会自动添加到组件中,如下所示:
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns="library://ns.edge.be" >
<ns:AutoComplete />
</s:Skin>
但是: FlashBuilder 会自动创建前缀“ns”。例如,我想将其自定义为“e”。如何让 FlashBuilder 默认使用此自定义前缀?
我这样做有两个原因:
- “ns”没有说什么:它只是说命名空间已被使用,而不是什么命名空间。
- 当我使用其他也以“library://ns”等 url 开头的库时。 FlashBuilder 可能会开始对前缀进行编号来解决冲突(ns、ns1、ns2 等),这会更加令人困惑。
编辑:
我还将 config.xml 传递给编译器,其中包含以下与命名空间相关的声明:
<compiler>
<namespaces>
<namespace>
<uri>library://ns.edge.be</uri>
<manifest>manifest.xml</manifest>
</namespace>
</namespaces>
</compiler>
<include-namespaces>
<uri>library://ns.edge.be</uri>
</include-namespaces>
I have a component library. It has a manifest file that looks like this:
<?xml version="1.0"?>
<componentPackage>
<component id="AutoComplete" class="be.edge.components.AutoComplete" />
<!-- more components left out for brevity -->
</componentPackage>
I compile the library through FlashBuilder with these compiler settings:
When I use the compiled library in other FlashBuilder projects everything works as expected. I get code completion and when I select a suggestion from the code completion a namespace attribute is automatically added to the component, like this:
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:ns="library://ns.edge.be" >
<ns:AutoComplete />
</s:Skin>
But: FlashBuilder automatically creates the prefix 'ns'. I would like to customize this to 'e' for instance. How can I make FlashBuilder use this custom prefix by default?
I have two reasons for this:
- 'ns' doesn't say anything: it just says A namespace has been used, not what namespace.
- when I use other libraries that also start with a url like 'library://ns.' FlashBuilder will probably start numbering the prefixes to resolve the conflict (ns, ns1, ns2, etc.), which would be even more confusing.
EDIT:
I also pass a config.xml to the compiler that has the following declarations relating to namespaces:
<compiler>
<namespaces>
<namespace>
<uri>library://ns.edge.be</uri>
<manifest>manifest.xml</manifest>
</namespace>
</namespaces>
</compiler>
<include-namespaces>
<uri>library://ns.edge.be</uri>
</include-namespaces>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这用于工作:
在 /src 文件夹中创建一个名为
design.xml
的文件:在 /src 中创建一个名为
manifest.xml
的文件文件夹:在构建属性中配置您的命名空间 URL 等:

这应该会导致 flash builder 提示如下:(
请注意该类显示为
MyClass
而不是MyClassTag
,命名空间显示为mangos
)但是,我只是尝试这样做,尽管该类是正确重命名,命名空间显示为
ns
。我知道这曾经在 FB3.x 中工作,也许我忘记了一个步骤,或者 FB4.5 破坏了它。This used to work:
Create a file called
design.xml
in your /src folder:Create a file called
manifest.xml
in your /src folder:Configure your Namespace URL, etc in the build properties:

This is supposed to cause flash builder to prompt as follows:
(Note that the class appears as
MyClass
instead ofMyClassTag
, and the namespace appears asmangos
)However, I just tried doing this, and although the class was renamed correctly, the namespace appeared up as
ns
. I know this used to work in FB3.x, maybe I've either forgotten a step, or FB4.5 has broken it.如果您只是将
xmlns:ns
更改为xmlns:e
或xmlns:foo
,则 MXML 解析器将接受更改。更改并不是那么困难,而且我认为没有办法更改它默认生成名称空间的方式。If you just change
xmlns:ns
toxmlns:e
orxmlns:foo
then the MXML parser will pick up on the change. It's not all that difficult to change, and I don't think there is a way to change how it generates namespaces by default.