1
8
9 import com.sekati.core.CoreObject;
10 import com.sekati.events.Dispatcher;
11 import com.sekati.events.Event;
12 import com.sekati.utils.Delegate;
13
14
17 class com.sekati.data.SO extends CoreObject {
18
19 private var _this:SO;
20 private var _so:SharedObject;
21 private var _name:String;
22 private static var onSOStatusEVENT:String = "onSOStatus";
23 private static var onSOSyncEVENT:String = "onSOSync";
24
25
31 public function SO(so_name:String) {
32 super( );
33 if(!so_name) {
34 throw new Error( "@@@ " + this.toString( ) + " Error: instance Constructor expects so_name param." );
35 return;
36 }
37 _name = so_name;
38 _this = this;
39 _so = SharedObject.getLocal( _name );
40 _so.onStatus = Delegate.create( _this, so_onStatus );
41 _so.onSync = Delegate.create( _this, so_onSync );
42 }
43
44
49 public function so_onStatus(info:Object):Void {
50 trace( "status info: " + info );
51 var e:Event = new Event( onSOStatusEVENT, this, {info:info} );
52 Dispatcher.$.dispatchEvent( e );
53 }
54
55
58 public function so_onSync(obj:Object):Void {
59 trace( "sync obj: " + obj );
60 var e:Event = new Event( onSOSyncEVENT, this, {obj:obj} );
61 Dispatcher.$.dispatchEvent( e );
62 }
63
64
70 public function write(prop:String, val:Object):Void {
71 _so.data[prop] = val;
72 _so.flush( );
73 }
74
75
80 public function read(prop:String):Object {
81 return _so.data[prop];
82 }
83
84
88 public function clear():Void {
89 _so.clear( );
90 }
91
92
96 public function getSize():Number {
97 return _so.getSize( );
98 }
99
100
104 public function getData():String {
105 var str:String = _name + "={\n";
106 for (var prop in _so.data) {
107 str += prop + ": " + _so.data[prop] + "\n";
108 }
109 str += "};";
110 return str;
111 }
112
113
117 public function showSettings():Void {
118 System.showSettings( 1 );
119 }
120
121
125 public function destroy():Void {
126 _so.data = null;
127 _so.flush( );
128 delete this;
129 super.destroy( );
130 }
131 }