03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

■ A Flash application can be used as a user interface for a service that allows users to search<br />

for music reviews. The application lets users store information about their favorite<br />

albums. The information can be stored on the remote server, but this causes problems if<br />

the application cannot connect to the service. Also, retrieving the data from a remote<br />

service can be slow <strong>and</strong> detract from the user experience. Shared objects enable the<br />

application to store information about the albums to the device <strong>and</strong> load it quickly when<br />

needed.<br />

Note: Because space is limited on mobile devices, the data is not completely persistent; in<br />

some situations, the platform could delete the oldest data from the device.<br />

To create a local shared object, use the following syntax:<br />

var so:shared object = shared object.getLocal("mySharedObject");<br />

Reading <strong>and</strong> writing data on a h<strong>and</strong>set can be slow. To ensure that data is immediately<br />

available when the application requests it from the device, Flash Lite 2.0 requires you to set up<br />

a listener. The player invokes the listener when the device has loaded the shared object's data.<br />

Methods that access the SharedObject instance returned by the call to getLocal() should<br />

wait until the listener is invoked before attempting any operations.<br />

Example<br />

In the following example, a SWF file creates a listener function named Prefs <strong>and</strong> then creates<br />

a shared object. The player calls the loadCompletePrefs function when the data is available.<br />

function loadCompletePrefs (mySO:SharedObject) {<br />

if (0 == mySO.getSize() )<br />

{<br />

// If the size is 0, we need to initialize the data:<br />

mySO.data.name = "Sigismund";<br />

mySO.data.email = "siggy@macromedia.com";<br />

}<br />

else<br />

{<br />

// Trace all the data in mySO:<br />

trace( "Prefs:" );<br />

for (var idx in mySO.data) {<br />

trace( " " + idx +": " + mySO.data[idx] );<br />

}<br />

}<br />

}<br />

SharedObject.addListener( "Prefs", loadCompletePrefs );<br />

// We can now create the shared object:<br />

var Prefs:SharedObject = SharedObject.getLocal("Prefs");<br />

552 ActionScript classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!