YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

YUI Library Examples: SWFStore Utility: SWFStore Settings Example

SWFStore Utility: SWFStore Settings Example

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:

This example shows what can happen if storage capacity is exceeded, and how to deal with it effectively. By default, you're allowed 100k per domain. If a larger amount of data is attempted to be stored, an exception will occur. This shows how to deal with that exception and how to enable more storage.

Setting up the Example

The first step is to instantiate a SWFStore and set up listeners, once the page is ready. We also disable all of the Buttons at first.

Once SWFStore is ready, it will dispatch a contentReady event. We can then enable the Buttons.

Exceeding Storage Capacity

Unless the user has disabled storage altogether, or set it below the default, you will generally have 100kb per domain. If you expect that you'll need additional storage, you should call the setSize method in advance, passing in an amount greater than you expect to use. Don't worry about requesting too much, as it's only an allotted amount and no hard drive space will be taken up until it's filled with data. Plus, Flash Player is set up to round off values -- 0kb, 10kb, 100kb, 1mb, 10mb, and unlimited. For instance, if you expect to store no more than 300kb, you might as well ask for more as Flash Player's request dialog will actually ask for 1mb.

If the storage amount requested exceeds what is currently set as the maximum available storage, whether through calling setSize(amount) or by attempting to store an item that is larger than the available space, a quotaExceededError is dispatched and the item will not save. Flash Player will attempt to display a dialog requesting additional storage. However, since the SWF we've embedded is 0px x 0px, the dialog has insufficient space to display. We can detect this in advance via swfstore.hasAdequateDimensions(). The SWF itself will therefore detect whether it's large enough--if not, we can then simply resize the SWF's container and try again. Here we've done just that, using the Animation utility to make the resize more apparent. We check the size of the SWF first, and if it's not large enough we resize it and tell the Animation utility to call the function again once the resize is complete. This is necessary because the dialogs will not render if the SWF is too small--thus you cannot simply resize after invoking the dialog, you must check the SWF's dimensions in advance.

The settings panel can also be invoked manually. You can try this in this example by clicking the Display Settings button and adjusting the slider in the dialog that displays--or even turn off storage altogether. This is accomplished in code by calling swfstore.displaySettings(). Here we've done so in the showSettings function below. Again we've used the Animation utility to resize the SWF if necessary. It is set up to call showSettings() again once it's finished its animation, thereby ensuring display of the dialog. Note that the required space for these SWF dialogs is 215px wide by 138px high, but it's better to set it a bit higher due to CSS padding or other factors which may decrease its true dimensions. 300x300 is a nice starting point.

Avoiding the Problem Altogether

If you try storing a larger amount of data than the allotted storage available, such as trying to store the full text of Shakespeare's Hamlet, about 180kb, in the default 100kb of space, the save will fail as I've mentioned. Try copying and pasting that text and saving. A way to increase the amount of data you can store without requiring the dialogs is by compressing your data. This is accomplished via the useCompression parameter of SWFStore (off by default). Try turning on compression by clicking the Use Compression button. This should compress the 180kb down to about 70kb, and it should save properly. Be sure to purge out the data when you're done to avoid taking up precious hard drive space.

More SWFStore Utility Resources:

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings