# Using the FileReference class to recconnect?

**URL:** <https://forum.kirupa.com/t/using-the-filereference-class-to-recconnect/233910>\
**Category:** flash\
**Created:** [July 27, 2007, 10:34pm UTC](https://forum.kirupa.com/t/using-the-filereference-class-to-recconnect/233910 "2007-07-27T22:34:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![schemagroup](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@schemagroup](https://forum.kirupa.com/u/schemagroup)\
**Post date:** [July 27, 2007, 10:34pm UTC](https://forum.kirupa.com/t/using-the-filereference-class-to-recconnect/233910/1 "2007-07-27T22:34:25Z")

</div>

Hello,

I would like to know if there is a way to recconnect my connection useing the file reference class. For instance when the user uploads the file to the remote server, and loses there connection. Is there a way in the class that I can recconnect useing the file reference class. Any suggestions would be helpful, although I’m considering of adding a function where it would reconnect in the file reference class. I have attached the fla and also paste the source.

Thank you!

Abe

Heres the source code:

import flash.net.FileReference;  
var progressBar:MovieClip;  
var reference:FileReference = new FileReference();  
var referenceListener:Object = {};

var scriptLocation:String = ‘uploader.php’;  
var progressBarHeight:Number = 10;  
var progressBarY:Number = 50;  
var progressBarColor:Number = 0x66ccff;

uploadButton\_mc.\_visible = false;

reference.addListener(referenceListener);

referenceListener.onSelect = activateUploadButton;  
referenceListener.onProgress = updateProgress;  
referenceListener.onComplete = restart;

referenceListener.onHTTPError = handleError;  
referenceListener.onIOError = handleError;  
referenceListener.onSecurityError = handleError;  
chooseButton\_mc.onRelease = choose;  
uploadButton\_mc.onRelease = uploadCurrent;

function activateUploadButton():Void  
{  
display\_txt.text = reference.name;  
uploadButton\_mc.\_visible = true;  
}  
function choose():Void  
{  
reference.browse([{description:‘All Files (_._)’, extension:’_.mov;_.wmv’}]);  
}  
function handleError(errorName:String, detail:Object):Void  
{  
restart();  
if (arguments.length === 2)  
{  
if (typeof detail === ‘number’)  
{  
display\_txt.text = ‘HTTP Error #’+detail;  
}  
else  
{  
display\_txt.text = 'Security Error: ‘+detail;  
}  
}  
else  
{  
display\_txt.text = ‘IO Error’;  
}  
}  
function makeProgressBar(x:Number, y:Number):MovieClip  
{  
var bar:MovieClip = createEmptyMovieClip(‘progressBar\_mc’, 0);  
bar.\_visible = false;  
bar.beginFill(progressBarColor);  
bar.lineTo(Stage.width, 0);  
bar.lineTo(Stage.width, progressBarHeight);  
bar.lineTo(0, progressBarHeight);  
bar.lineTo(0, 0);  
bar.endFill();  
bar.\_width = 0;  
bar.\_visible = true;  
bar.\_x = x;  
bar.\_y = y;  
return bar;  
}  
function restart():Void  
{  
removeMovieClip(progressBar);  
display\_txt.text = ‘’;  
uploadButton\_mc.\_visible = false;  
chooseButton\_mc.\_visible = true;  
}  
function updateProgress(fileReference:FileReference, bytesLoaded:Number, bytesTotal:Number):Void  
{  
display\_txt.text = fileReference.name+’ - '+Math.ceil((bytesLoaded/bytesTotal)_100)+’%’;  
progressBar.\_width = Math.ceil(Stage.width_(bytesLoaded/bytesTotal));  
}  
function uploadCurrent():Void  
{  
chooseButton\_mc.\_visible = false;  
progressBar = makeProgressBar(0, progressBarY);  
reference.upload(scriptLocation);  
}

Abel Gudino
