P. 1
Optimizing Performance for the ADOBE FLASH PLATFORM

Optimizing Performance for the ADOBE FLASH PLATFORM

|Views: 547|Likes:
Published by Natasya Hopkins

More info:

Published by: Natasya Hopkins on May 09, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

05/09/2011

pdf

text

original

Divide your application into multiple SWF files.

Mobile devices can have limited access to the network. To load your content quickly, divide your application into
multiple SWF files. Try to reuse code logic and assets through the entire application. For example, consider an
application that has been divided into multiple SWF files, as shown in the following diagram:

Bufer

Playhead

Bufer

Playhead

Bufer

Playhead

74

OPTIMIZING PERFORMANCE FOR THE FLASH PLATFORM

Optimizing network interaction

Last updated 6/23/2010

Application divided into multiple SWF files

In this example, each SWF file contains its own copy of the same bitmap. This duplication can be avoided by using a
runtime shared library, as the following diagram illustrates:

Using a runtime shared library

Using this technique, a runtime shared library is loaded to make the bitmap available to the other SWF files. The
ApplicationDomain class stores all class definitions that have been loaded, and makes them available at runtime
through the getDefinition() method.

A runtime shared library can also contain all the code logic. The entire application can be updated at runtime without
recompiling. The following code loads a runtime shared library and extracts the definition contained in the SWF file
at runtime. This technique can be used with fonts, bitmaps, sounds, or any ActionScript class:

portfolio.swf

10KB

10KB

infos.swf

10KB

main.swf

Total size 40KB

preload.swf

10KB

contact.swf

portfolio.swf infos.swf

main.swf

Total size 10KB

preload.swf

10KB

library.swf

contact.swf

75

OPTIMIZING PERFORMANCE FOR THE FLASH PLATFORM

Optimizing network interaction

Last updated 6/23/2010

// Create a Loader object

var loader:Loader = new Loader();

// Listen to the Event.COMPLETE event

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingComplete );

// Load the SWF file

loader.load(new URLRequest("library.swf") );

var classDefinition:String = "Logo";

function loadingComplete(e:Event ):void

{

var objectLoaderInfo:LoaderInfo = LoaderInfo ( e.target );

// Get a reference to the loaded SWF file application domain

var appDomain:ApplicationDomain = objectLoaderInfo.applicationDomain;

// Check whether the definition is available

if ( appDomain.hasDefinition(classDefinition) )

{

// Extract definition

var importLogo:Class = Class ( appDomain.getDefinition(classDefinition) );

// Instantiate logo

var instanceLogo:BitmapData = new importLogo(0,0);

// Add it to the display list

addChild ( new Bitmap ( instanceLogo ) );

} else trace ("The class definition " + classDefinition + " is not available.");

}

Getting the definition can be made easier by loading the class definitions in the loading SWF file’s application domain:

76

OPTIMIZING PERFORMANCE FOR THE FLASH PLATFORM

Optimizing network interaction

Last updated 6/23/2010

// Create a Loader object

var loader:Loader = new Loader();

// Listen to the Event.COMPLETE event

loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, loadingComplete );

// Load the SWF file

loader.load ( new URLRequest ("rsl.swf"), new LoaderContext ( false,

ApplicationDomain.currentDomain) );

var classDefinition:String = "Logo";

function loadingComplete ( e:Event ):void

{

var objectLoaderInfo:LoaderInfo = LoaderInfo ( e.target );

// Get a reference to the current SWF file application domain

var appDomain:ApplicationDomain = ApplicationDomain.currentDomain;

// Check whether the definition is available

if (appDomain.hasDefinition( classDefinition ) )

{

// Extract definition

var importLogo:Class = Class ( appDomain.getDefinition(classDefinition) );

// Instantiate it

var instanceLogo:BitmapData = new importLogo(0,0);

// Add it to the display list

addChild ( new Bitmap ( instanceLogo ) );

} else trace ("The class definition " + classDefinition + " is not available.");

}

Now the classes available in the loaded SWF file can be used by calling the getDefinition() method on the current
application domain. You can also access the classes by calling the getDefinitionByName() method. This technique
saves bandwidth by loading fonts and large assets only once. Assets are never exported in any other SWF files. The only
limitation is that the application has to be tested and run through the loader.swf file. This file loads the assets first, and
then loads the different SWF files that compose the application.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->