By on October 27, 2011

CPU optimization tips for the Adobe Flash Platform

Optimizing Performance for the Adobe Flash Platform contains a treasure trove of tips on less obvious performance enhancements. For example, chapter 3, “Minimizing CPU usage”, highlights the following CPU management features:

  • Pause and resume SWF files based on screen exposure: This is an automatic feature in Flash Player since version 10.1. Flash Player minimizes processing when SWF content goes off-screen.
  • Instance management: This feature introduced the hasPriority HTML parameter. By default, Flash Player doesn’t start SWF content that is not visible. You can override this behavior in most cases by using the hasPriority parameter.
  • Sleep mode: On mobile devices, Flash Player and AIR detect when the device backlight goes into sleep mode. When this event occurs, rendering of SWF content stops, and frame rates drop to 4fps. Because the frame rate stays above zero, all open data connections can remain open.
  • Freezing and unfreezing objects: You can use REMOVED_FROM_STAGE and ADDED_TO_STAGE events to keep objects that are no longer in the display list from consuming unnecessary CPU cycles.
  • Activate and deactivate events: By using events to detect when your application is activated or deactivated, you can reset the frame rate, freeze or unfreeze objects, or perform other CPU optimizations.
  • Mouse interactions: Detecting mouse interaction on many objects simultaneously can be CPU-intensive. You can reduce that overhead by disabling mouse interactions on objects that do not respond to mouse events.
  • Timers versus ENTER_FRAME events: To execute code at specific intervals you can choose between a timer or ENTER_FRAME events. The optimal choice for your situation depends on a number of factors, such as whether your application uses animation.
  • Tweening syndrome: Minimize the use of tweens, especially for content intended for low-performance mobile devices.

Visit the Optimization Guide to find out more about these topics and many others, including memory management, efficient use of the ActionScript language, rendering, networking, and database access.

1:48 PM Comments (0) Permalink
By on October 21, 2011

Using Flash Builder 4.5.1 to compile an AIR App that uses a native extension

To use a native extension in an AIR application, you have these three tasks to do:

  1. Declare the extension in your application descriptor file.
  2. Include the ANE file in your application’s library path.
  3. Package the application.

This post is about Step 2 with regard to Flash Builder 4.5.1 projects.

Native extensions are packaged in ANE files. To compile an AIR application that uses a native extension, include the ANE file in the Flash Builder project’s build path.

In Flash Builder 4.5.1, do the following steps:

  1. Change the filename extension of the ANE file from .ane to .swc.
  2. Select Project > Properties on your Flash Builder project.
  3. Select the Flex Build Path in the Properties dialog box.
  4. In the Library Path tab, select Add SWC….
  5. Browse to the SWC file and select Open.
  6. Select OK in the Add SWC… dialog box. The ANE file now appears in the Library Path tab in the Properties dialog box.
  7. Expand the SWC file entry. Double-click Link Type to open the Library Path Item Options dialog box.
  8. In the Library Path Item Options dialog box, change the Link Type to External.

Now you can compile your application using, for example, Project > Build Project.

The part about changing the ANE file’s file extension from .ane to .swc is not strictly necessary. In step 4 above, when you browse to find the file, in the “Choose a SWC file” dialog box, you can change the setting of the Files Of Type drop-down field. It is set by default to *.swc.  Change it to *.*.

Now you can choose the ANE file. Then, continue with step 5 above.

However, when you build your Flash Builder 4.5.1 project with an ANE file rather than a SWC file, you get compiler warnings. The first warning is on the import statement for the extension class, saying that the extension could not be found. Successive warnings occur when you use the extension’s classes.

But interestingly, the application still builds and runs successfully.

Note: Adobe recommends using the next version of Flash Builder for developing native extensions for Adobe AIR. Sign up now to get access to the prerelease of Flash Builder 4.6.

For more information about using a native extension in your AIR application, see Using native extensions in AIR applications.

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

12:31 PM Comments (1) Permalink
By on October 20, 2011

Starling example hints

Problems building and debugging the Starling example on Adobe Developer Connection? This blog posting might help.

11:00 AM Comments (0) Permalink
By on

Looking for ActionScript examples? Try this

There are tons of awesome code snippets and examples in the ActionScript Reference and ActionScript Developer guide. Learn about the enhancements we’re working to make it easier to find examples: http://e-musings.tumblr.com/post/11670105969/looking-for-actionscript-examples-try-this

10:32 AM Comments (0) Permalink
By on October 14, 2011

Native extensions: When to call FREContext instance methods

Here’s a little tidbit about developing native extensions for Adobe AIR for Android devices using the native extension Java API.

The main point: The call that your extension’s ActionScript side makes to ExtensionContext.createExtensionContext()  must return before the native side of the extension can call methods of the instance of your class that extends the  FREContext class.

