SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
AIR NATIVE EXTENSION
Claire Chang
WHAT’S ANE
• Adobe AIR 原⽣生擴充功能的
ActionScript API,可讓您存取以原⽣生
程式碼進⾏行程式設計的特定裝置功
能。	

• 原⽣生擴充功能是以下的組合:	

• ActionScript 類別。	

• 原⽣生程式碼。	

• 例如,有⼀一種原⽣生擴充功能可讓 AIR
應⽤用程式存取 Android 震動功能。
下載現成的ANE
• ane的網站

http://extensionsforair.com/	

• 官⽅方的ane

http://www.adobe.com/devnet/air/native-
extensions-for-air.html
NATIVEEXTENSION結構及原理
⼀一個NativeExtension項
⺫⽬目主要有兩個部分組
成:As 端的庫項⺫⽬目和
底層代碼的實現項⺫⽬目。
ACTION SCRIPT 類別項⺫⽬目
• 在AS的Library部分,開發者需要定義要開發的ANE,在Action Script
中會被呼叫到的API界⾯面	

• 這些API的具體實現會在相應的Java程式中被實作。	

• 在AS部分最核⼼心的類別是ExtensionContext,負責與Java程式的溝通。	

• ExtensionContext會呼叫createExtensionContext⽅方法創建和初始化Java
端的原⽣生程式。	

• ExtensionContext的call⽅方法會呼叫具體的Java⽅方法並獲得返回結果。	

• 同時Extension還會接受從java拋出的事件。
JAVA類別項⺫⽬目 - 1
• 在Java實現部分需要引⼊入AIR SDK中的FlashRuntimeExtensions.jar進⾏行
開發。	

• 最主要的三個類別是:FREExtension,FREContext和FREFunction	

• 上⾯面三個接⼝口都包含在FlashRuntimeExtensions.jar裡。	

• FREExtension	

• FREExtension是java端⾃自定義代碼的⼊入⼝口,是⼀一接⼝口,需要⽤用⼾戶重
寫createContext⽅方法從⽽而獲得本地代碼的內容。	

• AS庫項⺫⽬目部分的ExtensionContext的createExtensionContext⽅方法就
會調⽤用FREExtension的getContext來獲得在java裡所撰寫的內容。
JAVA類別項⺫⽬目 - 2
• FREContext	

• FREContext是是本地擴展的具體內容的提供者。我們需要重寫getFunctions⽅方法,
從⽽而返回本地擴展的具體的實現函數。	

• FREContext也會提供⼀一些與app相關的API以⽅方便開發	

• FREFunction	

• FREFunction是本地⽅方法的具體實現。FREFunction是⼀一個接⼝口,提供了call⽅方法。
在AS端的ExtensionContext中調⽤用的call⽅方法都會對應到具體的FREFunction的call⽅方
法。	

• FREContext的getFunctions函數會返回⼀一個Map,其key為⼀一個⾃自定義的String,
value是具體的FREFunction。	

• 通過getFunction⽅方法。AIR Runtime通過getFunction將AS端的call(key,args)⽅方法和java
端具體的FREFunctions的call(args)⽅方法進⾏行對應。
準備⼯工作
• 開始之前確保以下軟體都已經安裝	

• Flash Builder 4.6	

• AIR SDK 3	

• Flex SDK 4.6	

• 原⽣生語⾔言⽅方所需的Extensions	

• Android:FlashRuntimeExtensions.jar

位置:${FB_HOME}sdks4.6.0libandroidFlashRuntimeExtensions.jar	

• iOS:FlashRuntimeExtensions.h

位置:${FB_HOME}sdks4.6.0includeFlashRuntimeExtensions.h
ANDROID的ANE開發
2. 將項⺫⽬目的類型設為
Library型
1. 在eclipse中新建⼀一個Android項⺫⽬目,設置好專案名稱,注
意不要勾選創建Activity。
3. 開啟⼀一個android專案,將FlashRuntimeExtensions.h加⼊入
libraries
FREEXTENSION
接⼝口類和AIR程序對接
FRECONTEXT
FREFUNCTION
輸出成.JAR檔
FLASH端的對應程式
記得要選擇這個
實作ANE要讓AS呼叫的⽅方法
extension.xml
NotificationInterface.as
IOS的部份
• 開啟⼀一個CocoaTouch Static Library的專案	

!
!
!
!
!
!
!
!
• 將FlashRuntimeExtensions.h拉⼊入專案中
• 在.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的函式
• 實作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;
}
參考資料
• 【技術】Flash Air Native Extension 應⽤用

http://lets-make-games.blogspot.tw/2013/03/flash-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
謝謝⼤大家

Weitere ähnliche Inhalte

Ähnlich wie Ane

Azure Functions
Azure FunctionsAzure Functions
Azure FunctionsDino Wang
 
Adobe Air的应用与前景(孙颖)
Adobe Air的应用与前景(孙颖)Adobe Air的应用与前景(孙颖)
Adobe Air的应用与前景(孙颖)mimi qiao
 
