php - Multiple File Upload With ProgressBar in Flash Action script with preview of image and individual progress bar for each file -
i trying develop multiple file upload script in flash action script 3.0 on
adobe flash cs3
and here code :-
flash action script :
import flash.net.filereferencelist; import flash.events.event; import flash.net.urlrequest; import flash.net.filereference; var fileref:filereferencelist = new filereferencelist(); var uploadurl:urlrequest = new urlrequest(); var uploadphotoscript:string = "http://localhost/as3/1.php"; uploadurl.url = uploadphotoscript; var totalfiles:int = 0; btn_browse.addeventlistener(mouseevent.click, onuploadclicked); function onuploadclicked(e:mouseevent):void { fileref = new filereferencelist(); fileref.browse(new array( new filefilter( "images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png" ))); fileref.addeventlistener(event.select, fileselecthandler); } function fileselecthandler(event:event):void { each(var filetoupload:filereference in fileref.filelist){ ++totalfiles; uploadsinglefile(filetoupload); } } function uploadsinglefile(file:filereference):void { file.addeventlistener(progressevent.progress, onuploadprogress); file.addeventlistener(event.complete, onfileuploadcomplete); progressbar.width=2; file.upload(uploadurl); file.addeventlistener(event.complete, completehandler); } function onuploadprogress(e:progressevent):void { var f:filereference = e.currenttarget filereference; var filename:string = f.name; var progres:number = (e.bytesloaded / e.bytestotal) * 100; progressbar1.width=3.5*(progres); txt_curr.text=""+filename+""; prog1.text=""+progres+" %" } function completehandler(event:event):void { trace("upload complete"); } function onfileuploadcomplete(e:event):void { --totalfiles; if(totalfiles == 0){ trace("all file uploaded !"); progressbar.width=100*3.5; } }
where btn_browse button added movie , progressbar, progressbar1 symbols used show progress of files , current file being uploaded respectively. , txt_curr textbox shows name of current file being processed.
php:
<?php if(!empty($_files)){ $tmpfile = $_files['filedata']['tmp_name']; $targetfile = "images/" . $_files['filedata']['name']; move_uploaded_file($tmpfile, $targetfile); } ?>
now want is:
can 1 me in this? new flash , trying learn it. in advance.
you have array of filereference
s, , not have array of progress bars. so, answer questions:
to add set of progress bars, declare class (say movieclip base, sprite can do), name myprogressbar
, define visuals etc, define function adjust it, , add instance of set this:
var mybars:vector.<myprogressbar>; function fileselecthandler(event:event):void { (var i:int=0;i<fileref.filelist.length;i++){ ++totalfiles; var mynextbar:myprogressbar=new myprogressbar(); mynextbar.y=i*myprogressbar.theheight; mybarhandler.addchild(mynextbar); mybars.push(mynextbar); uploadsinglefile(fileref.filelist[i]); } }
this way each element in fileref.filelist
corresponding element in mybars
. then, when parse yet progressevent, have index based on e.target
:
function onuploadprogress(e:progressevent):void { var f:filereference = e.currenttarget filereference; var i:int=fileref.filelist.indexof(f); var progressbar:myprogressbar=mybars[i]; var progres:number = (e.bytesloaded / e.bytestotal) * 100; progressbar.adjustprogress(progres); // alter progress bar }
your fourth question answered along first one.
about delete buttons - should clarify want delete , where. previews - can first use filereference.load()
method, load file locally, enabling reach contents, can addchild()
somewhere other file loaded web.
Comments
Post a Comment