本文介绍了Flex的FileReference.save()只能被称为用户事件处理程序 - 我怎样才能解决这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Web服务调用之后调用FileReference.save()已完成,但这种方法有一个限制:在Flash Player中,你只能成功调用此方法在响应用户事件(例如,事件处理程序点击鼠标或按键preSS事件)。否则,调用此方法将导致Flash Player引发Error异常。 (从文档<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html?allClasses=1#save%28%29"相对=nofollow>这里)

I need to call FileReference.save() after a web service call has completed, but this method has a restriction: "In Flash Player, you can only call this method successfully in response to a user event (for example, in an event handler for a mouse click or keypress event). Otherwise, calling this method results in Flash Player throwing an Error exception." (from the documentation here)

这限制是有点模糊。这是否意味着我只能从注册为一个侦听特定类型的用户事件的事件处理函数中调用FileReference.save()方法?如果是的话,到底哪些用户事件是有效的? (或许有,将永远不会被用户交互我的应用程序分派的事件,我可以注册一个事件处理函数,该函数的事件类型,并从该函数中进行保存()调用?)

This restriction is a bit vague. Does it mean that I can only call the FileReference.save() method from within an event handler function that is registered as a listener for certain types of user events? If so then exactly which user events are valid? (Perhaps there's an event that will never be dispatched by user interaction with my application and I could register an event handler function for that event type and make the save() call from within that function?)

我的困难是,我不能安全地调用FileReference.save()方法,直到我的web服务返回将用作FileReference.save()方法调用的参数数据,因此事件触发在FileReference.save()调用实际上是一个的ResultEvent而不是用户的事件,我持怀疑态度,以便调度新的(人造)用户事件的类型,才能够触发FileReference.save()调用,除非它绝对是一个这将永远不会被派往与我的应用程序的实际用户交互的结果用户事件。

My difficulty is that I can't safely call the FileReference.save() method until my web service returns with the data that will be used as the argument of the FileReference.save() method call, so the event that triggers the FileReference.save() call is actually a ResultEvent rather than a user event, and I'm leery of dispatching a new (faux) user event type in order to be able to trigger the FileReference.save() call unless it's definitely a user event that would never be dispatched as a result of actual user interaction with my application.

在简单地说我在做什么,现在是这样的:我有一个注册为处理程序,按一下按钮的功能。在这个功能使我的web服务调用从服务器获取数据。我也有它被调用Web服务调用完成时,结果处理函数,并且它在这里,我想打电话给FileReference.save()方法,因为它在这一点上,我知道数据是随时可以保存到一份文件。但上述限制从这样阻止了我 - 我得到一个错误:

In a nutshell what I'm doing now is this: I have a function that is registered as a handler for a button click. In this function I make my web service call to fetch data from the server. I also have a result handler function which gets invoked when the web service call completes, and it's in here that I want to call the FileReference.save() method since it's at this point that I know that the data is ready to be saved to a file. But the aforementioned restriction is blocking me from doing this -- I get an error:

Error #2176: Certain actions, such as those that display a pop-up window,
may only be invoked upon user interaction, for example by a mouse click
or button press.

我试过很多事情来解决这个问题,如与FileReference.save创建第二个鼠标点击事件处理函数()中调用和超时时间间隔后调用它(为Web服务的时间才能完成),但我一直运行到同样的错误 - 也许这种做法行不通,因为第二个功能是没有注册为事件侦听器作为它的参数事件类型

I've tried many things to get around this such as creating a second mouse click event handler function with the FileReference.save() call within and calling it after a timeout interval (to give the web service time to complete), but I keep running into the same error -- maybe that approach doesn't work since the second function isn't registered as an event listener for the event type used as its argument.

我是新来的Flex开发所以也许我只是没有想到这个以正确的方式。如果任何人都可以提出另一种方式我真的AP preciate它。在此先感谢您的意见或建议。

I'm new to Flex development so perhaps I'm just not thinking about this in the right way. If anyone can suggest another approach I'd really appreciate it. Thanks in advance for your comments or suggestions.

- 詹姆斯

推荐答案

的Adobe确实这是一种安全措施,以确保用户是那些用文件而不是潜在的有害code搞乱。我的理解是,他们执行这一只允许(点击?)事件,从UI组件发起到执行的FileReference方法处理,因此产生自己的事件编程方式将无法正常工作,虽然我没有试过验证这一点。不幸的是,我找到了最好的解决方法是重新工作的用户界面有点符合此约束。在特定的情况下,你可以把这个两个点击的过程的一个按钮,上面写着类似prepare下载,它的网络服务后变为下载文件就完成了。这是不到从用户的角度理想,但我不认为有多少人可以做的,除非你能以某种方式完成您的Web服务调用显示触发FileReference.save()调用按钮之前。

Adobe does this as a sort of security measure to ensure users are the ones messing with files rather than potentially harmful code. My understanding is that they enforce this by only allowing handlers of (click?) events that originate from UI components to execute the FileReference methods, so generating your own events programmatically will not work, although I have not tried to verify this. Unfortunately the best resolution I've found is to re-work the UI a bit to conform to this constraint. In your particular situation, you could make this a two click process with a button that says something like "Prepare Download", which changes to "Download File" after the web service is complete. This is less than ideal from a user perspective, but I don't think there's much else that can be done unless you can somehow complete your web service call prior to displaying the button that triggers the FileReference.save() call.

这篇关于Flex的FileReference.save()只能被称为用户事件处理程序 - 我怎样才能解决这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 22:18