FORUMS: list search recent posts

Progress bar with file reference

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kevin Petty
Progress bar with file reference
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.

Thanks in advance for any help.

package {

import flash.display.MovieClip;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.URLRequest;
import PauseButton;
import PlayButton;


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);
}



loadMOV.label="Send Link";
/* loadMOV.addEventListener(MouseEvent.CLICK,getMOV);*/

//Transcript Download----

loadTRANS.label="Download Transcript";
/*loadTRANS.addEventListener(MouseEvent.CLICK,getTrans);*/
loadTRANS.addEventListener(MouseEvent.CLICK, clickHandler2);

function clickHandler2(event:MouseEvent) {
download2(person.FI+".txt");
}
function download2(fileName:String) {
downloadURL2 = new URLRequest();
downloadURL2.url = "http://www.omninewmedia.com/test/transcripts/" + fileName;
file = new FileReference();
file.download(downloadURL2, fileName);
}
pauseVid.addEventListener(MouseEvent.CLICK,pauseMe);
playVid.addEventListener(MouseEvent.CLICK,playMe);

with (pauseVid) {
x=80;
y=240;
buttonMode=true;
useHandCursor=true;
}
addChild(pauseVid);

with (playVid) {
x=105;
y=240;
buttonMode=true;
useHandCursor=true;
}
addChild(playVid);

with (loadWMV) {
x=220;
y=275;
width=200;
buttonMode=true;
useHandCursor=true;
}
addChild(loadWMV);

with (loadMOV) {
x=220;
y=300;
width=200;
buttonMode=true;
useHandCursor=true;
}
addChild(loadMOV);

with (loadTRANS) {
x=220;
y=325;
width=200;
buttonMode=true;
useHandCursor=true;
}
addChild(loadTRANS);

with (thisName) {
text = person.NM;
x=30;
y=290;
width = 125;
height=20;
selectable=false;
//embedFonts=true;
}
addChild(thisName);

with (thisTitle) {
text = person.TT;
x=30;
y=310;
width = 125;
height=20;
selectable=false;
///embedFonts=true;
}
addChild(thisTitle);

with (thisCompany) {
text = person.CP;
x=30;
y=330;
width = 140;
height=20;
selectable=false;
//embedFonts=true;
}
addChild(thisCompany);


NS.play("videos/"+person.FI+".flv");

}
/*public function getWMV(e:MouseEvent){
trace("WMV");
}

public function getMOV(e:MouseEvent){
trace("MOV");
}

public function getTrans(e:MouseEvent){
trace("Transcript");
}*/

public function pauseMe(e:MouseEvent) {
NS.pause();
}
public function playMe(e:MouseEvent) {
NS.resume();
}
public function stopMov() {
NS.close();
}

}
}


Return to posts index

Pieter Helsen
Re: Progress bar with file reference
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);
}

loadWMV.addEventListener(ProgressEvent.PROGRESS, progressHandler);
loadWMV.addEventListener(Event.COMPLETE, completeHandler);
transWMV.addEventListener(ProgressEvent.PROGRESS, progressHandler);
transWMV.addEventListener(Event.COMPLETE, completeHandler);

Well... Something like that. :)

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.


Return to posts index

Kevin Petty
Re: Progress bar with file reference
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

Here is my current code:

package{

import flash.display.MovieClip;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.text.TextField;
import flash.text.TextFormat;
import fl.controls.Button;
import flash.events.MouseEvent;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.events.*;
import PauseButton;
import PlayButton;
import loader_mc;
import barMC;



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);
}




/* loadMOV.label="Send Link";
loadMOV.addEventListener(MouseEvent.CLICK,getMOV);*/

//Transcript Download----

loadTRANS.label="Download Transcript";
loadTRANS.addEventListener(MouseEvent.CLICK,getTrans);
loadTRANS.addEventListener(MouseEvent.CLICK, clickHandler2);

function clickHandler2(event:MouseEvent){
download2(person.FI+".txt");
}
function download2(fileName:String) {
downloadURL2 = new URLRequest();
downloadURL2.url = "http://www.omninewmedia.com/test/transcripts/" + fileName;
file = new FileReference();
file.download(downloadURL2, fileName);
}

pauseVid.addEventListener(MouseEvent.CLICK,pauseMe);
playVid.addEventListener(MouseEvent.CLICK,playMe);

with(pauseVid){
x=80; y=240; buttonMode=true; useHandCursor=true;
} addChild(pauseVid);

with(playVid){
x=105; y=240; buttonMode=true; useHandCursor=true;
} addChild(playVid);

with(loadWMV){
x=220; y=275; width=200; buttonMode=true; useHandCursor=true;
} addChild(loadWMV);
/*
with(loadMOV){
x=220; y=300; width=200; buttonMode=true; useHandCursor=true;
} addChild(loadMOV);*/

with(loadTRANS){
x=220; y=325; width=200; buttonMode=true; useHandCursor=true;
} addChild(loadTRANS);

with(thisName){
text = person.NM; x=30; y=290; width = 125; height=20; selectable=false;
//embedFonts=true;
} addChild(thisName);

with(thisTitle){
text = person.TT; x=30; y=310; width = 125; height=20;selectable=false;
///embedFonts=true;
} addChild(thisTitle);

with(thisCompany){
text = person.CP; x=30; y=330; width = 140; height=20; selectable=false;
//embedFonts=true;
} addChild(thisCompany);


NS.play("videos/"+person.FI+".flv");

}

public function getWMV(e:MouseEvent){
trace("WMV");
}

/* public function getMOV(e:MouseEvent){
trace("MOV");
}*/

public function getTrans(e:MouseEvent){
trace("Transcript");
}

public function pauseMe(e:MouseEvent){
NS.pause();
}

public function playMe(e:MouseEvent){
NS.resume();
}

public function stopMov(){
NS.close();
}

}
}



Return to posts index


Pieter Helsen
Re: Progress bar with file reference
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.


Return to posts index

Kevin Petty
Re: Progress bar with file reference
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?

Thanks again
Kevin



Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]