Flash教程:汇总网页传递参数到flex中的三种方法

作者:佚名    来源:转载    发布时间:2010-11-14 12:38:46
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?myName=Danger’>
    …
    <embed src=’TitleTest.mxml.swf?myName=Danger’ … />
</object>
3.如果通过url直接访问Flash,可以直接再后面加参数,例如:
http://localhost:8100/flex/myApp.swf?myName=Nick&myHometown=San
如何在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
{
trace(Application.application.parameters["id"]);
trace(this.parameters["id"]);// 这样写也行
}
]]>
</mx:Sctipt>
</mx:Application>

你可能感兴趣的:(Flash)