flash language_api_best_practices

Best practices

Throughout these articles we use best practices:

We systematically type variables in order to optimize performances of our applications and to guarantee a better management of compilation errors.

Upon definition of loops we always use a reference variable in order to avoid the virtual machine reevaluating the length of the array on each iteration.

We prefer the following code:

var arrayData:Array = [ 5654, 95, 54, 687968, 97851];
// stocking the length of a array
var lng:int = arrayData.length;
for ( var i:int = 0; i< lng; i++ )
{
}

To this non-optimised code:

var arrayData:Array = [ 5654, 95, 54, 687968, 97851];
for ( var i:int = 0; i< arrayData.length; i++ )
{
}

We also avoid redefining our variables in loops.

We prefer the following code:

var arrayData:Array = [5654, 95, 54, 687968, 97851];
var lng:int = arrayData.length;
// declaration of the currentElement variable once only
var currentElement:int;
for ( var i:int = 0; i< lng; i++ )
{
currentElement = arrayData[i];
}

To the non-optimised version:

var arrayData:Array = [5654, 95, 54, 687968, 97851];
for ( var i:int = 0; i< arrayData.length; i++ )
{
// declaration of the currentElement variable on each iteration
var currentElement:int = arrayData[i];
}

Let’s now discover some more subtleties of ActionScript 3.








Adobe Training center


Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42