Packagecom.myflashlab.air.extensions.ar
Classpublic class AR
InheritanceAR Inheritance Object

AR class is the entry point to use Augmented Reality in your Adobe AIR app. To start an AR experience, you should follow the following steps:

View the examples



Public Properties
 PropertyDefined By
  listener : EventDispatcher
[static] [read-only] This property allows you to listen to different AR events.
AR
Public Methods
 MethodDefined By
  
callJS($data:String):void
[static] Call this method whenever you wish to call a function on the js side.
AR
  
captureScreen($captureMode:Boolean, $savePath:String):void
[static] Use this method to take a screenshot from your AR content.
AR
  
checkFeatureSupport($features:Array, $onResult:Function):void
[static] Call this method to know if the AR features you wish to support in your AR experience is supported on the current device or not.
AR
  
config($config:Config):void
[static] This method lets you set the initial camera configuration for your AR window.
AR
  
endAR():void
[static] Call this method to close the AR window.
AR
  
init($androidKey:String, $iosKey:String):void
[static] This is the first method you must call when starting with the AR ANE.
AR
  
launchAR($arWorldPath:String):void
[static] Use this method to launch the AR window.
AR
Public Constants
 ConstantDefined By
  ANDROID_SDK_VERSION : String = 7.2.1
[static]
AR
  EXTENSION_ID : String = com.myflashlab.air.extensions.ar
[static]
AR
  IOS_SDK_VERSION : String = 7.2.1
[static]
AR
  RESULT_ERROR : int = 0
[static]
AR
  RESULT_OK : int = 1
[static]
AR
  VERSION : String = 2.0.4
[static]
AR
Property Detail
listenerproperty
listener:EventDispatcher  [read-only]

This property allows you to listen to different AR events.


Implementation
    public static function get listener():EventDispatcher
Method Detail
callJS()method
public static function callJS($data:String):void

Call this method whenever you wish to call a function on the js side.

Parameters

$data:String

captureScreen()method 
public static function captureScreen($captureMode:Boolean, $savePath:String):void

Use this method to take a screenshot from your AR content.

Parameters

$captureMode:Boolean
 
$savePath:String

checkFeatureSupport()method 
public static function checkFeatureSupport($features:Array, $onResult:Function):void

Call this method to know if the AR features you wish to support in your AR experience is supported on the current device or not. you must create an array with the features you need and pass them to this method.

Parameters

$features:Array — An array of AR features you want to check their support.
 
$onResult:Function — A function to handle the results. function onCheckResult($status:int, $msg:String):void

config()method 
public static function config($config:Config):void

This method lets you set the initial camera configuration for your AR window. You must call this method before you launch your AR experience.

Parameters

$config:Config

endAR()method 
public static function endAR():void

Call this method to close the AR window.

init()method 
public static function init($androidKey:String, $iosKey:String):void

This is the first method you must call when starting with the AR ANE. Pass in your Android and iOS SDK keys to this method.

Parameters

$androidKey:String
 
$iosKey:String

launchAR()method 
public static function launchAR($arWorldPath:String):void

Use this method to launch the AR window. You can load your AR html/js files from File.applicationDirectory or File.documentsDirectory or even from a url.

Parameters

$arWorldPath:String

Constant Detail
ANDROID_SDK_VERSIONConstant
public static const ANDROID_SDK_VERSION:String = 7.2.1

EXTENSION_IDConstant 
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.ar

IOS_SDK_VERSIONConstant 
public static const IOS_SDK_VERSION:String = 7.2.1

RESULT_ERRORConstant 
public static const RESULT_ERROR:int = 0

RESULT_OKConstant 
public static const RESULT_OK:int = 1

VERSIONConstant 
public static const VERSION:String = 2.0.4

