目的:从自动生成的***.html 中向swf传参数,但是我在mxml中取值时为空!各位大侠帮忙看下。在AC_FL_RunContent下传参没问题,但是在object中就不行!
mxml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" updateComplete="getVars();">
<mx:Script> <![CDATA[ //
public function getVars():void
{
var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;//root.loaderInfo.parameters;
MyValue.text = flashvars['param1'];
Value2.text = flashvars['param2'];
if(stage){
var myValue:String=Application.application.parameters.param1;
}
var txt:String = "";
txt += ("params:" + "\n");
try {
var key:String;
var val:String;
for (key in flashvars) {
val = String(flashvars[key]);
txt += ("\t" + key + ":\t" + val + "\n");
}
}catch (error:Error) { txt += (error); }
txtArea.text = txt;
}
]]>
</mx:Script>
<mx:Form x="13" y="10">
<mx:FormItem label="MyValue">
<mx:TextInput id="MyValue" text="{MyValue}"/>
</mx:FormItem> <mx:FormItem label="Value2">
<mx:TextInput id="Value2" text="{Value2}"/>
</mx:FormItem>
</mx:Form>
<mx:TextArea id="txtArea" x="10" y="106" width="260" height="117">
</mx:TextArea> <mx:Button label="调入 FlashVars" click="getVars()" x="87" y="231"/>
</mx:Application>
html代码如下:
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="getxml" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="getxml.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="param1=56666¶m2=2222" /> <embed src="getxml.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="getxml" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</noscript>
mxml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" updateComplete="getVars();">
<mx:Script> <![CDATA[ //
public function getVars():void
{
var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;//root.loaderInfo.parameters;
MyValue.text = flashvars['param1'];
Value2.text = flashvars['param2'];
if(stage){
var myValue:String=Application.application.parameters.param1;
}
var txt:String = "";
txt += ("params:" + "\n");
try {
var key:String;
var val:String;
for (key in flashvars) {
val = String(flashvars[key]);
txt += ("\t" + key + ":\t" + val + "\n");
}
}catch (error:Error) { txt += (error); }
txtArea.text = txt;
}
]]>
</mx:Script>
<mx:Form x="13" y="10">
<mx:FormItem label="MyValue">
<mx:TextInput id="MyValue" text="{MyValue}"/>
</mx:FormItem> <mx:FormItem label="Value2">
<mx:TextInput id="Value2" text="{Value2}"/>
</mx:FormItem>
</mx:Form>
<mx:TextArea id="txtArea" x="10" y="106" width="260" height="117">
</mx:TextArea> <mx:Button label="调入 FlashVars" click="getVars()" x="87" y="231"/>
</mx:Application>
html代码如下:
<noscript>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="getxml" width="100%" height="100%"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="getxml.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="param1=56666¶m2=2222" /> <embed src="getxml.swf" quality="high" bgcolor="#869ca7"
width="100%" height="100%" name="getxml" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</noscript>
public function getRootName(name:String):void{
rootName = name;
}
protected function initApp(event:FlexEvent):void{
ExternalInterface.call("relevanceInit");
}
protected function preInit(event:FlexEvent):void{
ExternalInterface.addCallback("getRootName",getRootName);
}
就是先给js注册一个flex方法,然后再在flex里面调用js,让js通过注册的flex方法赋值
<param name="movie" value="tst">
</object>