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.
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.
I'm a noob at Flex, but from what I've read:
Try calling .cancel() before .browse() to ensure no event is conflicting.
精彩评论