PDA

View Full Version : keeping form data in Flash?



bootiteq
October 23rd, 2008, 05:18 AM
Hi there,

Is there another/better way of doing this in AS3?

here is my data container


package {
public class dataContainer {

var _data:Object;

public function dataContainer ():void{
_data = new Object();
}
public function addValue(nam:String, val:String):void{
_data[nam] = val;
}
public function removeValue(nam:String):void{
delete _data[nam];
}
public function get data():Object{
return _data;
}
}
}


on a frame I put this...



import dataContainer;
var dc = new dataContainer();

dc.addValue ("name","harry");
dc.addValue ("age","22");
dc.addValue ("sex","male");

trace (dc.data.name);

trace ("--------------------------------------------");

for (var i in dc.data) {
trace (i + " = " + dc.data[i]);
}

trace ("--------------------------------------------");

dc.removeValue ("sex");

for (var n in dc.data) {
trace (n + " = " + dc.data[n]);
}


which traces:

harry
--------------------------------------------
age = 22
sex = male
name = harry
--------------------------------------------
age = 22
name = harry



Any help appreciated :crazy:


..

bootiteq
October 24th, 2008, 09:34 PM
bump

Krilnon
October 24th, 2008, 09:40 PM
What can your dataContainer do that a regular Object can't? If you know what the form fields are going to be ahead of time, then you could make them explicit properties of the class; that would allow you to avoid using an object with a lookup table for properties, and you could benefit from some compiler error checking and such elsewhere in your code.

bootiteq
October 25th, 2008, 06:58 AM
I will use in conjuction with some form components I am making so it needs to be flexible. The user of the component can name the variables they send to anything they like.

The value of the variables will always be of type string.

I was thinking that all vars will be checked then sent using for...in.

The way i've mentioned above will work a treat - just not sure if there is a better way to do this with AS3 now.

Any ideas?