A native extension often targets multiple platforms. For
example, an extension can target devices running iOS and devices
running Android. In this case, your ActionScript class implementation
and your native code implementation, including the native code language,
can vary based on the target platform.
A best practice is for your ActionScript extension classes to
provide the same ActionScript public interfaces regardless of their
implementation. By keeping the public interfaces the same, you have
a true cross-platform native extension. If the ActionScript public
interfaces are the same, but the ActionScript implementation is
different, you create a different ActionScript library for each
platform.
You can also create extensions that do not have a native code
implementation for some target platforms. Such an extension is useful
in the following situations:
-
When only some target platforms support a native implementation
of the desired functionality.
An extension can use a native
implementation on those platforms, but use an ActionScript-only
implementation on other platforms. For example, consider one platform
that provides a specialized mechanism for communication between
computer processes. The extension for that platform has a native implementation.
The same extension for another platform is ActionScript-only, using
ActionScript Socket classes.
When application developers use
the extension, they can write one application without knowing how
the extension is implemented on the different target platforms.
-
When testing an extension.
Consider a native extension
that uses a specific feature of a mobile device. You can create
an ActionScript-only extension for the desktop. Then, an application
developer can use the desktop extension for simulation testing during development
before testing on the real target device. Similarly, as an extension
developer, you can test the ActionScript side of your extension before
involving your native code implementation.
When you publish an extension, you specify the target platforms
in an extension descriptor file in a
<platform>
element.
Each
<platform>
element names a target, such
as
iPhone-ARM
or
Windows-x86.
You
can also specify a
<platform>
element named
default
.
The
default
platform has an ActionScript-only implementation
to use on all platforms not specified with a
<platform>
element.
For more information, see
Native extension descriptor files
.
Note:
The implementation for at least one targeted platform must
contain native code. If no targeted platforms require native code,
then using native extensions is not the correct choice. In such
cases, create a SWC library.