13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Storing local data<br />

package {<br />

import mx.collections.ArrayCollection;<br />

import flash.net.SharedObject;<br />

}<br />

public class LSOHandler {<br />

}<br />

private var mySO:SharedObject;<br />

private var ac:ArrayCollection;<br />

private var lsoType:String;<br />

// The parameter is "feeds" or "sites".<br />

public function LSOHandler(s:String) {<br />

init(s);<br />

}<br />

private function init(s:String):void {<br />

ac = new ArrayCollection();<br />

lsoType = s;<br />

mySO = SharedObject.getLocal(lsoType);<br />

if (getObjects()) {<br />

ac = getObjects();<br />

}<br />

}<br />

public function getObjects():ArrayCollection {<br />

return mySO.data[lsoType];<br />

}<br />

public function addObject(o:Object):void {<br />

ac.addItem(o);<br />

updateSharedObjects();<br />

}<br />

private function updateSharedObjects():void {<br />

mySO.data[lsoType] = ac;<br />

mySO.flush();<br />

}<br />

The following Flex application creates an instance of the ActionScript class for each of the types of shared objects it<br />

needs. It th<strong>en</strong> calls methods on that class wh<strong>en</strong> the user adds or removes blogs or site URLs.<br />

Last updated 6/6/2012<br />

704

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!