확장스크립트를 이용한 flash script를 이용한 native code의 통신방법에 대해 정리하겠다.
 
세가지의 연동관련 이슈가 있다.

1) Flash단에서 Native단으로 이벤트 전달
2) Flash단에서 Native단의 상태 얻기
3) Native단의 이벤트 발생시 Flash단에서 그 이벤트를 전달받기

각 이슈별로 Flash단과 Native단관점에서 하는 일은 아래와 같다.

1) Flash단에서 Native단으로 이벤트 전달

    Flash -> ext_fscommand2(arg1, arg2, arg3) 형태로 argument로 구분하여 이벤트를 전달할 수 있다.
    Native -> engine에서 제공하는 callback함수 int onFlashEngineStatus(int stat, void *arg1, void *arg2, void **arg3)로 처리 가능
int onFlashEngineStatus(
int stat,   // status
void *arg1,  // 구분자
void *arg2,  // arg개수
void **arg3) // arg리스트

2) Flash단에서 Native단의 상태 얻기

   Flash단 -> 기본적으로 이벤트 전달할 때와 동일하며 새번째 arg는 script에서 정의된 var값이 넘어간다. 
                   var var1;
                   ext_fscommand(arg1, arg2, "var1")이 호출되면 var1변수값이 변경된다.
   Native단 -> onFlashEngineStatus()에서 arg1과 arg2로 구분하여 해당 이벤트를 전달 받을 수 있으며 이 때 s3wi_setFlashVar()로 값을 채워넣을 수 있다.

3) Native단의 이벤트 발생시 Flash단에서 그 이벤트를 전달받기

   Flash단 -> Listener를 등록하여 Native단의 이벤트를 전달 받을 수 있다.
   messageEvent = new Object();
messageEvent.onEvent = function() {
   if (arguments[0] == "STAT_EVENT_BATTERY")
   {
                 //배터리 레벨표시 아이콘 프레임 변경, arguments[1] = 0~4 까지
                 battery_mc.gotoAndStop(arguments[1])
   }   
else
   {
                 debug_txt.text = "Unkown Event Error";
   }
};
ExtendedEvents.OnM35TPlatformEvent.addListener(messageEvent); // OnM35TPlatformEvent는 native에서 전송시 첫번째 파라메터


  Native단 -> 내부에서 flash단으로 이벤트를 보내야 하는 경우 s3wi_SendExtendedEvent()로 이벤트를 보낼 수 있다.
                  flash_SendExtendedEvent(hFlash, argc, argv))



Posted by 삼스