如何访问 AS3 中的 flashvars,并将它们添加到现有文本字段?

发布于 2024-10-12 06:54:44 字数 3027 浏览 2 评论 0原文

编辑:我开始意识到我面临的主要问题是我想要一个已经存在于影片剪辑或舞台上的文本字段来从 flashvar 中获取字符串。由于某种原因它不会这样做。如何更改预先存在的文本字段以匹配 flashvar 文本?

Html:

<div id="flashContent">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="29px" id="egnewsTicker" align="middle">
                <param name="movie" value="egnewsTicker.swf" />
                <param name="flashvars" value="newslisttest=this is my test" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="showall" />
                <param name="menu" value="false" />
                <param name="devicefont" value="false" />
                <param name="salign" value="lt" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="egnewsTicker.swf" width="100%" height="29px">
                    <param name="movie" value="egnewsTicker.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="transparent" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="false" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="lt" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="flashvars" value="newslisttest=this is my test" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>

我知道这应该是一个简单的任务,并且我找到了几篇提供示例的网络文章,但当我尝试编写自己的代码时,我根本无法使其工作。我想做的就是传递一个 flashvar 字符串,并能够使用 AS3 在 flash 中按名称访问它,但我似乎无法实现这一点。

我正在尝试:

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
newsItem.newsHeadline.text = String(paramObj[varName]);

我也尝试过:

newsItem.newsHeadline.text = this.loaderInfo.parameters.newslisttest;

我尝试的任何东西都不起作用,它总是保持空白。在 flash as3 中访问 flashvars 的技巧是什么?我只是不明白,而且我在任何地方都找不到好的解释......

Edit: I've come to realize the main problem I'm facing is that I want a text field that already exists in a movieclip or on the stage to take the string from a flashvar. For some reason it will not do that. How do I make a pre-existing text field change to match the flashvar text?

Html:

<div id="flashContent">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" height="29px" id="egnewsTicker" align="middle">
                <param name="movie" value="egnewsTicker.swf" />
                <param name="flashvars" value="newslisttest=this is my test" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="transparent" />
                <param name="scale" value="showall" />
                <param name="menu" value="false" />
                <param name="devicefont" value="false" />
                <param name="salign" value="lt" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="egnewsTicker.swf" width="100%" height="29px">
                    <param name="movie" value="egnewsTicker.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="play" value="true" />
                    <param name="loop" value="true" />
                    <param name="wmode" value="transparent" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="false" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="lt" />
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="flashvars" value="newslisttest=this is my test" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>

I know this is supposed to be a simple task, and I have found several web articles that give examples, but I simply cannot make it work when I'm trying to do my own code. All I want to do is pass a flashvar string and be able to access it by name in flash using AS3, but I can't seem to accomplish that.

I'm trying:

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
newsItem.newsHeadline.text = String(paramObj[varName]);

I've also tried:

newsItem.newsHeadline.text = this.loaderInfo.parameters.newslisttest;

Nothing I try works, it always just stays blank. What is the trick to accessing flashvars in flash as3? I'm just not getting it and I can't find a good explanation anywhere...

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

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

发布评论

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

评论(3

倥絔 2024-10-19 06:54:44

试试这个: stage.loaderInfo.parameters.yourparamstage.loaderInfo.parameters["yourparam"]

您可以发布您的 html 代码,以便我们了解您如何传递flashvars 到 Flash。

Try this: stage.loaderInfo.parameters.yourparam or stage.loaderInfo.parameters["yourparam"]

Can you post your html code, so we can see how you pass the flashvars to Flash.

风苍溪 2024-10-19 06:54:44

我整天都在浪费时间......

AS3:

var uid:String;
// your code
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
// your code
function loaderComplete(e:Event=null):void
{
    var fv = stage.loaderInfo.parameters;
    uid = fv['uid'] || "'uid' not found";
}

HTML:

<object type='application/x-shockwave-flash' data='/flash/yourSWF.swf' width='320' height='240'>
<param name='wmode' value='transparent' />
<param name='FlashVars' value='uid=yourData' />
<param name='movie' value='/flash/yourSWF.swf' />
</object>

I've been wasted all the day long for that...

AS3:

var uid:String;
// your code
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
// your code
function loaderComplete(e:Event=null):void
{
    var fv = stage.loaderInfo.parameters;
    uid = fv['uid'] || "'uid' not found";
}

HTML:

<object type='application/x-shockwave-flash' data='/flash/yourSWF.swf' width='320' height='240'>
<param name='wmode' value='transparent' />
<param name='FlashVars' value='uid=yourData' />
<param name='movie' value='/flash/yourSWF.swf' />
</object>
允世 2024-10-19 06:54:44

如果您仍然遇到此问题,请按照以下步骤操作。
我使用了 flash vars,它们对我来说工作得很好。

我的 html 脚本是:

<html>
<body>
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"FlashVars="uid=123&name=santhu" width="100%" height="100%" id="index" align="middle">
  <param name="movie" value="index.swf" />
  <param name=FlashVars value="uid=123&name=santhu">
  <!--[if !IE]>-->
   <object type="application/x-shockwave-flash" data="index.swf" 
            FlashVars="uid=123&name=santhu"  width="100%" height="100%">
     <param name="movie" value="index.swf" />
     <param name=FlashVars value="uid=123&name=santhu">
  <!--<![endif]-->
  <!--[if !IE]>-->
   </object>
  <!--<![endif]-->
</object>
</div>
</body>
</html>

我的加载变量的 AS 代码是

this.root.loaderInfo.addEventListener(Event.COMPLETE, SWFLoadComplete);
private function SWFLoadComplete(e:Event)
{
  obj=this.root.loaderInfo.parameters;
  trace(obj.uid , obj.name);  // outputs: 123 santhu
}

If you are still having this problem, follow below lines.
I used flash vars, they work fine for me.

My html script was:

<html>
<body>
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"FlashVars="uid=123&name=santhu" width="100%" height="100%" id="index" align="middle">
  <param name="movie" value="index.swf" />
  <param name=FlashVars value="uid=123&name=santhu">
  <!--[if !IE]>-->
   <object type="application/x-shockwave-flash" data="index.swf" 
            FlashVars="uid=123&name=santhu"  width="100%" height="100%">
     <param name="movie" value="index.swf" />
     <param name=FlashVars value="uid=123&name=santhu">
  <!--<![endif]-->
  <!--[if !IE]>-->
   </object>
  <!--<![endif]-->
</object>
</div>
</body>
</html>

and my AS code to load vars is

this.root.loaderInfo.addEventListener(Event.COMPLETE, SWFLoadComplete);
private function SWFLoadComplete(e:Event)
{
  obj=this.root.loaderInfo.parameters;
  trace(obj.uid , obj.name);  // outputs: 123 santhu
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文