Posts in Category "Flash Player"

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/

Putting the Community in community help

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

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.

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.

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

 

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.

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

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.

Adobe Cookbook recipe challenge begins!

Got a tasty tip or technique to offer to the Flash Platform developer community? Want a shot at winning a Samsung 10.1 tablet? If so, head on over to the Adobe Developer Center and learn more about the Adobe Cookbook recipe request challenge: http://adobe.ly/ot8Eoy. Everyone who responds to the challenge by contributing a cookbook recipe gets an Adobe Developer Connection T-shirt, plus a chance to win the tablet. Good luck!

Vector.sort() documentation update

A community member  pointed out recently that the ActionScript Language Reference description for Vector.sort() is incomplete. The reference will be updated soon. In the meantime, here’s the corrected description, which now includes sorting according to a “sort option” as well as sorting by using a compare function.

Vector sort() method:

Sorts the elements in the Vector object, and also returns a sorted Vector object. This method sorts according to the parameter sortBehavior, which is either a function that compares two values, or a set of sorting options.

The method takes one parameter. The parameter is one of the following:

  • a function that takes two arguments of the base type (T) of the Vector and returns a Number:

function compare(x:T, y:T):Number {}

The logic of the function is that, given two elements x and y, the function returns one of the following three values:

  • a negative number, if x should appear before y in the sorted sequence
  • 0, if x equals y
  • a positive number, if x should appear after y in the sorted sequence
  • a number which is a bitwise OR of the following values:
  • 1 or Array.CASEINSENSITIVE
  • 2 or Array.DESCENDING
  • 4 or Array.UNIQUESORT
  • 8 or Array.RETURNINDEXEDARRAY
  • 16 or Array.NUMERIC

If the value is 0, the sort works in the following way:

  • Sorting is case-sensitive (Z precedes a).
  • Sorting is ascending (a precedes b).
  • The array is modified to reflect the sort order; multiple elements that have identical sort fields are placed consecutively in the sorted array in no particular order.
  • All elements, regardless of data type, are sorted as if they were strings, so 100 precedes 99, because “1” is a lower string value than “9”.

Parameters
sortBehavior:* — A Function or a Number value that determines the behavior of the sort. A Function parameter specifies a comparison method. A Number value specifies the sorting options.

Returns
Vector  — A Vector object, with elements in the new order.