I used to upload a single image and want to upload multiple images at a time ~~
Document files.:
Package {<br/> Import flash. display. sprite; <br/> Import flash. events. event; <br/> Import flash. events. mouseevent; <br/> Import flash.net. filefilter; <br/> public class files extends sprite {// File class <br/> private var container: SPRITE = new sprite (); // The container stores the uploadfile <br/> private var filenums: Int = 0; // The number of existing files <br/> private const Filey: Int = 50; // y coordinate of the uploadfile file <br/> private const fileygap: Int = 50; // uploadfil Y coordinate spacing of E files <br/> private var fileuploadsuccess: Int = 0; // number of successfully uploaded files <br/> private var fileuploadfail: Int = 0; // number of files that failed to be uploaded <br/> private var URL: String = "http: // localhost: 8080/upload2/index. JSP "; // target address <br/> private var myfilefilter: filefilter = new filefilter (" Images (*. JPG ;*. GIF ;*. PNG )","*. JPG ;*. GIF ;*. PNG "); // file filtering <br/> Public Function files () {<br/> Init (); // initialization <br/> adduploadfile (); // Add an uploadfile <br />}< Br/> private function Init (): void {<br/> addchild (container); // Add a container <br/> upload_btn.addeventlistener (mouseevent. click, onupload); // upload button to add events <br/> alldelete_btn.addeventlistener (mouseevent. click, onalldelete); // delete all button add event <br/> This. addeventlistener (uploadfile. file_ready, onready); // listens for file preparation events <br/> This. addeventlistener (uploadfile. file_delete, ondelete); // listens for file deletion events <br/>}< br/> private function on Upload (Event: mouseevent): void {// upload <br/> If (container. numchildren = 1) // if there is only one uploadfile, that is, no file has been selected <br/>{< br/> message. TEXT = "You have not selected any files"; <br/> return; <br/>}< br/> for (var I: Int = 0; I <container. numchildren; I ++) <br/>{< br/> (container. getchildat (I) As uploadfile ). uploadmyfile (); // upload one by one <br/>}< br/> This. addeventlistener (uploadfile. file_upload_success, onfileuploadsuccess); // listens for successful events <br/> This. ad Deventlistener (uploadfile. file_upload_fail, onfileuploadfail); // listens for failed events </P> <p >}< br/> private function onfileuploadsuccess (Event: Event ): void {// process uploaded events <br/> fileuploadsuccess ++; // number of successful events + <br/> message. TEXT = "successfully uploaded" + fileuploadsuccess + "files! "+" Upload Failed "+ fileuploadfail +" files! "; // Update information bar <br/> If (fileuploadsuccess + fileuploadfail = filenums) // if the number of successes + the number of failures is the number of files, the call is successful. <br/>{< br/> fileuploadsuccess = 0; <br/> fileuploadfail = 0; <br/> deleteallfiles (); // delete all objects <br/>}< br/> private function onfileuploadfail (Event: Event ): void {// handle upload failure events <br/> fileuploadfail ++; // number of failed events + <br/> message. TEXT = "successfully uploaded" + fileuploadsuccess + "files! "+" Upload Failed "+ fileuploadfail +" files! "; // Update information bar <br/> If (fileuploadsuccess + fileuploadfail = filenums) // if the number of successes + the number of failures is the number of files, the call is successful. <br/>{< br/> fileuploadsuccess = 0; <br/> fileuploadfail = 0; <br/> deleteallfiles (); // delete all objects <br/>}< br/> private function onalldelete (Event: mouseevent ): void {// delete all objects <br/> If (container. numchildren = 1) // if there is only one uploadfile, that is, no file has been selected <br/>{< br/> message. TEXT = "You have not selected any files"; <br/> return; <br/>} else <br />{< Br/> message. Text = "all files are successfully deleted"; <br/>}< br/> for (var I: Int = 0; container. numchildren! = 1;) <br/>{< br/> container. removechildat (I); // remove all except the last uploadfile <br/>}< br/> arrangefiles (); // rearrange the container <br/> filenums = 0; // The number of files is 0 <br/>}< br/> private function deleteallfiles (): void {<br/> for (var I: Int = 0; container. numchildren! = 1;) <br/>{< br/> container. removechildat (I); // remove all except the last uploadfile <br/>}< br/> arrangefiles (); // rearrange the container <br/> filenums = 0; // The number of files is 0 <br/>}< br/> private function onready (Event: Event): void {// process file preparation events <br/> filenums ++; // number of files + + <br/> adduploadfile (); // Add an uploadfile <br/>}< br/> private function ondelete (Event: Event ): void {<br/> filenums --; // number of files -- <br/> container. removechild (event.tar get as sprite); // Delete the uploadfile that triggered the event <br/> arrangefiles (); // rearrange the container <br/>}< br/> private function arrangefiles (): void {// sort the container <br/> for (var I: Int = 0; I <container. numchildren; I ++) <br/>{< br/> (container. getchildat (I) As sprite ). y = Filey + I * fileygap; // sort <br/>}< br/> private function adduploadfile (): void {// Add an uploadfile <br/> var tempfile: uploadfile = new uploadfile (URL, myfilefilter); // set the target address and file filtering <br/> container. addchild (tempfile); // Add the tempiner <br/> tempfile. y = Filey + filenums * fileygap; <br/>}< br/>}
Uploadfile.:
Package {<br/> Import flash. display. sprite; <br/> Import flash.net. filereference; <br/> Import flash.net. filefilter; <br/> Import flash.net. URLRequest; <br/> Import flash. events. event; <br/> Import flash. events. mouseevent; <br/> Import flash. events. ioerrorevent; <br/> public class uploadfile extends sprite {// single file upload class <br/> private var myfile: filereference; // file acquisition <br/> private var fileisready: boolean = false; // File ready <br/> private var URL: string; // upload destination address <br/> private var myfilefilter: filefilter; // filtered file <br/> private var URLRequest: URLRequest; // target request <br/> Public Static Var file_ready: String = "file_ready "; // prepare the event <br/> Public Static Var file_delete: String = "file_delete"; // Delete the event <br/> Public Static Var file_upload_success: String = "file_upload_success "; // upload success event <br/> Public Static Var file_upload_fail: String = "File_upload_fail"; // upload failure event <br/> Public Function uploadfile (URL: String, myfilefilter: filefilter) {// constructor <br/> This. url = URL; // save address <br/> This. URLRequest = new URLRequest (URL); // Save the request <br/> This. myfilefilter = myfilefilter; // sets the filter file <br/> Init (); // initialization <br/>}< br/> private function Init (): void {<br/> myfile = new filereference (); <br/> delete_btn.visible = false; // The delete button is invisible. <br/> browse_btn.addeventlisten Er (mouseevent. click, onbrowse); // click the Browse button to add events <br/>}< br/> private function onbrowse (Event: mouseevent): void {<br/> myfile. browse ([myfilefilter]); // browse <br/> myfile. addeventlistener (event. select, onselect); // when a file is selected <br/>}< br/> private function onselect (Event: Event ): void {<br/> filename_txt.text = event.tar get. name; // update text content <br/> delete_btn.visible = true; // delete button visible <br/> If (fileisready = false) // if not ready To dispatch the prepared event <br/> {<br/> This. dispatchevent (new event (file_ready, true); <br/>}< br/> fileisready = true; // prepare <br/> delete_btn.addeventlistener (mouseevent. click, ondelete); // delete button to add events <br/>}< br/> private function ondelete (Event: mouseevent): void {<br/> delete_btn.removeeventlistener (mouseevent. click, ondelete); <br/> This. dispatchevent (new event (file_delete, true); // dispatch the deleted event <br/> delete_btn.visible = False; // The delete button is invisible. <br/> fileisready = false; // set the file to unprepared. <br/> filename_txt.text = ""; // update the text content <br/> myfile. cancel (); // cancel the file <br/>}< br/> Public Function uploadmyfile (): void {// upload interface <br/> If (fileisready) // if you have prepared <br/>{< br/> myfile. upload (URLRequest, myfile. name); // upload <br/> myfile. addeventlistener (event. complete, oncomplete); // Add completion event <br/> myfile. addeventlistener (ioerrorevent. io_error, onerror); // Add a failure event <br />}< Br/> Public Function deletemyfile (): void {// Delete interface <br/> delete_btn.removeeventlistener (mouseevent. click, ondelete); <br/> This. dispatchevent (new event (file_delete, true); <br/> delete_btn.visible = false; // The delete button is invisible. <br/> fileisready = false; // set the file to not prepared <br/> filename_txt.text = ""; // update the text content <br/> myfile. cancel (); // file cancellation <br/>}< br/> private function oncomplete (Event: Event): void {// uploaded <br/> Del Ete_btn.visible = false; // The delete button is invisible. <br/> fileisready = false; // The file is set to unprepared. <br/> myfile. cancel (); // file canceled <br/> filename_txt.text = "uploaded successfully! "; // Update text content <br/> This. dispatchevent (new event (file_upload_success, true); // dispatch an upload success event <br/>}< br/> private function onerror (Event: ioerrorevent ): void {// Upload Failed <br/> delete_btn.visible = false; // The delete button is invisible <br/> fileisready = false; // set the file to not prepared <br/> myfile. cancel (); // file cancellation <br/> filename_txt.text = "Upload Failed! "; // Update text content <br/> This. dispatchevent (new event (file_upload_fail, true); // dispatch an upload failure event <br/>}< br/>}
The upload_btn, alldelete_btn, and message of the document class are components in Main. Fla.
: Http://www.fileupyours.com/files/262979/upload.rar
Here is the client code
For other JSP and JavaBean components, refer:
Http://hi.baidu.com/%D3%EA%BA%F3%B5%C4%B5%AD%C0%B6%C7%E7%BF%D5/blog/item/f888b9839255f4a90df4d2cf.html
Http://hi.baidu.com/%D3%EA%BA%F3%B5%C4%B5%AD%C0%B6%C7%E7%BF%D5/blog/item/604606ccee6dba5a0eb345c9.html
This guy is amazing ~~ Haha ~ Younger brother's food ~~