It worked for me.  Here is the output I see in the console window after
clicking on "Save SharedObject" then "Retrieve SharedObject":

 

[SWF] C:\gemini\TestApp\bin\TestApp-debug.swf - 447,488 bytes after
decompression

[CustomVO]test string,12345,46

[object Object]

test string

test xml data: <mytag name="test string" id="12345"/>

 

Also, you should be able to find the shared object file on your file
system and see the Strings in the XML.  See
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhel
p.htm?context=LiveDocs_Book_Parts&file=lsos_087_3.html .

 

-Brian

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of annespg
Sent: Thursday, May 24, 2007 9:52 AM
To: [email protected]
Subject: [flexcoders] problems with storing XML in SharedObject

 

I just joined this forum hoping I might get an answer since traffic 
on the Adobe Flex Forum seems pretty darn sparse. I'm surprised 
since the Flash Forum is so active one can get several answers 
within hours and on the Flex Forum one can go months and never get 
an answer. At any rate...

I am trying to store some XML in the SharedObject, but it doesn't 
seem to work. I think I'm getting it in there, but if I close the 
app and then try to retrieve it, it is null. I have the following 
test code. What the heck am I doing wrong?!?!?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " 
layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import valueObjects.CustomVO;
import flash.net.registerClassAlias;

private var mySO:SharedObject;
private function init():void{
mySO = SharedObject.getLocal("testSO");
}

private function saveSO():void{
var obj:CustomVO = new CustomVO("test string",12345);
var tagname:String = "mytag"; 
var x:XML = <{tagname} name={obj.name} id={obj.id}/>; 
var test:CustomVO = CustomVO.buildCustomVOFromXML(x);
trace (test); //this works fine, so my x:XML variable seems fine
mySO.data.testString = obj.name;
mySO.data.testXMLData = x;
// the debugger shows the data is in mySO fine at this point
mySO.flush();
}
private function getSO():void{
//if I close the application and then launch again and invoke this
//function the testString is there OK, but the testXMLData is null
var theData:Object = mySO.data;
var theXML:XML = mySO.data.testXMLData; //this comes back null
trace(theData); // shows [object Object]
trace(mySO.data.testString);// shows 'test string'
trace("test xml data: "+theXML.toXMLString()); // shows no data 
}
private function removeSO():void{
mySO.clear();
}
]]>
</mx:Script>
<mx:Button x="175" y="101" label="Save SharedObject" click="saveSO
()"/>
<mx:Button x="175" y="165" label="Retrieve SharedObject" click="getSO
()"/>
<mx:Button x="175" y="235" label="Remove SharedObject" 
click="removeSO()"/>

</mx:Application>

package valueObjects{
[Bindable]
public class CustomVO{
public var name:String;
public var id:Number;
public var timeStamp:Number;

public function CustomVO(name:String,id:Number){
this.name = name;
this.id = id;
this.timeStamp = new Date().milliseconds;
}
public function toString():String{
return ("[CustomVO]" +name+","+id+","+timeStamp);
}
public static function buildCustomVOFromXML(item:XML):CustomVO{
var v:CustomVO = new CustomVO([EMAIL PROTECTED], [EMAIL PROTECTED]);

return v;
}
}
} 

 

Reply via email to