Local permanent data storage (Flash Lite shared object)

Source: Internet
Author: User
Tags hasownproperty
Sharedobject
Object 
|
+-SharedObject

public dynamic class SharedObject
extends Object

The sharedobject Flash Lite version allows the Flash SWF file to save data to the device when it is disabled, and then load the data from the device during playback. The Flash Lite shared object stores a group of name/value pairs in the device.

Note:The name "Export dobject" is derived from the flash export dobject class. The Flash version of this class allows multiple Flash SWF files to share their stored data. However, the mongodobject Flash Lite version does not support data sharing between different Flash SWF files.

In Flash Lite, if the original version of the SWF file is modified, the file will be treated as different versions even if the file name remains unchanged. This is different from Flash Player. in Flash Player, even if the SWF file is modified, the file will be treated as the same version as long as the URL and name of the file remain unchanged. In Flash Lite, SWF files of different versions cannot access shared objects.

In order to maintain the consistency of the Flash Platform, the construction and call conventions of ActionScript are also applicable to Flash Lite players.

The following example illustrates the possibility of using shared objects:

  • A flash application can be used as a service user interface, which allows users to search for a second-hand car list. The application connects to the server that provides the used car list based on the search term and preference entered by the user. The Flash application can save the last search performed by the user and pre-fill the form when the SWF file is played the next time. Therefore, you need to create a mongodobject instance that stores search parameters each time you perform a new search. When the SWF file is disabled, the player saves the data in the shared object to the device. When you play the SWF file again, The Flash Lite player loads the shared object and prefill the search form with the same search data that you entered last time.

  • A flash application can be used as a service user interface, which allows users to search for music comments. This application allows users to store information about their favorite albums. This information can be stored on the remote server, but if the application cannot connect to the service, the problem may occur. In addition, retrieving data from remote services may be slow and may impede user experience. The shared object allows the application to store information about a specific set to a device and quickly load the information as needed.

Note:Due to limited space on mobile devices, data is not completely permanent. In some cases, the platform may delete the earliest data from the device.

To create a local shared object, use the following syntax:

var so:shared object = shared object.getLocal("mySharedObject");

Reading and writing data on a mobile phone may be slow. Flash Lite 2.0 requires you to set a listener to ensure that the application can obtain the data immediately when requesting data from the device. When the device loads the data of the shared object, the player calls the listener. Access the mongodobject instanceGetlocal ()The method should wait until the listener is called and then try to perform any operation.


Availability

Flashing Lite 2.0


Example

In the following example, the SWF file creates a file namedPrefsAnd then create a shared object. When data is available, the player callsLoadcompleteprefsFunction.

function loadCompletePrefs (mySO:SharedObject) { 
if (0 == mySO.getSize() )
{
// If the size is 0, we need to initialize the data:
mySO.data.name = "Sigismund";
mySO.data.email = "siggy@macromedia.com";
}
else
{
// Trace all the data in mySO:
trace( "Prefs:" );
for (var idx in mySO.data) {
trace( " " + idx +": " + mySO.data[idx] );
}
}
}

SharedObject.addListener( "Prefs", loadCompletePrefs );

// We can now create the shared object:
var Prefs:SharedObject = SharedObject.getLocal("Prefs");

After the player sends a notification of data availability to the listener, the application can useGetlocal ()The shared object returned by a method call. Applications can add, modify, or delete properties during playback. After the content is detached, the shared object may be written to the device. However, to ensure that the shared object is written to the device, the application must callFlush ()Method.

The Flash Lite shared object is only applicable to SWF files stored locally. Flash Lite shared objects cannot be used for SWF files played back in browsers that support networks.

The total storage capacity of the Flash Lite shared object for each SWF file is limited by the device and cannot exceed the predefined size. You can useExport dobject. getmaxsize ()Method to Determine the size.

Note:Remote shared objects are not supported in Flash Lite 2.0.


See

Flush (export dobject. Flush method),Onstatus (handler dobject. onstatus handler)


Attribute Summary

Modifier

Attribute

Description

 

Data:Object

TheDataAttribute Set.

Attributes inherited from the object class

Constructor (object. constructor attribute),_ PROTO _ (object. _ PROTO _ attribute),Prototype (object. Prototype attribute),_ Resolve (object. _ resolve attribute)


Event Summary

Event

Description

Onstatus= Function (infoobject:Object){}

It is called every time an error, warning, or information notification is published for a shared object.


Method Summary

Modifier

Signature

Description

Static

Addlistener(Objectname:String, Policyfunction:Function): Void

Create an event listener that is called when the Flash Lite player loads shared object data from the device.

 

Clear(): Void

Clear all data in the shared object and delete the shared object from the disk.

 

Flush(Mindiskspace:Number):Object

Write the shared object to a local permanent file.

Static

Getlocal(Name:String):Sharedobject

Returns a reference to a local permanently shared object. This object can only be used on the current client.

Static

Getmaxsize():Number

Returns the total number of bytes that a SWF file can use to store a shared object on a device.

 

Getsize():Number

Obtains the current size of the shared object (in bytes ).

Static

Removelistener(Objectname:String)

Delete and useAddlistener ()Method to add any listener.

Methods inherited from object classes

Addproperty (object. addproperty method),Hasownproperty (object. hasownproperty method),Ispropertyenumerable (object. ispropertyenumerable method)Isprototypeof (object. isprototypeof method),Registerclass (object. registerclass method),Tostring (object. tostring method)Unwatch (object. unwatch method),Valueof (object. valueof method),Watch (object. Watch method)

 

 

  • Addlistener (mongodobject. addlistener method)
  • Clear (export dobject. Clear method)
  • Data (export dobject. Data Attribute)
  • Flush (export dobject. Flush method)
  • Getlocal (using dobject. getlocal method)
  • Getmaxsize (export dobject. getmaxsize method)
  • Getsize (using dobject. getsize method)
  • Onstatus (handler dobject. onstatus handler)
  • Removelistener (method dobject. removelistener)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.