HI Maxim,
Yes you right, By streaming the bytes from url and we need to
write into a file using filestream, Please refer the code below:
-----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">
<mx:Style>
.progressWindow
{
background-color:#FFFFFF;
border-style:solid;
drop-shadow-enabled:true;
corner-radius:5;
}
.progressStyle
{
vertical-center:0;
horizontal-center:0;
}
</mx:Style>
<mx:Script>
<![CDATA[
import flash.filesystem.*;
import com.ProgressWindow;
public var stream:URLStream = new URLStream();
public var file:File = File.documentsDirectory.resolvePath("c:/
jackson.mp4");
public var fileStream:FileStream = new FileStream();
public function init():void
{
stream.addEventListener(ProgressEvent.PROGRESS, progressBar);
stream.addEventListener(Event.COMPLETE, writeComplete);
stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
stream.addEventListener(Event.OPEN, opentHandler);
stream.load(new URLRequest("
http://localhost:8080/concept/
jackson.mp4"));
}
public function writeComplete(evt:Event):void
{
var fileData:ByteArray = new ByteArray();
stream.readBytes(fileData,0,stream.bytesAvailable);
fileStream.openAsync(file, FileMode.UPDATE);
fileStream.writeBytes(fileData,0,fileData.length);
fileStream.close();
stream.removeEventListener(ProgressEvent.PROGRESS, progressBar);
stream.removeEventListener(Event.COMPLETE, writeComplete);
ProgressWindow.getInstance().close();
}
public function progressBar(event:ProgressEvent):void
{
ProgressWindow.getInstance().setProgress
(event.bytesLoaded,event.bytesTotal);
}
private function ioErrorHandler(event:IOErrorEvent):void
{
ProgressWindow.getInstance().close();
}
private function securityErrorHandler
(event:SecurityErrorEvent):void
{
ProgressWindow.getInstance().close();
}
private function opentHandler(event:Event):void
{
ProgressWindow.getInstance().show();
}
]]>
</mx:Script>
</mx:WindowedApplication>
-----------------------------------------
Lokh