在本教程http://www.brighthub.com/internet/web-development/articles/11010.aspx中,我找到了下面的代码。有没有办法打破这一点,使mxml文件只有mxml,而脚本标记之间的代码放在一个actionscript文件中?
谢谢。
-Nick
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="600"
height="400"
frameRate="100"
creationComplete="CreationComplete()"
enterFrame="EnterFrame(event)">
<mx:Script><![CDATA[
public function CreationComplete():void
{
}
public function EnterFrame(event:Event):void
{
}
]]></mx:Script>
</mx:Application>发布于 2011-01-08 14:24:58
在Flex中有几种方法可以实现这一点:
<mx:Script source="yourfile.as" />
您还可以在脚本标记中使用includes="yourfile.as"声明w/:
<mx:Script
<![CDATA[
include "yourfile.as";
//Other functions
]]>
</mx:Script>Application):的主MXML文件
作为文件:
package {
public class MainAppClass {
//Your imports here
public function CreationComplete():void {
}
public function EnterFrame(event:Event):void {
}
}
}MXML文件:
<component:MainAppClass xmlns:component="your namespace here"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="600"
height="400"
frameRate="100"
creationComplete="CreationComplete()"
enterFrame="EnterFrame(event)">
</component:MainAppClass>http://www.adobe.com/2006/mxml“layout="absolute”width="600“height="400”frameRate="100“creationComplete="model.CreationComplete()”enterFrame="model.EnterFrame(event)">脚本 >
脑海中浮现出两个框架,它们可以帮助使用注入,它们是Mate或Parsley。
我不确定代码隐藏模式是否适用于主MXML文件(它扩展了Application),因此如果您遇到问题,可以尝试将主MXML文件中的内容分解为一个单独的组件,该组件包含在Main中。它可能看起来像这样:
Main.mxml:
<mx:Application blah,blah,blah>
<component:YourComponent />
</mx:Application>YourComponent.mxml:
<component:YourComponentCodeBehind creationComplete="model.creationComplete()"...>
//Whatever MXML content you would have put in the Main file, put in here
</component:YourComponentCodeBehind>YourComponentCodeBehind.as
package {
class YourComponentCodeBehind {
//Whatever AS content you would have put in the Main .as file, put in here
}
}根据我从Flex架构收集到的信息,这是设置应用程序的一种非常常见的方法:您的主MXML包含一个“视图”,它是应用程序其余部分的入口点。此视图包含组成应用程序的所有其他视图。
希望这是有意义的:)
https://stackoverflow.com/questions/4632490
复制相似问题