Air 无法从应用程序存储目录加载SWF

Air 无法从应用程序存储目录加载SWF,air,loader,Air,Loader,在发布我的AIR应用程序(CurrentFile)时,我还将chatFile.swf与安装文件一起包括在内。 在我的AIR设置面板[AIR 3.7 for Desktop]中的“包含文件”下,我有以下内容: CurrentFile.swf CurrentFile-app.xml chatFile.swf 以下是my CurrentFile.swf中的AS3代码: import flash.net.URLRequest; import flash.events.Event; impor

在发布我的AIR应用程序(CurrentFile)时,我还将chatFile.swf与安装文件一起包括在内。 在我的AIR设置面板[AIR 3.7 for Desktop]中的“包含文件”下,我有以下内容:

  • CurrentFile.swf
  • CurrentFile-app.xml
  • chatFile.swf
以下是my CurrentFile.swf中的AS3代码:

import flash.net.URLRequest;
import flash.events.Event;    
import flash.display.Loader;
import flash.filesystem.File;
var chatLoaderWindow:Loader;    
    function loadchat(m:MouseEvent):void
    {

        chatLoaderWindow = new Loader();
        chatLoaderWindow.contentLoaderInfo.addEventListener(Event.COMPLETE, chatLoadComplete);
        chatLoaderWindow.contentLoaderInfo.addEventListener(Event.INIT, chatInitLoad);
        chatLoaderWindow.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, chatErrorLoad);
        chatLoaderWindow.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, chatHttpStatus);
        myclip.chatwindow.addChild(chatLoaderWindow);
        var f:File = File.applicationStorageDirectory.resolvePath("chatFile.swf");
        chatLoaderWindow.load(new URLRequest(f.url));
        tracebox.text = "Chat URL" + f.url;
    }
    function chatLoadComplete(e:Event):void
    {
        tracebox.text = "chat loaded";

    }
    function chatErrorLoad(io:IOErrorEvent):void
    {
        tracebox.text = "chat IO Error: "+io;

    }
    function chatInitLoad(i:Event):void
    {
        tracebox.text = "chat INIT";

    }
    function chatHttpStatus(e:HTTPStatusEvent):void
    {
        tracebox.text = "chat Http"+e;

    }
    myclip.chatbut.addEventListener(MouseEvent.CLICK,loadchat);


    /*
    Output:
    chat IO Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2035" errorID=2035]
编辑:我想出来了。这真的很简单

这不是必需的:

var f:File = File.applicationStorageDirectory.resolvePath("chatFile.swf");
chatLoaderWindow.load(new URLRequest(f.url));
插入以下内容:

chatLoaderWindow.load(new URLRequest("app:/chatFile.swf"));
现在我的问题是:
File.applicationStorageDirectory.resolvePath的用途是什么?

这里有两个目录。一个是“应用程序”目录,安装文件放置在该目录中。一个是“应用程序存储”目录,它是运行时写入文件的方便地方。要访问这些目录,您可以使用File.resolvePath()函数或使用URI方案快捷方式app:或app storage:。在最初的尝试中,您只是在错误的目录中查找文件。

file.applicationStorageDirectory.resolvePath(“somefile.swf”)。url将等于“应用程序存储:/somefile.swf”

File.applicationDirectory.resolvePath(“somefile.swf”).url将等于“app:/somefile.swf”

应用程序目录是安装应用程序的位置。应用程序存储目录是应用程序可以保存文件的文件夹

resolvePath()返回一个文件对象。您可以将其用于获取文件位置的跨平台url以外的目的,例如fileObj.exists和fileObj.parent.createDirectory()。fileObj.url正是您将与URLLoader一起使用的url,用于以独立于平台的方式访问文件