簡體   English   中英

如何在ActionScript中編碼為我的APK包含的幾個SWF文件的確切文件位置?

[英]How do I code in actionscript the exact file location for several swf I have included for my apk?

在Android版Air設置的“包含文件”部分中,我將test1.swf和test2.swf添加到了自動包含的主文件中。 那么以下內容是否正確:

myLoader.load(new URLRequest("test1.swf")

或者,我還應該包含其他文件夾嗎? 以下內容正確嗎?

myLoader.load(new URLRequest("\..\..test1.swf")

我現在無法在Android上對此進行測試,但是我相信包含的文件位於應用程序目錄中,您可以按以下方式訪問該文件:

var path:String = File.applicationDirectory.resolvePath("test1.swf").nativePath;

myLoader.load(new URLRequest(path));

您還可以使用以下縮寫網址:

myLoader.load(new URLRequest("app://test1.swf"));

您還可以使用FileStream類加載swf,這使您可以更好地控制事物。 看起來像這樣:

    var file:File = File.applicationDirectory.resolvePath("test1.swf");

    if (file.exists) {
        var swfData:ByteArray = new ByteArray();
        var stream:FileStream = new FileStream();
        stream.open(file, FileMode.READ);
        stream.readBytes(swfData);
        stream.close();

        var myLoader:Loader = new Loader();
        var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
        loaderContext.allowCodeImport = true;

        myLoader.loadBytes(swfData, loaderContext);
        addChild(myLoader);

    }else {
        trace("file doesn't exist");
    }

暫無
暫無

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

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