YUI AS Component Documentation |
Class SWFStore

Package | Top Level
Class | public class SWFStore
Inheritance | SWFStore flash.display.Sprite

A wrapper for Flash SharedObjects to allow them to be used in JavaScript.

Public Properties

| Property | Defined by
--- | --- | ---
|  | MINIMUM_HEIGHT : Number = 138 [static] The minimum height required to be able to display the settings panel within the SWF | SWFStore
|  | MINIMUM_WIDTH : Number = 215 [static] The minimum width required to be able to display the settings panel within the SWF | SWFStore

Public Methods

| Method | Defined by
--- | --- | ---
|  | SWFStore() Creates a store, which can be used to set and get information on a user's local machine. | SWFStore
|  | calculateCurrentSize():uint Gets the amount of space taken by the current store. | SWFStore
|  | clear():Boolean Removes all data in local storage for this domain. | SWFStore
|  | displaySettings():void Displays the settings dialog to allow the user to configure storage settings manually. | SWFStore
|  | getItems():Array Returns the storage object as an Array of name/value pairs. | SWFStore
|  | getLength():int Returns the number of keys in storage. | SWFStore
|  | getModificationDate():Date Gets the timestamp of the last store. | SWFStore
|  | getNameAt(index:int):String Returns the key name in storage, if any, at the specified index. | SWFStore
|  | getPath(path:String):String Expands a path with shorthands to url | SWFStore
|  | getShareData():Boolean Whether or not to data is being shared among different browsers | SWFStore
|  | getTypeAt(index:int):String Returns the data type of of the storage. | SWFStore
|  | getTypeOf(location:String):String Returns the data type of of the storage. | SWFStore
|  | getUseCompression():Boolean Whether or not compression is used | SWFStore
|  | getValueAt(index:int):* Returns the value of the key in local storage, if any, at the specified index. | SWFStore
|  | getValueOf(location:String):* Returns the value of the key in local storage, if any. | SWFStore
|  | hasAdequateDimensions():Boolean Helper function to determine if SWF visible area is large enough to fit the settings panel | SWFStore
|  | removeItem(location:String):Boolean Removes the data in local storage at the specified location, if any. | SWFStore
|  | removeItemAt(index:int):Boolean Removes the data in local storage at the specified location, if any. | SWFStore
|  | setItem(location:String, item:*):Boolean Saves data to local storage. | SWFStore
|  | setShareData(value:Boolean):void Whether or not to share data among different browsers | SWFStore
|  | setSize(value:int):String This method requests more storage if the amount is above the current limit (typically ~100KB). | SWFStore
|  | setUseCompression(value:Boolean):void Whether or not to use compression | SWFStore

Protected Methods

| Method | Defined by
--- | --- | ---
|  | initializeSharedObject():void | SWFStore

Property detail

MINIMUM_HEIGHT | property

`public static var MINIMUM_HEIGHT:Number = 138`

The minimum height required to be able to display the settings panel within the SWF

MINIMUM_WIDTH | property |

`public static var MINIMUM_WIDTH:Number = 215`

The minimum width required to be able to display the settings panel within the SWF

Constructor detail

SWFStore | () | constructor

`public function SWFStore()`

Creates a store, which can be used to set and get information on a user's local machine. This is typically invoked through the YUI JS API.

If multiple SWF files need access to the same store, or if the SWF file that creates a store will later be moved, the value of this parameter affects how accessible the store will be.

For example, if you create a store with localPath set to the default value (the full path to the SWF file), no other SWF file can access that shared object. If you later move the original SWF file to another location, not even that SWF file can access the data already stored.

To avoid inadvertently restricting access to a store, set this parameter. The most permissive approach is to set localPath to `/` (forward slash), which makes the store available to all SWF files in the domain, but increases the likelihood of name conflicts with other stores in the domain. A more restrictive approach is to append localPath with folder names that are in the full path to the SWF file. Note that not just any folder path can be placed here, but only those that are in the path of the SWF. For instance, if the SWF is located at company.com/products/mail/mail.swf, the available options for localPath would be "/products/mail/", "/products/", or "/".

Method detail

calculateCurrentSize | () | method

`public function calculateCurrentSize():uint`

Gets the amount of space taken by the current store. Note that this value is calculated as requested, so large datasets could result in reduced performance.

Returns

| `uint` — the size of the store in KB

clear | () | method |

`public function clear():Boolean`

Removes all data in local storage for this domain.

Be careful when using this method, as it may remove stored information that is used by other applications in this domain

