Flash as file upload progress bar

Source: Internet
Author: User
Tags file upload file upload progress bar php file php file upload

Let's take a look at the effect chart first:

Here is the code added to the as IFRAME.

Import flash.net.FileReference;
Import Mx.controls.Alert;

var My_pb:mx.controls.ProgressBar;
var maxSize = 1000*1000*100; File size limit: 100M
Set progress bar mode
My_pb.mode = "Manual";
My_pb.label = "Upload progress:%1%";
My_pb._visible=false
Minimum number before the progress bar is added
My_pb.minimum = 0;
Maximum value before progress bar is stopped
My_pb.maximum = 100;
var increment_num:number = My_pb.minimum;

var alltypes:array = new Array ();
var imagetypes:object = new Object ();
Imagetypes.description = "Images (*.jpg, *.jpeg, *.gif, *.png)";
Imagetypes.extension = "*.jpg; *.jpeg; *.gif; *.png ";
Alltypes.push (imagetypes);

var texttypes:object = new Object ();
Texttypes.description = "Text Files (*.txt, *.rtf)";
Texttypes.extension = "*.txt;*.rtf";
Alltypes.push (texttypes);

var flvtype:object =new Object ();
flvtype.description = "flv Files (*.flv)";
Flvtype.extension = "*.flv";
Alltypes.push (Flvtype);

var rmtype:object =new Object ();
Rmtype.description = "rm Files (*.RM)";
Rmtype.extension = "*.rm";
Alltypes.push (Rmtype);

Defines the action after a warning is confirmed.
var myclickhandler:function = Function (evt_obj:object) {
if (Evt_obj.detail = = Alert.ok) {
Trace ("Start stock app");
}
};

var listener:object = new Object ();

Listener.onselect = function (file:filereference): Void {
Trace ("onselect:" + file.name);
Filesurl.text=file.name;
MSG ("Sorry, the file you selected is too big!") ");
if (!file.upload ("http://localhost/upfiles/hlp.php")) {
Trace ("Upload dialog failed to open.");
//}
if (file.size<=maxsize)
{
Strstate.text = "You selected file:" + file.name + "\ n";
Btnupload.enabled = true;
}else
{
MSG ("Sorry, the file you selected is too big!") ");
btnupload.enabled = false;
}
}

Listener.oncancel = function (file:filereference): Void {
Trace ("OnCancel");
}

Listener.onopen = function (file:filereference): Void {
Trace ("OnOpen:" + file.name);
}

listener.onprogress = function (File:filereference, Bytesloaded:number, Bytestotal:number): Void {
Trace ("OnProgress with bytesloaded:" + bytesloaded + "Bytestotal:" + bytestotal);
My_pb.setprogress ((bytesloaded/bytestotal) *, my_pb.maximum);
}

Listener.oncomplete = function (file:filereference): Void {
Trace ("111111111111onComplete:" + file.name);
MSG ("Upload complete!") ");
GetURL ("Javascript:formsub ()");
}

Listener.onhttperror = function (file:filereference): Void {
Trace ("Onhttperror:" + file.name);
MSG ("Onhttperror:" + file.name);
}

Listener.onioerror = function (file:filereference): Void {
Trace ("Onioerror:" + file.name);
MSG ("Onioerror:" + file.name);
}

Listener.onsecurityerror = function (File:filereference, errorstring:string): Void {
Trace ("Onsecurityerror:" + file.name + "errorstring:" + errorstring);
MSG ("Onsecurityerror:" + file.name + "errorstring:" + errorstring);
}

var fileref:filereference = new Filereference ();
Fileref.addlistener (listener);
This.btnBrowse.onRelease = function () {
Fileref.browse (alltypes);
};
This.btnUpload.onRelease = function () {
if (!fileref.upload ("/upload.php")) {
Trace ("Upload dialog failed to open.");
//}
Displays a warning dialog box.

//}
Fileuploadurl= "/upload.php";
function Scrubba () {
if (Fileuploadurl) {
My_pb._visible=!false;
btnbrowse.enabled = false;
if (!fileref.upload (Fileuploadurl)) {
Trace ("Upload dialog failed to open.");
}
Fileuploadurl= ';
}
}
_root.onenterframe = Scrubba;

function msg (msgtxt:string) {
Alert.show (msgtxt, "message", Alert.ok, this, Myclickhandler, "Stockicon", Alert.ok);
}
Description: hlp.php file is php file upload code, please go to this site to find.

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.