Flash AS3 Implementation Picture upload

Source: Internet
Author: User

This is a simple image upload program, you can upload the local image online, and then write a load to show the uploaded image function

Note:

Up_name: A dynamic text box that displays the file name of a selected picture

Liulan: For the "Browse" button, click on it will pop-up browse box, select the picture to upload

Shangchuan: For the "Upload" button, click on it will upload the selected pictures

Loading: For dynamic text boxes, to display upload progress percentages and upload success information, etc.

Put these components all in one MC and bind the following class to this MC

The code is as follows Copy Code

Package {
Import flash.display.*;
Import Flash.text.TextField;
Import flash.events.*;
Import flash.system.*;
Import Flash.net.URLRequest;

Upload class
Import flash.net.FileReference;
File Type Filter class
Import Flash.net.FileFilter;
public class Shangchuanlan extends Sprite {
Create an Upload class
public var fileref:filereference=new filereference ();
Public Function Shangchuanlan () {
Liulan.buttonmode=true;
Shangchuan.buttonmode=true;
Events when clicking the browse button
Liulan.addeventlistener (Mouseevent.click,click_liulan);
Click the Upload button when the event
Shangchuan.addeventlistener (Mouseevent.click,up_load);
}
============================================= a gorgeous split line ======================================================== ======//
Private Function Click_liulan (e:mouseevent): void {
Set File type
var imagetypes:filefilter=new filefilter ("Images (*.jpg, *.jpeg, *.gif)", "*.jpg;, *.jpeg;, *.gif;");
Put the desired file type into an array because the arguments in the following browse are arrays
var alltypes:array=new Array (imagetypes);
Pop-up box, the file type is in the Alltypes array.
Fileref.browse (alltypes);
When you click Open in the pop-up box, perform the Up_select function
Fileref.addeventlistener (Event.select,up_select);
Upload or download after completion of event, execute Up_complete
Fileref.addeventlistener (Event.complete,up_complete);
After successfully uploading and receiving data from the server
Fileref.addeventlistener (Dataevent.upload_complete_data,up_complete_data);
Execute at start of upload or download
Fileref.addeventlistener (Event.open,up_open);
Execute during upload or download
Fileref.addeventlistener (progressevent.progress,up_progress);
}
============================================= a gorgeous split line ======================================================== ======//
The following are the functions that are executed when each event
Private Function Up_select (e:event): void {
Displays the file name of the selected file (the FileRef Name property) in the text box
Up_name.text=fileref.name;
}
Private Function Up_load (e:mouseevent): void {
Get the type of file
var Filetype:string=fileref.type;
Get the size of a file
var filesize:number=fileref.size;
Trace ("Type:" +filetype, "Size:" +filesize);
Connect Interface Web page
var loadurl:string= "http://www.xxx.com/xxx.asp";
var uploadurl:urlrequest = new URLRequest (Loadurl);
Send a file to a Web page with the upload event, syntax upload (URL, filename)
Fileref.upload (Uploadurl,fileref.name);
Trace (Uploadurl.url);
}
Private Function Up_complete (e:event): void {
Display information for the sender of the directive
Trace ("Completehandler:" + e);
loading.text= "Upload success!"
}
Private Function Up_complete_data (e:event): void {
Displays the message of the sender of the instruction, that is, the return information of the received page, which has the path of the file after the upload
Trace ("Uploadcompletedatahandler:" +e);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.