已发布的 Adobe Air 应用程序出现问题
我有一个 Air 应用程序(Adobe Flash CS4、Adobe AIR 1.1、ActionScript 3.0)。我已将其发布为 *.air 文件并将其安装在我的计算机上。效果很好。但是当我尝试在另一台计算机上使用它时,我发现了以下问题:
- 我从 http 安装 AIR: //get.adobe.com/ru/air/
- 我安装了 Main.air 并启动了它。
- 它无法正确解析 XML 文件 (pattern.xml)。
我的应用程序的代码如下:
public class Main extends MovieClip {
public function Main():void
{
this.stop();
var file:File = File.applicationDirectory.resolvePath("pattern.xml");
var fileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
str=str.substr(1);
var panoramaPattern=new XML(str);
fileStream.close();
}
}
我尝试在 Main() 中注释几个命令。那么,代码可以在没有
var panoramaPattern=new XML(str);
此命令的情况下工作吗? pattern.xml 已包含在“包含的文件”中。
I have an Air Application (Adobe Flash CS4, Adobe AIR 1.1, ActionScript 3.0). I've published it as *.air file and installed it on my computer. It worked fine. But when I tried to use it on the other computer, I found the following problem:
- I installed AIR from http://get.adobe.com/ru/air/
- I installed my Main.air and launched it.
- It can't parse XML file (pattern.xml) correctly.
The code of my app is following:
public class Main extends MovieClip {
public function Main():void
{
this.stop();
var file:File = File.applicationDirectory.resolvePath("pattern.xml");
var fileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
str=str.substr(1);
var panoramaPattern=new XML(str);
fileStream.close();
}
}
I tried to comment a several commands in Main(). So, code works without
var panoramaPattern=new XML(str);
What is wrong with this command? pattern.xml was included into "Included files".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想发生的情况是,一旦创建了此处(上面)的 swf 主类(在初始化时),ENTER_FRAME 事件就会将事件侦听器绑定到按钮,但该按钮在技术上并不存在。您在这里初始化的方法是非常糟糕的做法,但请允许我解释一下这一切是如何工作的。
每当您有一个扩展 DisplayObject 类型的类时,您都应该始终创建一个修改后的构造函数,旨在检测“stage”元素,如果它不存在,则侦听 ADDED_TO_STAGE 事件,然后执行您的显示 -回调中基于对象的初始化。这是因为基于显示对象的类是以一种半途而废的方式创建的。创建/实例化类时立即调用构造函数,但该类的属性和方法(包括作为显示对象的子级(如本例中的按钮等))在将该类添加到全局“之前不可用”舞台”对象。
对于 AIR,您的 NativeWindow 对象包含该 NativeWindow 的所有子级都继承的单个“stage”实例。因此,当您将 MovieClip 或 Sprite 等添加到舞台时,该显示对象的“stage”属性将使用对 NativeWindow 中包含的全局舞台对象的引用来填充。因此请永远记住,当涉及到 Flash 时,处理显示对象的构造函数/初始化的做法是将所有功能延迟到仅当全局“阶段”可供引用时才处理的回调。下面是使用您的代码的示例:
最后,我强烈建议您观看该网站上的一些免费视频教程,因为其中涵盖了广泛的主题,可以教您很多有关 Flash 的知识。
http://gotoandlearn.com/
I imagine what is happening is that as soon as your swf's main class here (above) is created (right at initialization), the ENTER_FRAME event is binding the event listener to the button, but the button does not technically exist. Your methodology for initializing here is very bad practice but allow me explain how this all works.
Any time that you have a class that extends a type of DisplayObject, you should ALWAYS create a modified constructor designed to detect the "stage" element, and if it doesn't exist, listen for the ADDED_TO_STAGE event, and then perform your display-object based initializations within the callback. This is because display object based classes are kind of created in a half-assed way. The constructor is called immediately when the class is created/instantiated, but the properties and methods of that class, including children that are display objects (as in this case, buttons etc) are not available until the class has been added to the global "stage" object.
In the case of AIR, your NativeWindow object contains a single instance of "stage" that all children of that NativeWindow inherit. So when you add a MovieClip or a Sprite etc to the stage, the "stage" property of that display object is populated with a reference to the global stage object contained within NativeWindow. So always remember, when it comes to flash the practice with dealing with constructors/initialization of display objects is to delay all functionality to a callback that is processed only when the global "stage" has become available to reference. Below is an example using your code:
Lastly I would highly recommend watching some of the free video tutorials on this site, as there are a wide range of subjects covered that will teach you much about flash.
http://gotoandlearn.com/
我找到了解决方案。
我已将pattern.xml 的编码更改为ANSI
我已将XML 加载算法更改为这个
它有效!
I've found the solution.
I've change the encoding of pattern.xml to ANSI
I've change XML loading algorithm to this one
It works!