AS3 将 FlashVars 传递给加载的 swf

发布于 2024-08-22 03:14:24 字数 585 浏览 7 评论 0原文

我有一个 A.swf,它将 B.swf 加载到影片剪辑上,并且需要向其传递一些 FlashVars。当用html加载B.swf时,我可以很好地传递FlashVars。从 A.swf 传递时,它会收到

错误 #2044: Unhandled ioError:。 text=错误#2032:流错误。 URL: file:

A.swf 中的代码

var request:URLRequest = new URLRequest ("B.swf");

var variables : URLVariables = new URLVariables();
variables.xml = "test.xml";

// This line causes the error 2044, else B.swf loads fine with FlashVars  
request.data = variables;

loader.load (request); 

在 B.swf 中,它像这样检查 Flashvars。从 html 端看它工作得很好

this.loaderInfo.parameters.xml

I have a A.swf which loads B.swf onto a movieclip and needs to pass it some FlashVars. When loading B.swf with html, I can pass FlashVars fine. When passing from A.swf, it gets a

Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:

The code in A.swf is

var request:URLRequest = new URLRequest ("B.swf");

var variables : URLVariables = new URLVariables();
variables.xml = "test.xml";

// This line causes the error 2044, else B.swf loads fine with FlashVars  
request.data = variables;

loader.load (request); 

In B.swf, it is checking the Flashvars like so. It works fine from html side

this.loaderInfo.parameters.xml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

金兰素衣 2024-08-29 03:14:24

尽管 querystring 方法在本地应该可以正常工作,但如果您使用的是 Flash Player 10.2,则有一个新的 API 可以实现此目的。

var context:LoaderContext = new LoaderContext();
context.parameters = {'xml': 'test.xml'};
loader.load(request, context);

文档在这里:
http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/flash/system/LoaderContext.html#parameters

Although the querystring method should work fine locally, if you're using Flash Player 10.2, there's a new API for this.

var context:LoaderContext = new LoaderContext();
context.parameters = {'xml': 'test.xml'};
loader.load(request, context);

The documentation is here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/LoaderContext.html#parameters

尘世孤行 2024-08-29 03:14:24

“A”不必将 FlashVars 传递给“B”。只需让 B 访问 FlashVars 本身即可。无论 B 位于 A 内部还是位于顶层本身,以下操作都将起作用:

在 B 的构造函数中添加 ADDED_TO_STAGE 事件侦听器。例如:

function B(){
    this.addEventListener(Event.AddedToStage, onAddedToStageHandler);
}

当您有权访问舞台时,您现在可以通过以下方式访问 A 中的 FlashVars:

要正确查看 B.swf 中名为 myVar flashVar 的变量,您可以(在 B 内)执行:

private function onAddedToStageHandler(){
var flashVars : Object = LoaderInfo(this.stage.loaderInfo).parameters;
// now you have access to your flashVars!
trace(flashVars.myVar);
}

stage.loaderInfo 是您需要查看的内容。

It's not necessary that "A" pass FlashVars to "B". Just have B access the FlashVars itself. The following will work whether B is inside of A, or top-level itself:

Add an ADDED_TO_STAGE event listener in B's constructor. e.g.:

function B(){
    this.addEventListener(Event.AddedToStage, onAddedToStageHandler);
}

When you have access to the stage you can now access the FlashVars in A this way:

To properly see a variable called myVar flashVar in B.swf, you do (inside B):

private function onAddedToStageHandler(){
var flashVars : Object = LoaderInfo(this.stage.loaderInfo).parameters;
// now you have access to your flashVars!
trace(flashVars.myVar);
}

stage.loaderInfo is what you need to look at.

很快妥协 2024-08-29 03:14:24

你可以在加载时将 flash 变量添加到 URI 中,但

URLRequest(String("B.swf" + "?myvar=45"));

问题是,当你加载 uri 中的字符串时,它会被放入一个对象 loaderInfo.parameters 中,所以如果你想传递这些参数,您需要创建一个字符串来传递这些参数。

这是来自 http://ragona.com/blog/pass-flashvars-loaded 的脚本-swf/ 显示如何将其再次转换为字符串数组

//:: Store loader info
var lInfo:Object = this.root.loaderInfo.parameters;
//:: Flashvars
var fVars:String = "?whee=nada"; //:: Getting the syntax change (? --> &) out of the way with a dummy var

//:: Set path + data
for (var flashVar in lInfo)
{
    fVars += "&" + flashVar + "=" + lInfo[flashVar];
}

var myRequest:URLRequest = new URLRequest(String("/myPath.swf" + fVars));

you can add the flash vars into the URI when you are loading it

URLRequest(String("B.swf" + "?myvar=45"));

the problem is that when you loaded the string in the uri, it is put inside an Object loaderInfo.parameters so if you want to pass those parameters, you need to create a string to pass these into.

here's a script from http://ragona.com/blog/pass-flashvars-loaded-swf/ that shows how to convert that into a string array again

//:: Store loader info
var lInfo:Object = this.root.loaderInfo.parameters;
//:: Flashvars
var fVars:String = "?whee=nada"; //:: Getting the syntax change (? --> &) out of the way with a dummy var

//:: Set path + data
for (var flashVar in lInfo)
{
    fVars += "&" + flashVar + "=" + lInfo[flashVar];
}

var myRequest:URLRequest = new URLRequest(String("/myPath.swf" + fVars));
遗弃M 2024-08-29 03:14:24

如何沙箱权限?我尝试通过设置添加文件夹,但这也不起作用。

http://www.macromedia.com/support/ Documentation/en/flashplayer/help/settings_manager04.html#117502

我做了一个简单的新项目。这是完整的代码。

var mc:MovieClip = new MovieClip ();

var loader:Loader = new Loader ();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, OnComplete);

var request:URLRequest = new URLRequest ("B.swf"); 

var variables : URLVariables = new URLVariables(); 
variables.xml = "test2.xml"; 

// This line causes the error 2044, if i comment out, it runs fine without FlashVars   
request.data = variables; 

loader.load (request);  


function OnComplete (e:Event)
{
    trace ("On Complete");
    mc = e.currentTarget.content as MovieClip;
    addChild (mc);
}

How do I sandbox the permissions? I tried adding the folder via the settings, but that didn't work too.

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html#117502

I made a simple as new project. This is the complete code.

var mc:MovieClip = new MovieClip ();

var loader:Loader = new Loader ();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, OnComplete);

var request:URLRequest = new URLRequest ("B.swf"); 

var variables : URLVariables = new URLVariables(); 
variables.xml = "test2.xml"; 

// This line causes the error 2044, if i comment out, it runs fine without FlashVars   
request.data = variables; 

loader.load (request);  


function OnComplete (e:Event)
{
    trace ("On Complete");
    mc = e.currentTarget.content as MovieClip;
    addChild (mc);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文