Let’s break that down.

The AIR runtime instantiates your FREExtension instance the first time the  ActionScript side of your extension calls ExtensionContext.createExtensionContext().

The sequence of calls to your Java implementation of the FREExtension class is:

  • FREExtension implementation class constructor
  • initialize()
  • createContext()

In createContext(), you return an instance of your class that extends the FREContext class.

But be careful. The FREContext object can only be considered fully constructed once the ExtensionContext.createExtensionContext() ActionScript method has returned.

Therefore, do not call any methods of your FREContext instance until after the ExtensionContext.createExtensionContext() ActionScript method has returned.

For example, you might be tempted to call your FREContext instance’s getActivity() method in its constructor. Don’t do it. You’ll get an IllegalStateException if you do.

Instead:

  • Provide an initialization method that the ActionScript side can call after ExtensionContext.createExtensionContext() returns.
  • In the initialization method, call your FREContext instance’s getActivity() method.

The Gyroscope and Vibration examples do exactly that. See them at http://www.adobe.com/devnet/air/native-extensions-for-air.html.

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

To use a native extension in your AIR application, see Using native extensions in AIR applications.

10:26 AM Comments (0) Permalink
By on October 12, 2011

Pen tablet native extension example

Sean Fujiwara recently posted a native extension for Adobe AIR at AIR 3 Native Extension Example – PenTablet.

This extension lets an AIR application get the pressure sensitivity data from a Wacom Intuos 4 pen tablet on Windows 7.  It’s a good example of a Windows native extension that handles Windows messages and uses a native library — in this case, the pen tablet’s library.

Sean also provided another native extension for Windows that encodes a bitmap into BMP, JPEG, or PNG format using Microsoft .NET Framework 4.  See  AIR 3 Native Extension Example – ImageProcessor.

You can see more examples and tutorials of native extensions at the Adobe Developer Connection page http://www.adobe.com/devnet/air/native-extensions-for-air.html

Detailed documentation about creating extensions is at Developing native extensions for Adobe AIR.

To use a native extension in your AIR application, see Using native extensions in AIR applications.

2:46 PM Comments (0) Permalink
By on October 10, 2011

Native JSON API released

The Flash Player 11/AIR 3.0 (Serrano) release fulfills a long-standing developer request by introducing a native ActionScript JSON API. With this API, you can import and export objects using JSON encoding. Native JSON functionality correlates closely with the ECMA-262 (5.1 Edition) specification for JSON. Because of this, its syntax is somewhat different from the third-party as3corelib JSON library. You can find out more about these differences in community member Todd Anderson’s blog posting at the Infrared5 company blog.

The API itself consists of a top-level class named JSON. This class provides two methods: stringify() for encoding, and parse() for decoding JSON strings. The JSON feature also supports toJSON() member functions in any class. Visit the official documentation at these locations:

ActionScript 3.0 Reference
ActionScript 3.0 Developer’s Guide

2:42 PM Comments (0) Permalink
By on October 4, 2011

Native extension detailed documentation

With the announcement of AIR 3 and its new native extension feature, detailed documentation about using Native Extensions for Adobe AIR is available now at:

Developing native extensions for Adobe AIR

You’ll find:

- Overview and conceptual information

- How to use the C and Java native extension APIs, plus reference pages

- How to package your native extension using ADT

- Details on the Extension Descriptor file

- Information on using Android shared libraries, and using resources on Android and iOS

If you are using a native extension in your AIR application, see:

Using native extensions in AIR applications

For lots of examples and tutorials, see this Adobe Developer Connection page:

http://www.adobe.com/devnet/air/native-extensions-for-air.htm

 

 

10:16 AM Comments (0) Permalink
By on September 30, 2011

Putting the “Community” in community content

Over the past year we’ve been out in the community listening to issues and gathering content. The results of our labors have been  links and code samples added to our help pages. While we feel this makes our content more dynamic, it doesn’t do much unless you know it there. So, in an effort to get  more eyes on all this great community content, we’re spicing up our pages in a couple of ways:

In the spirit of giving credit where credit is due, here’s a list of some of authors we’ve highlighted so far:
If you have a great tutorials, videos or code sample you want to share, send it along. We’d love to add it to our content so everyone can benefit from your expertise.
1:17 PM Comments (0) Permalink
By on September 22, 2011

iBattery native extension for Adobe AIR

Todd Anderson just posted “iBattery”,  a great example of a native extension for Adobe AIR on his blog.

His iBattery extension allows an AIR application to get the status of the battery of an iOS device — from ActionScript. Todd also gives a nice tutorial highlighting some of the details that go into creating a native extension.

You can see more examples of native extensions at the Adobe Developer Connection page http://www.adobe.com/devnet/air/native-extensions-for-air.html

7:36 AM Comments (0) Permalink