1
import flash.filesystem.*;
/// Change the line below to point to your mp3 online
var urlString:String = "http://edvizenor.com/upload/php/files/trust.mp3";
var urlReq:URLRequest = new URLRequest(urlString);
var urlStream:URLStream = new URLStream();
var fileData:ByteArray = new ByteArray();
urlStream.addEventListener(Event.COMPLETE, loaded);
urlStream.load(urlReq);

function loaded(event:Event):void
{
    urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
    writeAirFile();
}

function writeAirFile():void
{ 
    // Change the folder path to whatever you want plus name your mp3
    // If the folder or folders does not exist it will create it.

以下是我需要帮助的内容:

var file:File = File.userDirectory.resolvePath("Yahoo.mp3");// WORKS
var file:File = File.applicationDirectory.resolvePath("Yahoo.mp3"); // NO WORK

我需要得到这第二行以保存到它存储的目录。任何想法我做错了什么?

    var fileStream:FileStream = new FileStream();
    fileStream.open(file, FileMode.WRITE);
    fileStream.writeBytes(fileData, 0, fileData.length);
    fileStream.close();
    trace("The file is written.");
}
4

1 回答 1

0

保存在应用程序目录中。采用

var file:File = File.userDirectory.resolvePath("Yahoo.mp3");// WORKS
var file:File = File.applicationStorageDirectory.resolvePath("Yahoo.mp3"); // It will work


var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The file is written.");

}

因为应用程序目录是你的应用程序的包目录。

于 2012-08-28T05:36:47.323 回答