Skip to main content
Inspiring
Jan 30, 2014 1:41 PM UTC
Question

AIR - File.cancel() - BUG???

I've been trying for the last 3 hours now, but it just does not work. I'm using Flash CS 6, AIR 4.0.0.1390, OS 32-bit XP SP 3.

Scenario:

Using AIR's File, copy a large file to somewhere else "Asynchronously"

Pretty simple!! Here is the BUGGY part: try to show Progress - PROGRESSEVENT DOESN'T WORK. try to listen for canel() method - DOESN'T WORK. here is very simple, straigh-forward code:

import flash.filesystem.File;

import flash.events.Event;

import flash.events.ProgressEvent;

import flash.utils.setTimeout;

var a:File = File.desktopDirectory.resolvePath("file1.abc"); //file size: 300+ MB

var b:File = File.desktopDirectory.resolvePath("file2.abc");

a.addEventListener(Event.CANCEL, cn); //DOES NOT FIRE

a.addEventListener(ProgressEvent.PROGRESS, pr); // DOES NOT FIRE

a.addEventListener(Event.COMPLETE, cl);

a.copyToAsync(b, true);

 

function cn(e:Event):void

{

    trace('operation is cancelled');

}

function cl(e:Event):void

{

    trace('operation completed');

}

function pr(e:ProgressEvent):void

{

    trace(e.bytesLoaded + " " + e.bytesTotal);

}

to make everything pretty simple, I added these two lines:

var c:uint = setTimeout(function ():void {a.cancel(); b.cancel(); trace('cancelled');}, 50); //it traces 'cancelled', I DON'T KNOW wether it really cancels that operation or no

var d:uint = setTimeout(function ():void {b.deleteFile();}, 10000); //even after waiting for 10 seconds, it still shows Error, file is in use...

Here is the Adobe's documentation regarding .cancel() function:

"Cancels any pending asynchronous operation."

Is there any way to STOP/CANCEL current File's operation (such as openAsync, copyToAsync, moveToAsync)???? What if user wants to cancel large file copy??? NO WAY??

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Colin Holgate
Inspiring
Feb 1, 2014 1:24 PM UTC

I don't do file things in AIR, but from what I read it seems that file doesn't get progress events. filestream does. What happens if you use filestream instead of file?

Translate
Inspiring
Feb 2, 2014 5:36 AM UTC

In my same project, I use FileStream class as well and it works perfectly well. But I use it sychronously (because my files are not more than 4 MB). I think I will need to use FileStream class only for this particular issue, although File class could have been short-and-sweet...

As always, thanks Colin for your help...

Translate
Inspiring
Feb 1, 2014 6:35 AM UTC

not even one reply??!! Nobody can help me out?? Anyways, I'll find another way, but can anybody just confirm whether it is a bug or I did not understand correctly???

Translate