Skip navigation
Currently Being Moderated

FileReference.cancel

Aug 19, 2011 9:52 AM

The docs are confusing me a bit.  They say, "Calling this method does not dispatch the cancel event; that event is dispatched only when the user cancels the operation by dismissing the file upload or download dialog box."  Is the cancel event supposed to fire if you call fileref.cancel() after you've called fileref.upload()?  If it isn't, then what's a file upload dialog box?

 
Replies
  • Currently Being Moderated
    Aug 19, 2011 10:06 AM   in reply to Damon Edwards

    The Method, Cancel, is what you use to cancel an upload or download. The Event, Cancel, is what is sent when the user clicks on Cancel in an upload or download dialog.

     

    So, if you are downloading something already, and for some reason you need to cancel the download, you would use the Method. If your user clicks on something to do an upload or download, but then changes their mind, and clicks the Cancel button in the dialog, you can detect that event and maybe present an appropriate message.

     

    This all relates more to desktop browser work, I don't know if you would get involed in this with mobile apps.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 10:24 AM   in reply to Damon Edwards

    Try this script in the timeline of a new FLA:

     

     

    import flash.display.Sprite;

    import flash.events.*;

    import flash.net.FileReference;

    import flash.net.URLRequest;

     

     

    var downloadURL:URLRequest;

    var fileName:String = "SomeFile.pdf";

    var file:FileReference;

     

    FileReference_event_cancel();

     

    function FileReference_event_cancel() {

    downloadURL = new URLRequest();

    downloadURL.url = "http://www.[yourDomain].com/SomeFile.pdf";

    file = new FileReference();

    file.addEventListener(Event.CANCEL, cancelHandler);

    file.download(downloadURL, fileName);

    }

    function cancelHandler(event:Event):void {

    trace("cancelHandler: " + event);

    }

     

    Do a Test Movie. What appears? Does it look something like a dialog box? When you click Cancel, does something trace?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 10:31 AM   in reply to Damon Edwards

    The Event version of Cancel would only happen before the transfer. The Method version of Cancel would only be called after the transfer has started. It does make it slightly confusing when the class has two things called exactly the same thing.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 10:54 AM   in reply to Damon Edwards

    Since cancelling seems to be synchronous, wouldn't this work:

     

    pseudo function

    {

         show "canceling" message

         call cancel()

         remove "canceling" message

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 10:55 AM   in reply to Joe ... Ward

    Yes, what Joe said. The Method Canel isn't an event that has to work its way through the system, to sometime later actually do something. It's immediate.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 11:43 AM   in reply to Damon Edwards

    Here, this helps:

     

    http://xfiles.funnygarbage.com/~colinholgate/video/cancelvid.mov

     

    I think there's something slow about your notify routine. The canceling seems to take place correctly.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 11:44 AM   in reply to Colin Holgate

    By the way, do you get the same results with AIR 2.7 instead of AIR 3?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 19, 2011 12:31 PM   in reply to Damon Edwards

    There are cases wher eFlash can leave junk on the screen. Maybe the upload thing was remvoed, but just has some dirt on the screen. Try putting a message into a visible textfield, so you can see at what moment the removechild happens.

     

    It could be an AIR 3 graphical issue.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points