By on November 7, 2011

New Flash Runtimes gaming blog: for neophytes (and willing mentors)

Are you new to game development? Struggling to find your footing in the ActionScript game development world? So am I. Although ActionScript and programming are not new to me, game development and gaming in general are. In my blog I’ll be exploring how to get a game going, what kinds of existing games are out there, cutting edge technologies, and how various technologies work together towards a great gaming experience.

Come along for the ride, and please share your experiences and insights! http://actionscriptandotherthings.wordpress.com/

2:21 PM Comments (0) Permalink
By on

SWC and SWF files in native extensions

I’d like to highlight the role of your ActionScript library — a SWC file — in native extensions. And while I’m at it, I’d like to discuss the role of  the SWF files that the SWC file contains.

You’ve read it before: A native extension is made of two parts: The ActionScript side and the native code side. Here we are just talking about the ActionScript side.

You build the ActionScript side of your extension into an ActionScript library that is a SWC file. The SWC file is an archive file (think ZIP file) that contains your ActionScript classes and other resources, such as its images and strings.

Suppose your extension targets different platforms — for example, both iOS and Android. If  your extension requires a different ActionScript implementation for each platform, create a different SWC file for each platform. A best practice  is that all the ActionScript implementations have the same public interfaces. However, even if all the ActionScript implementations have the same public interfaces, what happens inside the implementation can vary by platform. If so,  you’ll have to create multiple SWC files.

The SWC file comes into play when you package your extension into an ANE file. To do the packaging, you use the ADT command-line tool. You specify a SWC file in the -swc option of the ADT packaging command. For example:

adt -package <signing options> -target ane MyExtension.ane MyExt.xml
    -swc MyExtension.swc
    -platform Android-ARM -C platform/Android .
    -platform iPhone-ARM -C platform/ios .
    -platform default -C platform/default library.swf

The SWC file contains a file called library.swf.  It is the main SWF file of your ActionScript library. ADT automatically puts the library.swf from the SWC file into the ANE file. When an AIR
application uses a native extension, it includes the extension’s ANE file in its library path so that the application can compile. In fact, the application compiles against the public interfaces in library.swf.

Let’s say, as discussed above, you have different SWC files for each platform, but they all share the same public interfaces. In this case, it doesn’t matter which of the platform-specific SWC files you use in the -swc option of the ADT command. It doesn’t matter because the library.swf file in the SWC file is used only for application compilation.

Application execution is another matter. Take a look again at the above ADT command.  Each platform directory (platform/android, platform/ios, and platform/default in this example) specifies the files to include in the ANE package. The -C option tells ADT to make the specified directory the current directory. ADT puts the files and directories that follow into the ANE package. Each platform directory has a library.swf file in it.  For the iOS and Android platform directories, the ‘.’ indicates that all the files in the current directory are to be packaged into the ANE. The files include the library.swf as well as native libraries.

Therefore, you must put the appropriate library.swf into each platform directory. When you have a different SWC file for each platform, get the library.swf from the appropriate SWC file. You can extract the library.swf from a SWC file with extraction tools such as WinZip.  When the application executes and calls your extension class, this is the library.swf file that runs.

Note the following about the library.swf file:

  • ADT requires that you provide a main SWF file named library.swf for each platform. When you create a SWC file, library.swf is the name of the main SWF file.
  • The library.swf file for each platform is different if your ActionScript side has platform dependencies.
  • The library.swf file for each platform is the same if the ActionScript side has no platform dependencies.
  • The library.swf for each platform can load other SWF files that you include in the platform-specific directory. These other SWF files can have any name.

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

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

Jackie Levy, Content and Community Lead

8:56 AM Comments (0) Permalink
By on November 4, 2011

Putting the Community in community help

Check out all the great new links we’ve added to community help: http://tmblr.co/Z8MtrwBUsOmL

2:44 PM Comments (0) Permalink
By on

Optimizing your application with object pooling

As applications grow in size and complexity, the number of objects you use increases rapidly. Instantiation can be expensive. Even with the new GC advice API in Flash Player 11 and AIR 3, garbage collection can slow down or pause your application.  One technique you can use to improve performance by decreasing the number of objects in your application and reducing how often garbage collection runs is object pooling.  With object pooling, you create objects during the initialization of your application, store them in a pool, and keep reusing them.

Look at an example of object pooling in Optimizing Performance for the Flash Platform. You can also read about garbage collection and the new GC advice API in Garbage collection internals for Flash Player and Adobe AIR.

12:33 PM Comments (0) Permalink
By on October 28, 2011

Examples, examples, and more examples

When we ask ActionScript developers what they want from the Flash Platform documentation team, their consistent answer is: more examples. There is no such thing as enough when it comes to code examples that developers can use to learn the language, solve specific problems, and share ideas with others who are working on similar applications.

