This example has been deprecated and will no longer be supported. Please note that the functionality of the SWFStore Utility requires that you host swfstore.swf on your own servers. YUI 2 is now in maintenance mode, so no future updates are planned and only critical fixes will be considered. For more information, please refer to the following blog posts:
Note that in cases where Flash is missing on the user's machine, the content of the Flash container does not get overwritten, and since the container is sized down to 0, additional logic (not demonstrated in this example) would be necessary to inform the user that no Flash is installed.
This example consists of two text fields, a few Buttons and a DataTable. The Buttons allow you to save data, set properties on SWFStore, or clear all items from storage.
Once the page is drawn,
initialize is called to instantiate a SWFStore instance and set up some listeners. We also disable all of the Buttons until the SWFStore is ready.
When SWFStore is ready, it will dispatch a
contentReady event. We can then enable the Buttons and initialize a DataTable with any previously stored values. Because items are stored as objects, we need to loop through them to turn them into name-value pairs suitable for use with the DataTable.
The "Save" Button is set up to take the values from the text fields and store them, using the
setItem method of SWFStore.
Similarly, a couple of other Buttons are set up to remove items from storage, either by name or index, or by clearing the entire local store.
We've already set up a listener for a "save" event, which is dispatched once an item is successfully stored. That calls the
onSave function, which loops through the rows of the DataTable. Using the
info property of the event, we can determine what type of change occurred, and either add rows, delete rows, or update its current values.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.