[Flex] 在 Flex4 中取得(GET)外部參數..
2011/02/14
之前在 在 Flex 中取得(GET)外部參數..  這篇文章去了解到在Flex 3 中
如何讀取到 http://www.sample.com.tw/Main.swf?UserId=Lucifer
其中網址傳進來的UserId 的值..
但是在Flex 4 中有些小改變…
所以筆記一下很容易忘記…
假設網址是  http://www.sample.com.tw/Main.swf?pid=Lucifer
所以在ActionScript 中…
您必須先
import mx.core.FlexGlobals;取得的方法是
FlexGlobals.topLevelApplication.parameters["pid"]完整Code :
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here --></fx:Declarations>
<fx:Script>
<![CDATA[import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.controls.*;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{var PublishId:String=FlexGlobals.topLevelApplication.parameters["pid"]
Alert.show(PublishId);
}
]]></fx:Script>
</s:Application>
結果:

讚一下:
標籤:
ActionScript,
Flex
 | 
 
			
				 This entry was posted on 上午11:26
	and is filed under          
ActionScript
,
Flex
						.
							
				You can follow any responses to this entry through 
				the RSS 2.0 feed. 
				
				
					You can leave a response,
		        
				or trackback from your own site.
			
訂閱:
張貼留言 (Atom)
0 意見:
張貼留言