관리 메뉴

nkdk의 세상

스크립트 작성시 액션 스크립트 부분 따로 나누기 본문

My Programing/Flex&AIR

스크립트 작성시 액션 스크립트 부분 따로 나누기

nkdk 2008. 5. 28. 11:08
Techniques for separating ActionScript from MXML
기술에 입각하여 설명드리면 다음과 같습니다.

<!-- usingas/ASSourceFile.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

  <!-- Specify the ActionScript file that contains the function. -->
  <mx:Script source="includes/Sample3Script.as"/>

  <mx:Panel title="My Application" paddingTop="10" paddingBottom="10"
     paddingLeft="10" paddingRight="10">
     <mx:HBox>
        <mx:Label text="Temperature in Fahrenheit:"/>
        <mx:TextInput id="fahrenheit" width="120"/>
        <mx:Button label="Convert" click="celsius.text=calculate(fahrenheit.text);"/>
        <mx:Label text="Temperature in Celsius:"/>
        <mx:Label id="celsius" width="120" fontSize="24"/>
     </mx:HBox>
  </mx:Panel>
</mx:Application>

// usingas/includes/Sample3Script.as
public function calculate(s:String):String {
    var n:Number = Number(s);
    var t:Number = Math.round((n-32)/1.8*10)/10;
    return String(t);
}

이렇게 따로 만들어서 설정이 가능합니다.  mvc라던지 부분을 만들 때 많은 응용이 가능하겠네요.^^ 추후에는 프레임 워크를 어떻게 짜서 mvc를 응용하는 가에 대한 문제가 관건이 되겠네요.