1.在<Object>和<embed>中设置flashVars参数 ,例如:
<object id=’mySwf’ classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000′ codebase=’http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab’ height=’100%’ width=’100%’>
<param name=’src’ value=’FlashVarTest.swf’/>
<param name=’flashVars’ value=’firstName=Nick&lastName=Danger’/>
<embed name=’mySwf’ src=’FlashVarTest.swf’ pluginspage=’http://www.adobe.com/go/getflashplayer’ height=’100%’ width=’100%’ flashVars=’firstName=Nick&lastName=Danger’/>
<embed src=’TitleTest.mxml.swf?myName=Danger’ … />
</object>
2.或者在<Object>和<embed>中的src属性中直接加参数 ,例如:
<object … >
<param name=’src’ value=’TitleTest.mxml.swf? ’firstName=Nick&lastName=Danger ’>
…
<embed src=’TitleTest.mxml.swf? ’firstName=Nick&lastName=Danger ’ … />
</object>
<object id=’mySwf’ classid=’clsid:D27CDB6E-AE6D-11cf-96B8-444553540000′ codebase=’http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab’ height=’100%’ width=’100%’>
<param name=’src’ value=’FlashVarTest.swf’/>
<param name=’flashVars’ value=’firstName=Nick&lastName=Danger’/>
<embed name=’mySwf’ src=’FlashVarTest.swf’ pluginspage=’http://www.adobe.com/go/getflashplayer’ height=’100%’ width=’100%’ flashVars=’firstName=Nick&lastName=Danger’/>
<embed src=’TitleTest.mxml.swf?myName=Danger’ … />
</object>
2.或者在<Object>和<embed>中的src属性中直接加参数 ,例如:
<object … >
<param name=’src’ value=’TitleTest.mxml.swf? ’firstName=Nick&lastName=Danger ’>
…
<embed src=’TitleTest.mxml.swf? ’firstName=Nick&lastName=Danger ’ … />
</object>
3. 修改加载flash的html页面,找到第二个AC_FL_RunContent 中的代码内容,代码如下
AC_FL_RunContent(
" src " , " ${swf} " ,
" width " , " ${width} " ,
" height " , " ${height} " ,
" align " , " middle " ,
" id " , " ${application} " ,
" quality " , " high " ,
" bgcolor " , " ${bgcolor} " ,
" name " , " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " , " application/x-shockwave-flash " ,
" pluginspage " , " http://www.adobe.com/go/getflashplayer "
);
" src " , " ${swf} " ,
" width " , " ${width} " ,
" height " , " ${height} " ,
" align " , " middle " ,
" id " , " ${application} " ,
" quality " , " high " ,
" bgcolor " , " ${bgcolor} " ,
" name " , " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " , " application/x-shockwave-flash " ,
" pluginspage " , " http://www.adobe.com/go/getflashplayer "
);
在"pluginspage", "
http://www.adobe.com/go/getflashplayer "位置后,加上代码("flashvars","youParmName=youValue"),即如下:
AC_FL_RunContent(
" src " , " ${swf} " ,
" width " , " ${width} " ,
" height " , " ${height} " ,
" align " , " middle " ,
" id " , " ${application} " ,
" quality " , " high " ,
" bgcolor " , " ${bgcolor} " ,
" name " , " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " , " application/x-shockwave-flash " ,
" pluginspage " , " http://www.adobe.com/go/getflashplayer ",
4.如果通过url直接访问Flash,可以直接再后面加参数 ,例如:
http://localhost:8100/flex/myApp.swf? ’firstName=Nick&lastName=Danger
如何在Flex中读取这些参数 :
可以用Application.application.parameters或LoaderConfig.parameters获得外部参数。
但是切忌:只能在Application部署完成之后才能获取这些参数。也就是在派发creationComplete之后才能获得。例如:
mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” width=”100%” height=”100%”
layout=”absolute” creationComplete=”initApp()” initialize=”init()”>
<mx:Script>
<![CDATA[
import mx.core.Application
private function init():void
{
trace(Application.application.parameters["id"]);//输出undefined证明获取参数失败
}
private function initApp():void
{
var str : String = "";
for (var i:String in Application.application.parameters)
{
str += Application.application.parameters[i] + "/n";
}
Alert.show(str);
str = Application.application.parameters[" firstName "];
Alert.show("dd="+ str);
}
]]>
</mx:Sctipt>
</mx:Application>
" src " , " ${swf} " ,
" width " , " ${width} " ,
" height " , " ${height} " ,
" align " , " middle " ,
" id " , " ${application} " ,
" quality " , " high " ,
" bgcolor " , " ${bgcolor} " ,
" name " , " ${application} " ,
" allowScriptAccess " , " sameDomain " ,
" type " , " application/x-shockwave-flash " ,
" pluginspage " , " http://www.adobe.com/go/getflashplayer ",
"flashvars","youParmName=youValue"
);
);
4.如果通过url直接访问Flash,可以直接再后面加参数 ,例如:
http://localhost:8100/flex/myApp.swf? ’firstName=Nick&lastName=Danger
如何在Flex中读取这些参数 :
可以用Application.application.parameters或LoaderConfig.parameters获得外部参数。
但是切忌:只能在Application部署完成之后才能获取这些参数。也就是在派发creationComplete之后才能获得。例如:
mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” width=”100%” height=”100%”
layout=”absolute” creationComplete=”initApp()” initialize=”init()”>
<mx:Script>
<![CDATA[
import mx.core.Application
private function init():void
{
trace(Application.application.parameters["id"]);//输出undefined证明获取参数失败
}
private function initApp():void
{
var str : String = "";
for (var i:String in Application.application.parameters)
{
str += Application.application.parameters[i] + "/n";
}
Alert.show(str);
str = Application.application.parameters[" firstName "];
Alert.show("dd="+ str);
}
]]>
</mx:Sctipt>
</mx:Application>