春觀夜櫻 夏望繁星 秋賞滿月 冬會初雪

28

2008.6

flex接收flashvars的方法和flash不一样,在as3中是用“root.loaderInfo.parameters”或“stage.loaderInfo.parameters”来取得传递的参数,而在flex中则要用“Application.application.parameters”来取得。看下面的代码,我们将利用“Application.application.parameters”的方法来取得flashvars传递过来的两个参数:myName和myHometown。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initVars()">
    <mx:Script><![CDATA[
        // Declare bindable properties in Application scope.
        [Bindable]
        public var myName:String;
        [Bindable]
        public var myHometown:String;
        
        // Assign values to new properties.
        private function initVars():void {
            myName = Application.application.parameters.myName;
            myHometown = Application.application.parameters.myHometown;
        }
    ]]></mx:Script>
    
    <mx:VBox>
    <mx:HBox>
        <mx:Label text="Name: "/>
        <mx:Label text="{myName}" fontWeight="bold"/>
    </mx:HBox>
    <mx:HBox>
        <mx:Label text="Hometown: "/>
        <mx:Label text="{myHometown}" fontWeight="bold"/>
    </mx:HBox>
    </mx:VBox>
</mx:Application>

下面是网页代码:

分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]