将 flashvars 样式参数传递给加载的 SWF
我有一个 Flex 3 应用程序(播放器 v9),它加载 Flash SWF(AS3,也是播放器 v9),并且需要动态地向其传递运行时已知的参数集合。 这些参数通常通过 HTML 页面中的 flashvars
元素传递。 嵌入的影片通过 loaderInfo.parameters 对象访问这些参数。
我尝试使用 SWFLoader
和 Loader
类,但参数传递没有成功。
相关细节:
- 它是本地程序,不能依赖查询字符串参数。
- 我已经在嵌入代码中设置了 loaderInfo.parameters["foo"] = "123" ,但该参数似乎永远不会出现在嵌入的电影中。
- 我无法在嵌入式电影中放置额外的参数传递机制,因为它们是由第三方创建的。
I have a Flex 3 app (player v9) which loads a Flash SWF (AS3, also player v9) and needs to dynamically pass it a collection of parameters which are known at run-time. These are parameters that are normally passed via the flashvars
element in an HTML page. The embedded movie accesses these parameters via the loaderInfo.parameters
object.
I've tried using SWFLoader
and Loader
classes with no success in param-passing.
Relevant details:
- It's a local program, and cannot rely on query string parameters.
- I've mucked with setting
loaderInfo.parameters["foo"] = "123"
from the embedding code, but the parameter never seems to wind up in the embedded movie. - I cannot place extra parameter-passing machinery in the embedded movie(s), as they are created by third parties.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 URL 中传递此参数没有帮助,因为它们是在 html 包装器中使用 javascript 代码获取的。
“flashVars”参数是使用 Application.application.parameters 获取的,因此,您必须根据您的情况手动设置这些参数。
如果您使用 SWFLoader 加载另一个应用程序,则应该创建该对象,该对象将代表加载的应用程序并应用您需要的所有内容:
Passing this params in URL won't help, because they're taken using javascript code in the html-wrapper.
The 'flashVars' params are taken using the Application.application.parameters, so, you have to set these params manually in your case.
If you are using SWFLoader to load another app, you should create the object, that will represent the application loaded and apply all you need:
原因很简单。
我今天发现了这一点。
在通过
SWFloader
加载的组件中,将parentApplication
或Aplication.application
设置为顶级应用程序(此女巫通过 SWFLoader 加载组件)。加载的组件可以看到
flashvars
设置为顶级应用程序。这可能是在
SWFLoader
中设置参数没有任何影响的原因。我已经在我的顶级应用程序上设置了正确的 flashvars,并且它们也可以在加载的应用程序中看到:-)。
The reason is simple.
I've discovered this today.
In the component loaded via
SWFloader
hasparentApplication
orAplication.application
set to the top level application (this witch loads component via SWFLoader).And the loaded component can see
flashvars
set to the top level application.This is probably the cause that setting parameters in
SWFLoader
does not have any impact.I've set proper flashvars on my toplevel application and they are also seen in the loaded one :-).
在网页上嵌入 SWF 时,您可以将 flashvars 作为 URL 上的参数传递给 SWF,也许同样的方法也适用于您的情况? 如果 SWF 位于
file:///some/path/to/a.swf
,请尝试使用file:///some/path/to/a.swf?hello=world& ;foo=bar
。 它可能会起作用。When embedding a SWF on a web page you can pass flashvars as parameters on the URL to the SWF, perhaps the same could work in your case? If the SWF is located at
file:///some/path/to/a.swf
try usingfile:///some/path/to/a.swf?hello=world&foo=bar
. It might work.如果我首先找到这个答案,今天会节省我很多时间: AS3 Pass FlashVars加载 swf。
本质上:从 Flash Player 10.2 开始,可以通过将 flashvar 设置为 LoaderContext 上的参数来传递它们。
Would have saved myself a lot of time today if I had found this answer first: AS3 Pass FlashVars to loaded swf.
Essentially: since Flash Player 10.2 it has been possible to pass flashvars along by setting them as parameters on the LoaderContext.