Nik*_*hil 10 apache-flex actionscript-3
从本教程http://www.brighthub.com/internet/web-development/articles/11010.aspx 我找到了下面的代码.有没有办法打破这个,所以mxml文件只有mxml,脚本标签之间的代码放在actionscript文件中?
谢谢.
-缺口
<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>
Run Code Online (Sandbox Code Playgroud)
bed*_*wyr 12
有几种方法可以在Flex中实现这一目标:
<mx:Script source="yourfile.as" />
您还可以使用includes="yourfile.as"脚本标记中的声明:
<mx:Script
<![CDATA[
include "yourfile.as";
//Other functions
]]>
</mx:Script>
Run Code Online (Sandbox Code Playgroud)
Application):AS档案:
package {
public class MainAppClass {
//Your imports here
public function CreationComplete():void {
}
public function EnterFrame(event:Event):void {
}
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
使用框架将您正在寻找的功能注入一种"模型",其中包含您将使用的数据功能.它看起来事情是这样的香菜:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
width="600"
height="400"
frameRate="100"
creationComplete="model.CreationComplete()"
enterFrame="model.EnterFrame(event)">
<mx:Script>
<![CDATA[
[Inject]
[Bindable]
public var model:YourModelClass;
]]>
</mx:Script>
</mx:Application>
Run Code Online (Sandbox Code Playgroud)我不确定代码隐藏模式是否适用于主MXML文件(扩展了应用程序),因此如果您遇到问题,可以尝试将主MXML文件中的内容分解为单独的组件,其中包含在主要.它可能看起来像这样:
Main.mxml:
<mx:Application blah,blah,blah>
<component:YourComponent />
</mx:Application>
Run Code Online (Sandbox Code Playgroud)
YourComponent.mxml:
<component:YourComponentCodeBehind creationComplete="model.creationComplete()"...>
//Whatever MXML content you would have put in the Main file, put in here
</component:YourComponentCodeBehind>
Run Code Online (Sandbox Code Playgroud)
YourComponentCodeBehind.as
package {
class YourComponentCodeBehind {
//Whatever AS content you would have put in the Main .as file, put in here
}
}
Run Code Online (Sandbox Code Playgroud)
从我从Flex架构中收集的内容来看,这是设置应用程序的一种非常常见的方式:主MXML包含一个"视图",它是应用程序其余部分的入口点.此视图包含构成应用程序的所有其他视图.
希望有道理:)
| 归档时间: |
|
| 查看次数: |
5514 次 |
| 最近记录: |