English 中文(简体)
AS3 - Cancel PHP
原标题:AS3 - Cancel PHP request

That script below is for uploading an image via PHP. Now I ld like to give the user the option to cancel the upload. How to cancel the PHP request once it got send?

    package
{
    import com.adobe.images.PNGEncoder;
    import flash.display.BitmapData;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.SecurityErrorEvent;
    import flash.events.IOErrorEvent
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.utils.ByteArray;

    public class ServeruploadExample
    {
        private var loader:URLLoader;

        private const API_KEY:String = "<api key>";
        private const UPLOAD_URL:String = "http://example.com/upload-image.php";

        public function ImgurExample() {

            loader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.VARIABLES;
            loader.addEventListener(Event.COMPLETE, onCookieSent);
            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
            loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

            // Create a bitmapdata instance of a movieclip on the stage.
            var mc:MovieClip;
            var b:BitmapData = new BitmapData(mc.width, mc.height, true);
            b.draw(mc);
            var png:ByteArray = PNGEncoder.encode(b);

            var vars:String = "?key=" + API_KEY + "&name=name&title=title";
            var request:URLRequest = new URLRequest(UPLOAD_URL + vars);
            request.contentType = "application/octet-stream";
            request.method = URLRequestMethod.POST;
            request.data = png;

            loader.load(request);
        }
        // privates


    }
}
最佳回答

Just calls the .close()meth of the URLloader, which will end theload operation.

以你为例,建立了一个取消纽芬兰语和:

public function cancel_upload_click_handler(e:MouseEvent):void
{
   loader.close();
}
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签