GitHub android 40項熱門技術
GitHub android 40項熱門技術GitHub android 40項熱門技術
GitHub android 40項熱門技術勝全 謝
 
Introduction to air for android 邱彦林
Introduction to air for android 邱彦林Introduction to air for android 邱彦林
Introduction to air for android 邱彦林FLASH开发者交流会
 
twMVC#23 | 快速上手 Azure Functions
twMVC#23 | 快速上手 Azure FunctionstwMVC#23 | 快速上手 Azure Functions
twMVC#23 | 快速上手 Azure FunctionstwMVC
 
Android应用开发 - 沈大海
Android应用开发 - 沈大海Android应用开发 - 沈大海
Android应用开发 - 沈大海Shaoning Pan
 
LargeCodebases_Lecture01_Getting Set Up.pptx
LargeCodebases_Lecture01_Getting Set Up.pptxLargeCodebases_Lecture01_Getting Set Up.pptx
LargeCodebases_Lecture01_Getting Set Up.pptxssusere42ed6
 
Ext Js开发指导
Ext Js开发指导Ext Js开发指导
Ext Js开发指导clong365
 
Google app engine安裝教學
Google app engine安裝教學Google app engine安裝教學
Google app engine安裝教學勝億 曾
 
Adobe air 開發經驗分享
Adobe air 開發經驗分享Adobe air 開發經驗分享
Adobe air 開發經驗分享Rhino Lu
 
Workflow Overview
Workflow OverviewWorkflow Overview
Workflow OverviewKevin Cao
 
使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin FormsChen Yu Pao
 
GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase Duran Hsieh
 
ASP.NET Core 3.0 新功能
ASP.NET Core 3.0 新功能ASP.NET Core 3.0 新功能
ASP.NET Core 3.0 新功能Edward Kuo
 
Eclipse開發平台快速入門
Eclipse開發平台快速入門Eclipse開發平台快速入門
Eclipse開發平台快速入門Luo Korth
 
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集ASUSCloud
 
GDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfGDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfDuran Hsieh
 

Ähnlich wie Ane (20)

Azure Functions
Azure FunctionsAzure Functions
Azure Functions
 
Adobe Air的应用与前景(孙颖)
Adobe Air的应用与前景(孙颖)Adobe Air的应用与前景(孙颖)
Adobe Air的应用与前景(孙颖)
 
Les 3 ppt
Les 3 pptLes 3 ppt
Les 3 ppt
 
GitHub android 40項熱門技術
GitHub android 40項熱門技術GitHub android 40項熱門技術
GitHub android 40項熱門技術
 
Introduction to air for android 邱彦林
Introduction to air for android 邱彦林Introduction to air for android 邱彦林
Introduction to air for android 邱彦林
 
twMVC#23 | 快速上手 Azure Functions
twMVC#23 | 快速上手 Azure FunctionstwMVC#23 | 快速上手 Azure Functions
twMVC#23 | 快速上手 Azure Functions
 
Android应用开发 - 沈大海
Android应用开发 - 沈大海Android应用开发 - 沈大海
Android应用开发 - 沈大海
 
Android工作坊
Android工作坊Android工作坊
Android工作坊
 
LargeCodebases_Lecture01_Getting Set Up.pptx
LargeCodebases_Lecture01_Getting Set Up.pptxLargeCodebases_Lecture01_Getting Set Up.pptx
LargeCodebases_Lecture01_Getting Set Up.pptx
 
Ext Js开发指导
Ext Js开发指导Ext Js开发指导
Ext Js开发指导
 
Google app engine安裝教學
Google app engine安裝教學Google app engine安裝教學
Google app engine安裝教學
 
Adobe air 開發經驗分享
Adobe air 開發經驗分享Adobe air 開發經驗分享
Adobe air 開發經驗分享
 
Workflow Overview
Workflow OverviewWorkflow Overview
Workflow Overview
 
使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms使用JetBrains Rider開發Xamarin Forms
使用JetBrains Rider開發Xamarin Forms
 
敦群學院-SharePoint精英計畫-系統開發-Day 3
敦群學院-SharePoint精英計畫-系統開發-Day 3敦群學院-SharePoint精英計畫-系統開發-Day 3
敦群學院-SharePoint精英計畫-系統開發-Day 3
 
GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase GDG Taichung: What is new in Firebase
GDG Taichung: What is new in Firebase
 
ASP.NET Core 3.0 新功能
ASP.NET Core 3.0 新功能ASP.NET Core 3.0 新功能
ASP.NET Core 3.0 新功能
 
Eclipse開發平台快速入門
Eclipse開發平台快速入門Eclipse開發平台快速入門
Eclipse開發平台快速入門
 
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集
0527 asus cloud day 開放。引領數位內容進軍國際 – 華碩雲端市集
 
GDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdfGDG Taichung - Flutter and Firebase.pdf
GDG Taichung - Flutter and Firebase.pdf
 

Mehr von Claire Chang

我們要做什麼」20230707
我們要做什麼」20230707我們要做什麼」20230707
我們要做什麼」20230707Claire Chang
 
