Question

I'm in the process of creating a mindmap flash app which has to save all images that are imported into a single folder, along with an xml for data storage. While my current app works when not embedded in a HTML, it breaks as soon as it is due to security violations.

By clicking a save button, the code loops through the array of images and creates a FileReference for each of them and calls FileReference.save to save the image.

As stated in this documentation, each save needs to by triggered by UI interaction: http://kb2.adobe.com/cps/405/kb405546.html

But it also states a chain of saves can be made by calling them from the same function.

However using my images array loop, only the first image gets saved and no popup is being called for subsequent images. My guess is that only one native popup at a time is allowed, but how would I go about doing this? Has anyone tried chaining filereferences before?

Was it helpful?

Solution

Push the file references into a vector, add the event listener to listen for the Event.COMPLETE callback on each file reference. Then, inside the callback, pop the file reference out of the array and call the next one in cue.

var myFiles:Vector.<FileReference> = new Vector.<FileReference>();

//Populate the vector (this example assumes you can figure this out

//While populating the vector, add the event listener to the file reference for the COMPLETE event.
myRef.addEventListener(Event.COMPLETE, onFileSaved);
myFiles.push(myRef);

private function onFileSaved(e:Event):void
{
    var i:int = 0;
    for(i; i < myFiles.length; ++i){
        if(myFiles[i] == FileReference(e.currentTarget)){
            FileReference(e.currentTarget).removeEventListener(Event.COMPLETE, onFileSaved);
            myFiles.splice(i, 1);
        }
    }

    if(myFiles.length > 0){
        FileReference(myFiles[0]).save();
    }
}

So this code is un-tested and will also have to be adapted to your specific scenario but you get the idea anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top