通过页面传递参数到flex中的几种方法

1.在和中设置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’" mce_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’" mce_src="’TitleTest.mxml.swf?myName=Danger’" … />     
</object>

 

2.或者在<Object>和<embed>中的src属性中直接加参数,例如:

  1. <object … >    
  2.     <param name=’src’ value=’TitleTest.mxml.swf?myName=Danger>    
  3.     …    
  4.     <embed src="’TitleTest.mxml.swf?myName=Danger’" mce_src="’TitleTest.mxml.swf?myName=Danger’" … />    
  5. </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> 
<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>

 

你可能感兴趣的:(Flex,Flash,Adobe,Go)