views:

50

answers:

1

Hi,

The following code is used in a component I name FileUpload.mxml which is used in two three different sections of the flex application.

private var uploadURL:URLRequest = new URLRequest;
private var file:FileReference = new FileReference;
private var media:MediaFacade;

public function browse():void
{
        var uUrl:String=""; // force
        uploadURL=new URLRequest();

        file=new FileReference();
        configureListeners();

        file.browse(getTypes());
}

private function configureListeners():void
{
    file.addEventListener(Event.CANCEL, cancelHandler);
            ...
    if (!Application.application.hasEventListener("uploadFileEvent")) {
        Application.application.addEventListener("uploadFileEvent", uploadFile);
    }
}

When it is used in the first instanced, it works fine, but when it is used in different sections it gets the following error from the code below:

Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

    private function doUploadFile():void
    {
        try
        {
            file.upload(uploadURL);
        }
        catch (e:Error) {
            trace(e.message);
        }
    }

It follows the same sequence every time, i.e., file=new FileReference; configureFileListeners(file); file.browse(); file.upload(uploadURL) but only works on the first instance of the component being created.

Any ideas would be appreciated.

Thanks in advance.

Angus.

A: 

browse method only can be call directly from "User-Interaction" event such as CLICK event. If you wrap it in a function or class than that error will occur.

ktutnik
It is being as far as I can tell: <mx:Button click="browse()" label="Browse" id="browse_button" toolTip="Browse for a file to upload" />
Angus