Pixi.js網頁遊戲開發實戰
Pixi.js網頁遊戲開發實戰Pixi.js網頁遊戲開發實戰
Pixi.js網頁遊戲開發實戰Claire Chang
 
Git版本管理控管實戰
Git版本管理控管實戰Git版本管理控管實戰
Git版本管理控管實戰Claire Chang
 
薩提爾的對話練習
薩提爾的對話練習薩提爾的對話練習
薩提爾的對話練習Claire Chang
 
從零架設直播伺服器
從零架設直播伺服器從零架設直播伺服器
從零架設直播伺服器Claire Chang
 
Learn to code 2 - Beyond the Basics
Learn to code 2 - Beyond the BasicsLearn to code 2 - Beyond the Basics
Learn to code 2 - Beyond the BasicsClaire Chang
 

Mehr von Claire Chang (7)

我們要做什麼」20230707
我們要做什麼」20230707我們要做什麼」20230707
我們要做什麼」20230707
 
Pixi.js網頁遊戲開發實戰
Pixi.js網頁遊戲開發實戰Pixi.js網頁遊戲開發實戰
Pixi.js網頁遊戲開發實戰
 
Git版本管理控管實戰
Git版本管理控管實戰Git版本管理控管實戰
Git版本管理控管實戰
 
ansible
ansibleansible
ansible
 
薩提爾的對話練習
薩提爾的對話練習薩提爾的對話練習
薩提爾的對話練習
 
從零架設直播伺服器
從零架設直播伺服器從零架設直播伺服器
從零架設直播伺服器
 
Learn to code 2 - Beyond the Basics
Learn to code 2 - Beyond the BasicsLearn to code 2 - Beyond the Basics
Learn to code 2 - Beyond the Basics
 

Ane

  • 2. WHAT’S ANE • Adobe AIR 原⽣生擴充功能的 ActionScript API,可讓您存取以原⽣生 程式碼進⾏行程式設計的特定裝置功 能。 • 原⽣生擴充功能是以下的組合: • ActionScript 類別。 • 原⽣生程式碼。 • 例如,有⼀一種原⽣生擴充功能可讓 AIR 應⽤用程式存取 Android 震動功能。
  • 5. ACTION SCRIPT 類別項⺫⽬目 • 在AS的Library部分,開發者需要定義要開發的ANE,在Action Script 中會被呼叫到的API界⾯面 • 這些API的具體實現會在相應的Java程式中被實作。 • 在AS部分最核⼼心的類別是ExtensionContext,負責與Java程式的溝通。 • ExtensionContext會呼叫createExtensionContext⽅方法創建和初始化Java 端的原⽣生程式。 • ExtensionContext的call⽅方法會呼叫具體的Java⽅方法並獲得返回結果。 • 同時Extension還會接受從java拋出的事件。
  • 6. JAVA類別項⺫⽬目 - 1 • 在Java實現部分需要引⼊入AIR SDK中的FlashRuntimeExtensions.jar進⾏行 開發。 • 最主要的三個類別是:FREExtension,FREContext和FREFunction • 上⾯面三個接⼝口都包含在FlashRuntimeExtensions.jar裡。 • FREExtension • FREExtension是java端⾃自定義代碼的⼊入⼝口,是⼀一接⼝口,需要⽤用⼾戶重 寫createContext⽅方法從⽽而獲得本地代碼的內容。 • AS庫項⺫⽬目部分的ExtensionContext的createExtensionContext⽅方法就 會調⽤用FREExtension的getContext來獲得在java裡所撰寫的內容。
  • 7. JAVA類別項⺫⽬目 - 2 • FREContext • FREContext是是本地擴展的具體內容的提供者。我們需要重寫getFunctions⽅方法, 從⽽而返回本地擴展的具體的實現函數。 • FREContext也會提供⼀一些與app相關的API以⽅方便開發 • FREFunction • FREFunction是本地⽅方法的具體實現。FREFunction是⼀一個接⼝口,提供了call⽅方法。 在AS端的ExtensionContext中調⽤用的call⽅方法都會對應到具體的FREFunction的call⽅方 法。 • FREContext的getFunctions函數會返回⼀一個Map,其key為⼀一個⾃自定義的String, value是具體的FREFunction。 • 通過getFunction⽅方法。AIR Runtime通過getFunction將AS端的call(key,args)⽅方法和java 端具體的FREFunctions的call(args)⽅方法進⾏行對應。
  • 8.
  • 9. 準備⼯工作 • 開始之前確保以下軟體都已經安裝 • Flash Builder 4.6 • AIR SDK 3 • Flex SDK 4.6 • 原⽣生語⾔言⽅方所需的Extensions • Android:FlashRuntimeExtensions.jar
 位置:${FB_HOME}sdks4.6.0libandroidFlashRuntimeExtensions.jar • iOS:FlashRuntimeExtensions.h
 位置:${FB_HOME}sdks4.6.0includeFlashRuntimeExtensions.h
  • 18. IOS的部份 • 開啟⼀一個CocoaTouch Static Library的專案 ! ! ! ! ! ! ! ! • 將FlashRuntimeExtensions.h拉⼊入專案中
  • 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/flash-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