관리 메뉴

nkdk의 세상

서버측에서 SWF 프로그램에게 파라미터를 전달하는 예 본문

My Programing/Flex&AIR

서버측에서 SWF 프로그램에게 파라미터를 전달하는 예

nkdk 2009. 10. 19. 01:02
SWF파일을 포함하는 HTML파일을 열고 다음과 같이 flashVars로 시작하는 한 줄을 삽입한다.

AC_FL_RunContent(
    "src", "TestApp",
    "flashVars", "myName=Danger&myHometown=Los%20Angeles",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "TestApp",
    "quality", "high",
    "name", "TestApp",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer"
);


Accessing the flashVars properties

<?xml version="1.0"?>
<!-- wrapper/ApplicationParameters.mxml -->
<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>


모든 파라미터의 값에 접근하는 예
<?xml version="1.0"?>
<!-- wrapper/IterateOverApplicationParameters.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
  <mx:Script><![CDATA[
     private function init():void {
        for (var i:String in Application.application.parameters) {
           ta1.text += i + ":" + Application.application.parameters[i] + "\n";
        }
     }
  ]]></mx:Script>
 
  <mx:TextArea id="ta1" width="300" height="200"/>

</mx:Application>

출처: http://micropilot.tistory.com/entry/SWF-Parameters-in-HTML