19. ? 在.m檔裡import檔案?
#import "FlashRuntimeExtensions.h"
? 實作LNGenericANEInitializer?方法
//
// The extension initializer is called the first time the ActionScript side of the extension
// calls ExtensionContext.createExtensionContext() for any context.
!
void LNGenericANEInitializer(void** extDataToSet, FREContextInitializer*
ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet) {
NSLog(@"Entering ExtInitializer()");
*extDataToSet = NULL;
*ctxInitializerToSet = &LNGenericANEContextInitializer;
*ctxFinalizerToSet = &LNGenericANEContextFinalizer;
NSLog(@"Exiting ExtInitializer()");
} 指定初始化和結束Context的函式
20. ? 實作Context初始化程式
// The context initializer is called when the runtime creates the extension context instance.
void LNGenericANEContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t*
numFunctionsToTest, const FRENamedFunction** functionsToSet) {
NSLog(@"Entering ContextInitializer()");
*numFunctionsToTest = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction) * 1);
func[0].name = (const uint8_t*)"helloWorld";
func[0].functionData = NULL;
func[0].function = &helloWorld;
*functionsToSet = func;
NSLog(@"Exiting ContextInitializer()");
}
? 實作函式內容
FREObject helloWorld(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
NSLog(@"Entering hellowWorld()");
// Create Hello World String
NSString *helloString = @"Hello World!";
// Convert Obj-C string to C UTF8String
const char *str = [helloString UTF8String];
// Prepare for AS3
FREObject retStr;
FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t*)str, &retStr);
// Return data back to ActionScript
return retStr;
}
21. 參考資料
? 【技術】Flash Air Native Extension 應?用?
http://lets-make-games.blogspot.tw/2013/03/?ash-air-native-extension.html
? AIR For Native Extension 創建?心得?
http://ez2code.blogspot.tw/2012/03/air-for-native-extension.html
? 官?方pdf?手冊?
http://www.adobe.com/content/dam/Adobe/en/devnet/devices/pdfs/
DevelopingActionScriptExtensionsForAdobeAIR.pdf
? Extending Adobe AIR?
http://www.adobe.com/devnet/air/articles/extending-air.html
? Building a native extension for iOS and Android?
http://www.adobe.com/devnet/air/articles/building-ane-ios-android-pt1.html
? Adobe Flash Platform?
http://help.adobe.com/en_US/air/extensions/index.html