将基于 Sprite 的 SWF 文件转换为 mxml
我使用 AS3 编写了一个大型 Actionscript 项目作为 Flash Builder 4.5 中的“Actionscript 项目”。我有一堆可靠的、可重用的代码,但其中一个重要的组件是 main.as 文件,它扩展了 Sprite 并用作我的应用程序的显示代码。
现在,出于各种原因,我需要将其作为 Flex 应用程序。我试图获得尽可能小的包装器,所以这就是我所拥有的(感谢互联网):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="590" minHeight="700"
initialize="initPlayer()">`
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
public function initPlayer():void {
Alert.show("Testing!");
var comp:UIComponent = new UIComponent();
comp.addChild(new MainView());
addChild(comp);
}
]]>
</fx:Script>
</s:Application>
但是,当我启动它时,它会出现一个空白窗口。没有错误,警报没有触发,什么都没有。知道发生了什么事吗?
I wrote a big Actionscript project using AS3 as an "Actionscript Project" in Flash Builder 4.5. I have a bunch of solid, reusable, code, but one of the big components is a main.as file that extends Sprite and serves as the display code for my application.
I now, for various reasons, need that to be a Flex application. I'm trying to get the most minimal wrapper possible, so here's what I have (thanks to the internet):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="590" minHeight="700"
initialize="initPlayer()">`
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.UIComponent;
public function initPlayer():void {
Alert.show("Testing!");
var comp:UIComponent = new UIComponent();
comp.addChild(new MainView());
addChild(comp);
}
]]>
</fx:Script>
</s:Application>
when I launch this, however, it comes up with a blank window. No errors, the alert doesn't fire, nothing. Any idea what's going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
applicationComplete
而不是initialize
。初始化是在应用程序生命周期的早期触发的,像addChild
这样的事情更适合在周期的后期进行(applicationComplete
对应于creationComplete
子组件)。Try using
applicationComplete
instead ofinitialize
. initialize is triggered early in the application life cycle, and stuff like doingaddChild
is better suited later on in the cycle (applicationComplete
corresponds tocreationComplete
in sub components).我使用一个简单的精灵类“TestSprite”而不是“MainView”。有用。警报和 TestSprite 都可以工作。所以,我认为你的“MainView”中一定有一些东西阻止了弹性显示它。
I use a simple sprite class "TestSprite" instead your "MainView". It works. Both the alert ahd the TestSprite works. so, i think there must be something in your "MainView" prevent flex display it.