Progress bar with file reference
by Kevin Petty
on
Jul 28, 2008 at 12:01:37 am
Hello all,
Thanks to some help by a few really generous members on here I have managed to get file.reference working to allow users two seperate download options in an interface I have created.
The only problem I have now is that when the user starts a download, there is no progress bar. I was hoping to get some help on this.
Here is the .AS page im using for my download page.
public class Player extends MovieClip {
var downloadURL:URLRequest;
var downloadURL2:URLRequest;
var file:FileReference;
public var thisName:TextField = new TextField();
public var thisTitle:TextField = new TextField();
public var thisCompany:TextField = new TextField();
public var loadWMV:Button = new Button();
public var loadMOV:Button = new Button();
public var loadTRANS:Button = new Button();
public var thisMovie:Video = new Video();
public var NS:NetStream;
public var NC:NetConnection = new NetConnection();
public var VID:Video = new Video();
public var customClient:Object = new Object();
public var pauseVid:PauseButton = new PauseButton();
public var playVid:PlayButton = new PlayButton();
public var myID:int;
public function Player(person:Object):void {
NC.connect(null);
NS = new NetStream(NC);
NS.client = customClient;
VID.attachNetStream(NS);
addChild(VID);
VID.x=80;
VID.y=20;
VID.width=293;
VID.height=216;
//Windows Media Download----
loadWMV.label="Download Windows Media";
/*loadWMV.addEventListener(MouseEvent.CLICK,getWMV);*/
loadWMV.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent) {
download(person.FI+".wmv");
}
function download(fileName:String) {
downloadURL = new URLRequest();
downloadURL.url = "http://www.omninewmedia.com/test/wmv/" + fileName;
file = new FileReference();
file.download(downloadURL, fileName);
}
Re: Progress bar with file reference by Pieter Helsen on Jul 28, 2008 at 12:24:34 am
Basically you create a loader_mc that you control via a progressEvent.
import flash.events.*;
public function progressHandler(evt:ProgressEvent):void {
addChild(loader_mc);
var percentage:Number = evt.bytesLoaded/evt.bytesTotal;
loader_mc.scaleY = percentage;
}
public function completeHandler(evt:Event):void {
removeChild(loader_mc);
}
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
Re: Progress bar with file reference by Kevin Petty on Aug 1, 2008 at 4:23:43 pm
Hi Pieter
As always, thanks so much for getting back to me.
I used the code you provided (at least I think I used it correctly) after creating a MC called loader_mc in the library of my main movie. However, Im getting the following errors:
Error 1120 Access of undefined property loader_mc
Error 1172 Definition loader_mc could not be found
public class Player extends MovieClip
{
var downloadURL:URLRequest;
var downloadURL2:URLRequest;
var file:FileReference;
public var thisName:TextField = new TextField();
public var thisTitle:TextField = new TextField();
public var thisCompany:TextField = new TextField();
public var loadWMV:Button = new Button();
public var loadMOV:Button = new Button();
public var loadTRANS:Button = new Button();
public var thisMovie:Video = new Video();
public var NS:NetStream;
public var NC:NetConnection = new NetConnection();
public var VID:Video = new Video();
public var customClient:Object = new Object();
public var pauseVid:PauseButton = new PauseButton();
public var playVid:PlayButton = new PlayButton();
public var myID:int;
public function Player(person:Object):void
{
NC.connect(null);
NS = new NetStream(NC);
NS.client = customClient;
VID.attachNetStream(NS);
addChild(VID);
VID.x=80; VID.y=20; VID.width=293; VID.height=216;
//Windows Media Download----
function progressHandler(evt:ProgressEvent):void {
addChild(loader_mc);
var percentage:Number = evt.bytesLoaded/evt.bytesTotal;
loader_mc.scaleY = percentage;
}
function completeHandler(evt:Event):void {
removeChild(loader_mc);
}
loadWMV.label="Download Windows Media";
loadWMV.addEventListener(MouseEvent.CLICK,getWMV);
loadWMV.addEventListener(MouseEvent.CLICK, clickHandler);
loadWMV.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loadWMV.addEventListener(Event.COMPLETE, completeHandler);
function clickHandler(event:MouseEvent){
download(person.FI+".wmv");
}
function download(fileName:String) {
downloadURL = new URLRequest();
downloadURL.url = "http://www.omninewmedia.com/test/wmv/" + fileName;
file = new FileReference();
file.download(downloadURL, fileName);
}
Re: Progress bar with file reference by Pieter Helsen on Aug 1, 2008 at 4:31:39 pm
Right-click the loader_mc in the library, go to Properties and check Export for Actionscript.
Also, The addChild statement should probably go in a startHandler
// Not sure if this is the one, I don't have flash installed on this laptop.
loadWMV.addEventListener(Event.START, startHandler);
function startHandler(){
addChild(loader_mc);
}
Kind regards,
Pieter
General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.
Re: Progress bar with file reference by Kevin Petty on Aug 1, 2008 at 4:55:11 pm
Pieter
Thanks for the really quick response.
I looked at the loader_mc in the library and it was indeed checked for export to actionscript. Any other suggestions of how I may get rid of the Undefined Property error?