未绑定元素的前缀 [英] Prefix for element not bound
问题描述
我是 Flex 开发的新手,正在使用 Flash Builder 4 和 SDK 4.现在我在第 4 行收到未绑定元素fx:Style"的前缀fx"的错误.我搜索了它,它有……与命名空间有关,但我自己无法解决.
I am a newbie in Flex development and using Flash Builder 4 with SDK 4. Now I get the error that "the prefix "fx" for element "fx:Style" is not bound" in line number 4. I searched for it, and it has sth. to do with namespaces, but I can not solve it by myelf.
我在目录components"中有名为UserStory.mxml"的文件,通过main.mxml将其放置到屏幕上:
I have the file called "UserStory.mxml" in the directory "components" to place it via the main.mxml onto the screen:
<fx:Script>
<![CDATA[
import components.UserStory;
private function init():void {
var userStory1:UserStory = new UserStory();
userStory1.x = 100;
userStory1.y = 100;
userStory1.userStoryText = "test";
this.addChild(userStory1);
}
]]>
</fx:Script>
第 1 行出现错误的文件.4:
The file in which the error occurs in line no. 4:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="300" height="150" styleName="userstory">
<fx:Style source="styles/styles.css"/>
<fx:Text x="5" y="5" width="275" height="135" text="{userStoryText}" fontFamily="notes" fontSize="18"/>
<mx:Script>
...
</mx:Script>
</mx:Canvas>
谁能告诉我怎么了?
推荐答案
正如您怀疑是命名空间的问题.MXML 只是 XML,在 XML 中,您可以定义命名空间并将它们绑定到 URL.命名空间是 XML 元素冒号之前的部分,通常在封闭元素上定义.
As you suspected it is a problem with the namespace. MXML is just XML and in XML you can define namespaces and bind them to a URL. The namespaces are the part before the colon of an XML element and are usually defined on the enclosing element.
如果您查看 MXML 文件,您会看到 mx
命名空间的一个命名空间声明:
If you look at your MXML file you'll see one namespace declaration for the mx
namespace:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" ...
fx
的声明丢失了,这就是编译器所抱怨的.添加适当的定义,您应该没问题(请参阅 此页面更多详情):
The declaration for fx
is missing and that's what the compiler complains about. Add the appropriate definition and you should be fine (see this page for more details):
<mx:Canvas xmlns:fx="http://ns.adobe.com/mxml/2009" ...
此外,如果您使用的是 Flex 4,您应该查看该文件,因为 mx:Canvas
是一个 Flex 3 组件,因此不能直接在 Flex 4 应用程序中使用.看看 API用于 Flex 4 SDK 的 Canvas 文档.
Also, if you are using Flex 4 you should review the file as mx:Canvas
is a Flex 3 component and as such not directly usable in Flex 4 apps. Have a look at the API docs of Canvas for the Flex 4 SDK.
这篇关于未绑定元素的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!