Returns

| `Boolean` — Whether the clear was successful

displaySettings | () | method |

`public function displaySettings():void`

Displays the settings dialog to allow the user to configure storage settings manually. If the SWF height and width are smaller than what is allowable to display the local settings panel, an error message will be sent to JavaScript.

getItems | () | method |

`public function getItems():Array`

Returns the storage object as an Array of name/value pairs.

Returns

| `Array` — The storage dictionary as an Array

getLength | () | method |

`public function getLength():int`

Returns the number of keys in storage.

Returns

| `int` — The number of keys

getModificationDate | () | method |

`public function getModificationDate():Date`

Gets the timestamp of the last store. This value is automatically set when data is stored.

Returns

| `Date` — A Date object

getNameAt | () | method |

`public function getNameAt(index:int):String`

Returns the key name in storage, if any, at the specified index.

Parameters

| `index:int` — The index of the "cookie" or store

Returns

| `String` — The data

getPath | () | method |

`public function getPath(path:String):String`

Expands a path with shorthands to url

Parameters

| `path:String` — Path with shorthands

Returns

| `String` — Path with shorthands expanded

getShareData | () | method |

`public function getShareData():Boolean`

Whether or not to data is being shared among different browsers

Returns

| `Boolean`

getTypeAt | () | method |

`public function getTypeAt(index:int):String`

Returns the data type of of the storage.

Parameters

| `index:int` — The index of the "cookie" or store

Returns

| `String` — The data type.

See also

getTypeOf

getTypeOf | () | method |

`public function getTypeOf(location:String):String`

Returns the data type of of the storage.

May be one of the following types:

- boolean
- function
- number
- object
- string
- number
- xml

Parameters

| `location:String` — The name of the "cookie" or store

Returns

| `String` — The data type.

getUseCompression | () | method |

`public function getUseCompression():Boolean`

Whether or not compression is used

Returns

| `Boolean`

getValueAt | () | method |

`public function getValueAt(index:int):*`

Returns the value of the key in local storage, if any, at the specified index. Corresponds to the key(n) method in the HTML5 spec.

Parameters

| `index:int` — The index of the "cookie" or store

Returns

| `*` — The value stored

getValueOf | () | method |

`public function getValueOf(location:String):*`

Returns the value of the key in local storage, if any. This corresponds to the HTML5 spec getItem(key).

Note: to return an item at a specific index, use the helper function

: `getValueAt(index)` Parameters

| `location:String` — The name of the "cookie" or key

Returns

| `*` — The data

See also

getValueAt

hasAdequateDimensions | () | method |

`public function hasAdequateDimensions():Boolean`

Helper function to determine if SWF visible area is large enough to fit the settings panel

Returns

| `Boolean` — Boolean Whether or not the area is large enough.

initializeSharedObject | () | method |

`protected function initializeSharedObject():void`

removeItem | () | method |

`public function removeItem(location:String):Boolean`

Removes the data in local storage at the specified location, if any.

Parameters

| `location:String` — The name of the "cookie" or store

Returns

| `Boolean` — Whether the remove was successful

removeItemAt | () | method |

`public function removeItemAt(index:int):Boolean`

Removes the data in local storage at the specified location, if any.

Parameters

| `index:int` — The name of the "cookie" or store

Returns

| `Boolean` — Whether the remove was successful

setItem | () | method |

`public function setItem(location:String, item:*):Boolean`

Saves data to local storage. It returns "true" if the storage succeeded; "false" if the user has denied storage on their machine or if the current limit is too low.

The size limit for the passed parameters is ~40Kb.

Parameters

| `location:String` — The data to store
| `item:*` — The name of the "cookie" or store

Returns

| `Boolean` — Boolean Whether or not the save was successful

setShareData | () | method |

`public function setShareData(value:Boolean):void`

Whether or not to share data among different browsers

Parameters

| `value:Boolean`

setSize | () | method |

`public function setSize(value:int):String`

This method requests more storage if the amount is above the current limit (typically ~100KB). The request dialog has to be displayed within the Flash player itself so the SWF it is called from must be visible and at least 215px x 138px in size. Since this is a "per domain" setting, you can use this method on a SWF in a separate page, such as a settings page, if the width/height of the compiled SWF is not large enough to fit this dialog.

Parameters

| `value:int` — The size, in KB

Returns

| `String`

setUseCompression | () | method |

`public function setUseCompression(value:Boolean):void`

Whether or not to use compression

Parameters

| `value:Boolean`