The secret: our existing ActionScript 3 documentation actually HAS a decent range of examples. The problem is that these examples are somewhat well hidden. To solve this problem, we’ve analyzed pathing info (provided by Adobe’s Omniture acquisition) that tells us what users are searching for, where they are looking, and how we can help them find what they need.

The ActionScript 3 Developer’s Guide‘s appendix (How to use ActionScript examples) explains how to work with different types of  examples. Until recently, this appendix did not make it easy to find the ZIP file that contains the example source, never mind explanations of the functionality that each example demonstrates. Here is a link to the examples ZIP, followed by a list of examples and their explanations. Let us know what you’d like to see added to the list.

Example ZIP file: Flash Professional CS5 and Flex 4 samples

List of examples:

11:32 PM Comments (2) Permalink
By on

New to AIR Native Extensions?

Looking to get started using Native extension? Here’s a quick primer with links to more resources. What the heck are AIR Native Extensions?

11:23 AM Comments (0) Permalink
By on

Optimizing network interaction in mobile applications

Optimizing Performance for the Flash Platform is filled with tips to make faster, more efficient Flash Player and AIR applications for desktop, mobile, and TV devices.

The chapter called Optimizing network interaction has some tips worth reviewing:

  • Use smart seeking.  Smart seeking improves performance when a user seeks to a new destination in a streaming video. Use Netstream.inBufferSeek.  (Adobe Flash Media Server 3.5.3 or greater required)
  • Divide your app into multiple SWF files. Multiple smaller SWF files means your content loads faster, especially on mobile devices with limited access to the network.
  • Provide event handlers and error messages for IO errors. Because network access can be less reliable on a mobile device, be sure to catch every IO error and keep the user informed.
  • Use Flash Remoting and AMF for optimized client-server data communication. As a binary format, Action Message Format (AMF) reduces the size of the data, improving the speed of transmission. Flash Remoting gateways, such as  ZendAMF, FluorineFX, WebORB, and BlazeDS, know how to handle the AMF format on behalf of the server side.
  • Cache assets locally after loading them. Avoid unnecessary loads from the network by saving files to the local file system, by using SharedObjects, or by saving data to a local database.

For more details on these tips, and other topics such as conserving memory and improving rendering performance, visit Optimizing Performance for the Flash Platform.

Jackie Levy, Content and Community Lead

9:12 AM Comments (0) Permalink
By on October 27, 2011

Optimizing Flash and AIR applications for mobile

Looking for ways to build incredibly speedy Flash or AIR applications for mobile devices? If so, look no further than Optimizing Performance for the Flash Platform. Released last year, this guide is brimming with valuable tidbits, provided in part by Adobe’s own Thibault Imbert. It offers tips for optimizing performance on mobile devices, desktops and TVs, ranging from basic ActionScript best practices to sophisticated graphics rendering techniques.

Here are a couple of simple ActionScript optimizations from the Miscellaneous optimizations section of the ActionScript 3.0 performance chapter.

Avoid evaluating statements in loops
Another optimization can be achieved by not evaluating a statement inside a loop. The following code iterates over an array, but is not optimized because the array length is evaluated for each iteration:

for (var i:int = 0; i< myArray.length; i++)
{
}

It is better to store the value and reuse it:

var lng:int = myArray.length;
for (var i:int = 0; i< lng; i++)
{
}

Use reverse order for while loops
A while loop in reverse order is faster than a forward loop:

var i:int = myArray.length;
while (--i > -1)
{
}

These tips provide a few ways to optimize ActionScript, showing how a single line of code can affect performance and memory. Many other ActionScript optimizations are possible. For more information,
see http://www.rozengain.com/blog/2007/05/01/some-actionscript-30-optimizations.

8:18 PM Comments (0) Permalink
By on

Configure Flash Builder 4.5 to use Flash Player 11 and AIR 3

I’ve seen several people ask how to set up Flash Builder 4.5 to develop applications that use Flash Player 11 and AIR 3 features. Here are the steps:

  1. Download playerglobal.swc from http://www.adobe.com/support/flashplayer/downloads.html.
  2. Copy it to [Flash Builder 4.5]/sdks/4.5.1/frameworks/libs/player/11.0.
  3. In Flash Builder > Project > Properties > Flex Compiler, set the minimum Flash Player version to 11.
  4. In the Flex Compiler properties, specify an additional compiler argument:
    -swf-version=13

Graeme Bull of FMSGuru.com has created an (always) excellent video tutorial that walks you through the steps:

Setting Up Flash Builder 4.5 for Flash 11 and AIR 3 Apps

 

3:11 PM Comments (1) Permalink
By on

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