2011-04-02 73 views
0

我有一个Air Application(Adobe Flash CS4,Adobe AIR 1.1,ActionScript 3.0)。我已经将它发布为* .air文件并将其安装在我的电脑上。它运行良好。但是,当我试图使用它在其他计算机上,我发现了以下问题:已发布Adobe Air应用程序问题

  1. 我安装了空气http://get.adobe.com/ru/air/
  2. 我安装我的Main.air并启动它。
  3. 它无法正确解析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(); 
    } 
} 

我试图在主要的置评几个命令()。所以,代码没有工作

var panoramaPattern=new XML(str); 

这个命令有什么问题? pattern.xml包含在“包含的文件”中。

回答

-1

我找到了解决方案。

  1. 我已经改变pattern.xml的编码为ANSI

  2. 我已经改变XML负载算法this one

它的工作原理!

1

我想象一下发生的事情是,只要你的swf的主要类在这里(上面)创建(在初始化时),ENTER_FRAME事件绑定事件监听器到按钮,但按钮在技术上并不存在。你在这里初始化的方法是非常糟糕的做法,但请允许我解释这是如何工作的。当你有一个扩展DisplayObject类的类时,你总是应该创建一个修改过的构造函数来检测“stage”元素,如果它不存在,那么监听ADDED_TO_STAGE事件,然后在回调中执行基于显示对象的初始化。这是因为基于显示对象的类是以一种半途而废的方式创建的。构造函数在类被创建/实例化时立即被调用,但是该类的属性和方法(包括作为显示对象的子对象(在本例中为按钮等))只有在类被添加到全局“舞台“的对象。

对于AIR,您的NativeWindow对象包含该“NativeWindow”的所有子项都继承的单个“stage”实例。因此,当您向舞台添加MovieClip或Sprite等时,该显示对象的“stage”属性将填充NativeWindow中包含的全局舞台对象的引用。所以一定要记住,在处理构造函数/初始化显示对象时,闪存的做法是将所有功能延迟到仅当全局“stage”可用于引用时才处理的回调。下面是使用代码的例子:

public class Main extends MovieClip {  

    public function Main():void 
    { 
     if(stage){ 
      init(); 
     }else{ 
      this.addEventListener(Event.ADDED_TO_STAGE, init); 
     } 
    } 

    //Can be private or public, doesn't matter private is better practice 
    private function init(e:Event = null) 
    { 
     //Notice the function paramter has a default value assigned of null. This is required so we can call this function without args as in the constructor  

     //Also the flag variable is not necessary because this function is called once 
     btnDialogCreate.addEventListener(MouseEvent.CLICK,CreateProject);   
    } 

    //Also it is generally considered bad practice to put capitals on the start of your function/variable names. Generally only classes are named this way ie: Main. 
    public function createProject(e:MouseEvent){ 
     //You do not need a try/catch statement for simply opening a file browser dialogue. This is a native method you're invoking with a native, predefined default directories inside the VM. Flash is already doing this for you 
     var directory:File=File.documentsDirectory; 
     directory.browseForDirectory("Directory of project"); 
    } 

} 

最后,我会强烈建议看一些本网站上的免费视频教程,因为有广泛的议题覆盖,将教你很多关于闪光。

http://gotoandlearn.com/

相关问题