googleAdsense_widever


dispatch custom event to actionscript from android source Adobe Air






1) android 단의 ~Extension.java ( extension.xml 에 정의된 initializer )


package com.artesophy.ane;

import android.content.Context;
import android.util.Log;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREExtension;

public class aneExtension implements FREExtension {
private static final String FREContext = null;
public static FREContext extensionContext;
public static Context appContext;
@Override
public FREContext createContext(String arg0) {
// TODO Auto-generated method stub
Log.i("lol", "call createContext");
return new aneContext();
}

@Override
public void dispose() {
// TODO Auto-generated method stub
extensionContext = null;
}

@Override
public void initialize() {
// TODO Auto-generated method stub

}
public static void customEvent(String customVal){
Log.i("lol", "sending cookies to AS");
extensionContext.dispatchStatusEventAsync("CUSTOM_EVENT", customVal);
}
}





2) funtion java 파일

package com.artesophy.ane;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class aneFunction implements FREFunction {

@Override
public FREObject call(FREContext context, FREObject[] arg1) {
// TODO Auto-generated method stub
aneExtension.extensionContext = context;
Context appContext = context.getActivity().getApplicationContext();
aneExtension.appContext = appContext;
return null;
}
}




3) 원하는 곳에서 이벤트를 발생시키는 함수를 호출한다.

aneExtension.customEvent(customVal);







4) actionscript 단의 Event 정의 클래스

package com.artesophy.ane
{
import flash.events.Event;
public class aneEvent extends Event
{
public static const CUSTOM_EVENT:String = "eventIsCatched";
private var _val:String = "";
public function aneEvent(type:String, val:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
_val = val;
}
public function get cookies():String{
return _val;
}
public override function clone():Event{
return new aneEvent(type, _val, bubbles, cancelable);
}
}
}





5) actionscript 단의 EventDispatcher 를 상속받은 클래스


package com.artesophy.ane
{
import flash.events.EventDispatcher;
import flash.events.StatusEvent;
import flash.external.ExtensionContext;

public class aneExtension extends EventDispatcher {  
private var context:ExtensionContext;
public function aneExtension()
{
try{
context = ExtensionContext.createExtensionContext("com.artesophy.ane", null);
context.addEventListener(StatusEvent.STATUS, onStatus);
}catch(e:Error){
trace(e.message);
}
}
public function customFunction1(val:String):void{
context.call("customFunc1", val);
}
public function customFunction2(val:String):void{
context.call("customFunc2", val);
}
public function onStatus(e:StatusEvent):void{
if(e.code == "CUSTOM_EVENT"){
trace("CUSTOM_EVENT event is arrived.");
var val:String = e.level;
dispatchEvent(new aneEvent(aneEvent.CUSTOM_EVENT, val));
}
}
}
}




6) ane 를 사용하는 Project 의 소스

protected function onCreationComplete(event:FlexEvent):void{
// TODO Auto-generated method stub
wvExt = new aneExtension();
wvExt.addEventListener(aneEvent.CUSTOM_EVENT, onANEEvent);
}


protected function onANEEvent(e:aneEvent):void{
trace("onEvent");
}








dispatchStatusEventAsync 함수를 호출할 때, 안드로이드 process 에서 오류가 발생한다면 

context 가 잘못되었기 때문.

actionscript 에서 호출해서 만든 context 에 대해 dispatchStatusEventAsync 를 발생시켜야 한다.


덧글

댓글 입력 영역


공지

어서오십시오.
트위터 : @FCliver
기저심리학 : 네이버카페
카카오톡 : FCliver
페이스북 : Fredric Cliver

통계 위젯 (화이트)

650
201
275623

접속자 위치