簡體   English   中英

已發布的Adobe Air應用程序出現問題

[英]Problem with published Adobe Air Application

我有一個Air應用程序(Adobe Flash CS4,Adobe AIR 1.1,ActionScript 3.0)。 我已經將其發布為* .air文件,並將其安裝在我的計算機上。 工作正常。 但是,當我嘗試在另一台計算機上使用它時,發現了以下問題:

  1. 我從http://get.adobe.com/ru/air/安裝了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();
    }
}

我試圖在Main()中注釋幾個命令。 因此,代碼無需

var panoramaPattern=new XML(str);

此命令有什么問題? pattern.xml已包含在“包含的文件”中。

我想象發生了什么事,一旦您的swf的主類(在上面)被創建(就在初始化時),ENTER_FRAME事件就會將事件偵聽器綁定到按鈕,但是該按鈕在技術上並不存在。 您在此處進行初始化的方法是一種非常不好的做法,但請允許我解釋一下這是如何工作的。

每當您擁有擴展DisplayObject類型的類時,都應始終創建經過修改的構造函數,以檢測“ stage”元素,如果該元素不存在,請偵聽ADDED_TO_STAGE事件,然后執行顯示-回調中基於對象的初始化。 這是因為基於顯示對象的類是以半確定的方式創建的。 創建/實例化該類后,構造函數將立即被調用,但是該類的屬性和方法(包括作為顯示對象的子級(如本例中的按鈕等))才可用,直到將該類添加到全局“階段”對象。

對於AIR,您的NativeWindow對象包含該NativeWindow的所有子級都繼承的“ stage”的單個實例。 因此,當您在舞台上添加MovieClip或Sprite等時,該顯示對象的“ stage”屬性將使用對NativeWindow中包含的全局舞台對象的引用進行填充。 因此,請始終記住,涉及Flash時,處理構造函數/顯示對象初始化的做法是將所有功能延遲到僅在全局“階段”可供參考時才處理的回調。 以下是使用您的代碼的示例:

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");
    }

}

最后,我強烈建議您觀看本站點上的一些免費視頻教程,因為其中涵蓋了廣泛的主題,它們將教給您很多有關Flash的知識。

http://gotoandlearn.com/

我找到了解決方案。

  1. 我已經將pattern.xml的編碼更改為ANSI

  2. 我已將XML加載算法更改為此

有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM