Hi,
I'm sure I'm missing something simple. I'm developing an application that will need to have content periodically updated. I wrote some code to download a FLV from the web as a test. But when I try to play it by giving it a source path that equals the native path of the FLV that was downloaded, nothig happens. I noticed that if I manually copied the downloaded file, pasted it to a new location and tried to play it, it worked fine. Also if I copy and paste the file using code, I can play it. Here's the code.
var urlString:String = "http://www.website/test.flv";
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();
}
var mediaPath:String;
function writeAirFile():void{
var file:File = File.applicationStorageDirectory.resolvePath("test.flv"); // 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.");
mediaPath = file.nativePath;
copyFlv()
}
function copyFlv(): void {
var sourceFile:File = File.applicationStorageDirectory.resolvePath("test.flv");
var destination:File = File.applicationDirectory.resolvePath("media/test.flv");
var destinationStr:String = destination.nativePath;
destination = new File(destinationStr);
sourceFile.addEventListener(Event.COMPLETE, fileCopyCompleteHandler);
sourceFile.addEventListener(IOErrorEvent.IO_ERROR, fileMoveIOErrorEventHandler);
sourceFile.copyToAsync(destination, true);
}
function fileCopyCompleteHandler(event:Event):void {
trace(event.target); // [object File]
var flv:FLVPlayback = new FLVPlayback;
addChild(flv)
flv.source = "media/test.flv";
trace("source = " + flv.source);
}
Any help would be appreciated.
Best,
C.S.