Flex 上传文件组件 - 文件引用问题
以下代码在我命名为 FileUpload.mxml 的组件中使用,该组件在 Flex 应用程序的两个三个不同部分中使用。
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);
}
}
当它在第一个实例中使用时,它工作正常,但是当它在不同的部分中使用时,它会从下面的代码中得到以下错误:
错误#2037:以错误的顺序调用函数,或者之前的调用不成功。
private function doUploadFile():void
{
try
{
file.upload(uploadURL);
}
catch (e:Error) {
trace(e.message);
}
}
每次都遵循相同的顺序,即 file=new FileReference;配置文件监听器(文件);文件.浏览(); file.upload(uploadURL) 但仅适用于正在创建的组件的第一个实例。
任何想法将不胜感激。
提前致谢。
安格斯。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
browse
方法只能从“用户交互”事件(例如 CLICK 事件)直接调用。如果将其包装在函数或类中,则会发生该错误。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.我是 Flex 的菜鸟,但从我读到的内容来看:
尝试在 .browse() 之前调用 .cancel() 以确保没有事件发生冲突。
I'm a noob at Flex, but from what I've read:
Try calling .cancel() before .browse() to ensure no event is conflicting.