I have changed it a little bit
As mentioned, I wouldn't pass a reference
too.
I used the Application creationComplete to assign the
value from SO, if undefined it will return an empty string
I created the SO in the class
constructor
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
xmlns="*"
creationComplete="ti1.text=fna.getName();">
<firstsharedobjectas id="fna"/> <mx:Label
id="label2" text="Enter Name:" />
<mx:TextInput id="ti1" password ="true"/> <mx:Button label="Store Name" click="fna.storeName(ti1.text)" /> <mx:Button
label="Show SO value" click="alert(fna.getName())"
/>
</mx:Application> firstsharedobjectas.as
-----------------------
// ActionScript
Document
class firstsharedobjectas { public var mySO:SharedObject; public var welcomeMessage:String; public function firstsharedobjectas(){ mySO = SharedObject.getLocal("mydata"); } public function getName() { var r = mySO.data.name == undefined ? '' : mySO.data.name; return r; } public function storeName(val) { mySO.data.name = val; mySO.flush(); } } Philippe
Maegerman From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Battershall, Jeff Sent: mardi 30 août 2005 16:52 To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] How come this code does not work I've not done a lot of work with Shared
Objects, but some things are amiss with your class definition. Your
storeName() function has a reference to an external object - breaks
encapsulation.
At minimum, your storeName function should
accept the string you're trying to store.
public function storeName(s:String)
{
mySO.data.name = s; mySO.flush();
} <mx:Button label="Store Name"
click="fna.storeName(fnewview.ti1.text)" />
Jeff
-- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com YAHOO! GROUPS LINKS
------------------------------------------------------------------ This e-mail and any attached files are confidential and intended solely for the use of the individual to whom it is addressed. If you have received this email in error please send it back to the person that sent it to you. Any views or opinions presented are solely those of author and do not necessarily represent those the Emakina Company. Unauthorized publication, use, dissemination, forwarding, printing or copying of this email and its associated attachments is strictly prohibited. We also inform you that we have checked that this message does not contain any virus but we decline any responsability in case of any damage caused by an a non detected virus. |
Title: Message