Search Flex Components Free

Custom Search

December 27, 2007

Flex Miscellaneous Local Shared Objects Source Code Example:

sharedobjectdemo .mxml


<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundAlpha="0"
horizontalAlign="center"
creationComplete="initApp()">

<mx:Script>

import mx.controls.Alert;
import flash.net.SharedObject;

private var lso:SharedObject;

private function initApp():void {
lso=SharedObject.getLocal("info");
if (lso == null)
{
Alert.show("Cannot create shared object", "Error");
}
else
{
if (lso.data.firstName != null) firstName.text = lso.data.firstName;
if (lso.data.lastName != null) lastName.text = lso.data.lastName;
if (lso.data.email != null) email.text = lso.data.email;
}
}

private function saveInfo():void
{
lso.data.firstName=firstName.text;
lso.data.lastName=lastName.text;
lso.data.email=email.text;
}

</mx:Script>

<mx:Text width="100%" textAlign="center">
<mx:text>
Fill in the form below and click the save button to save the information to the local shared object.
When you reload the application, the form is automatically populated with the data you saved.
</mx:text>
</mx:Text>

<mx:Form>

<mx:FormItem label="First Name">
<mx:TextInput id="firstName" width="200"/>
</mx:FormItem>

<mx:FormItem label="Last Name">
<mx:TextInput id="lastName" width="200"/>
</mx:FormItem>

<mx:FormItem label="Email">
<mx:TextInput id="email" width="200"/>
</mx:FormItem>

</mx:Form>

<mx:HBox>
<mx:Button label="Save to SharedObject" width="150" click="saveInfo()"/>
<mx:Button label="Clear SharedObject" width="150" click="lso.clear()"/>
</mx:HBox>

</mx:Application>

Related Flex Tutorials