加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex 开发中 ,html向flex传递参数

发布时间:2020-12-15 04:24:29 所属栏目:百科 来源:网络整理
导读:最近在做一个flex 的开发,需要用到从html向flex编译出来的swf文件传递一个参数。因为没有做个相关的工作,所以就找各种帖子来看看。 以下是网上提供的大多数方法。 ?1.使用Application.application.parameters,结合flashvars进行传参。2,使用LoaderInfo(thi

最近在做一个flex 的开发,需要用到从html向flex编译出来的swf文件传递一个参数。因为没有做个相关的工作,所以就找各种帖子来看看。

以下是网上提供的大多数方法。 ?1.使用Application.application.parameters,结合flashvars进行传参。2,使用LoaderInfo(this.root.loaderInfo).parameters

不过在我的开发中都是报错,之后查了一些资料,发现LoaderInfo(this.root.loaderInfo).parameters是使用在as开发成的swf中使用,不适合使用在flex项目中。Application.application.parameters的传参方法在flex4.0之后的版本已经被抛弃了,所以不能直接使用。

flex4.0之后提供的方法是使用FlexGlobals.topLevelApplication.parameters ,直接使用可能会报错,是因为需要导入import mx.core.FlexGlobals;,这样就正确了!

以下是一个小例子:


html中:

?<script type="text/javascript">
? ? ? ? ? ? <!-- For version detection,set to min. required Flash Player version,or 0 (or 0.0.0),for no version detection. -->?
? ? ? ? ? ? var swfVersionStr = "10.0.0";
? ? ? ? ? ? <!-- To use express install,set to playerProductInstall.swf,otherwise the empty string. -->
? ? ? ? ? ? var xiSwfUrlStr = "playerProductInstall.swf";
? ? ? ? ? ? var flashvars = {};
flashvars.soundUrl = "img/music.mp3" ? ? ? ? ? ? ? ?//这个就是需要传参给swf的参数
? ? ? ? ? ? var params = {};
? ? ? ? ? ? params.quality = "high";
? ? ? ? ? ? params.bgcolor = "#b9fbf9";
? ? ? ? ? ? params.allowscriptaccess = "sameDomain";
? ? ? ? ? ? params.allowfullscreen = "true";
? ? ? ? ? ? var attributes = {};
? ? ? ? ??
? ? ? ? ? ? swfobject.embedSWF(
? ? ? ? ? ? ? ? "****.swf","flashContent",?
? ? ? ? ? ? ? ? "470","90",?
? ? ? ? ? ? ? ? swfVersionStr,xiSwfUrlStr,?
? ? ? ? ? ? ? ? flashvars,params,attributes);
<!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
swfobject.createCSS("#flashContent","display:block;text-align:left;");
? ? ? ? </script>



flex中?

var soundUrl:String =FlexGlobals.topLevelApplication.parameters.soundUrl;?


这样就可以在flex 中引用外部参数了····


ps:菜鸟的学习,欢迎大侠拍砖指点哈!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读