Examples
The following example shows how you can start an AR experience
     import com.myflashlab.air.extensions.ar.*;
      
     AR.init("Wikitude_Android_SDK_key", "Wikitude_iOS_SDK_key");
      
     AR.listener.addEventListener(ArEvents.WORLD_LOAD_RESULT, onWorldLoadResult);
     AR.listener.addEventListener(ArEvents.NATIVE_WINDOW_CLOSED, onArClosed);
     AR.listener.addEventListener(ArEvents.CALIBRATION_NEEDED, onCalibrationNeeded);
     AR.listener.addEventListener(ArEvents.CALIBRATION_DONE, onCalibrationDone);
     AR.listener.addEventListener(ArEvents.JS_TALK, onJsTalk);
     AR.listener.addEventListener(ArEvents.SCREENSHOT_RESULT, onScreenshotresult);
      
     var features:Array = [];
     features.push(Features.GEO);
     features.push(Features.IMAGE_TRACKING);
     features.push(Features.INSTANT_TRACKING);
     features.push(Features.OBJECT_TRACKING);
     AR.checkFeatureSupport(features, onCheckResult);
      
     function onCheckResult($status:int, $msg:String):void
     {
         if($status == AR.RESULT_OK)
         {
             trace("Device supports all requested AR features");
             // now, use the permissionCheck ANE to ask users for camera and gps permissions
             // https://github.com/myflashlab/PermissionCheck-ANE/
             whenPermissionsAreOk();
         }
         else if($status == AR.RESULT_ERROR)
         {
             trace("Device does not support all features: " + $msg);
         }
     }
      
     function whenPermissionsAreOk():void
     {
         var _arSettings:Config = new Config();
         _arSettings.camFocusMode = CameraFocusMode.CONTINUOUS;
         _arSettings.camPosition = CameraPosition.BACK;
         _arSettings.camResolution = CameraResolution.SD_640x480;
          
         // for best performance, you must activated only the AR features which you will use.
         _arSettings.hasGeo = true;
         _arSettings.hasInstant = true;
         _arSettings.hasIR = true;
         _arSettings.hasObject = true;
          
         if(AR.os == AR.ANDROID)
         {
             // Android specific settings
             _arSettings.android.cam2Enabled = false;
             _arSettings.android.fullscreenMode = true;
             _arSettings.android.camFocusDistanceAndroid = 1;
         }
         else if(AR.os == AR.IOS)
         {
             // iOS specific settings
             _arSettings.ios.camFocusDistance = -1.0;
             _arSettings.ios.camFocusRange = FocusRange.NONE;
             _arSettings.ios.framerate = 30;
             _arSettings.ios.excludeBinnedVideo = true;
         }
          
         AR.config(_arSettings);
         AR.launchAR("AR_world/index.html");
     }
      
     function onWorldLoadResult(e:ArEvents):void
     {
         if(e.status == AR.RESULT_OK)
         {
             trace("AR World load succeeded for URL: " + e.url);
         }
         else if(e.status == AR.RESULT_ERROR)
         {
             trace("AR World load failed for URL: " + e.url);
             trace("failed reason: " + e.msg);
         }
     }
      
     function onArClosed(e:ArEvents):void
     {
         trace("AR closed");
     }
      
     function onCalibrationNeeded(e:ArEvents):void
     {
         trace("onCalibrationNeeded");
     }
      
     function onCalibrationDone(e:ArEvents):void
     {
         trace("onCalibrationDone");
     }
      
     function onJsTalk(e:ArEvents):void
     {
         trace("onJsTalk: " + e.msg);
          
         // you may call functions on the js side using the AR.callJS method.
          AR.callJS("remoteJSfunction('value1', 'value2')");
          
         // The best practice is to send a json string from js to AIR
         var obj:Object = JSON.parse(e.msg);
          
         if(obj.action == "close_ar")
         {
             AR.endAR();
         }
         else if(obj.action == "capture_screen")
         {
             AR.captureScreen(
                 Screenshot.CAPTURE_MODE_CAM,
                 "screenshot.png" // relative path to File.applicationStorageDirectory
             );
         }
     }
      
     function onScreenshotresult(e:ArEvents):void
     {
         if(e.status == AR.RESULT_OK)
         {
             trace("screenshot success", e.screenshot.nativePath + " = " + e.screenshot.size);
         }
         else if(e.status == AR.RESULT_ERROR)
         {
             trace("screenshot failed reason: " + e.msg);
         }
     }