Title: Message
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
-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Tuesday, August 30, 2005 10:30 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] How come this code does not work

Ok I am trying to link this code to a seperate .as file and have been unable to do so as far as getting the shared object to work here is the code for the mxml file.
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" initialize="fna.initApp()"  xmlns="*">
<firstsharedobjectas id="fna" fnewview="{this}"/>
<mx:Script>
public var mySO:SharedObject;
public var welcomeMessage:String;
 
 
</mx:Script>
<mx:Label id="label1" text="{welcomeMessage}" />
<mx:Label id="label2" text="Enter Name:" />
<mx:TextInput id="ti1" password ="true"/>
<mx:Button label="Store Name" click="fna.storeName()" />
</mx:Application>
 
Here is the code for the .as file
// ActionScript Document
 
class firstsharedobjectas
{
 public var fnewview:Object;
 public var mySO:SharedObject;
public var welcomeMessage:String;
 
 public function firstsharedobjectas()
 {
 

  
  }
public function initApp() {
 mySO = SharedObject.getLocal("mydata");
 welcomeMessage = "Hello " + getName();
}
 
public function getName() {
 return mySO.data.name;
}
 
public function storeName() {
 mySO.data.name = fnewview.ti1.text;
 mySO.flush();
}
}


--
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




------------------------------------------------------------------
**STATEMENT OF CONFIDENTIALITY**

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.
------------------------------------------------------------------

Reply via email to