Right so what you're essentially talking about is a Model, and the SharedObject is acting as a Service.

public class Model extends EventDispatcher
{
    private var so:SharedObject;

    public function Model()
    {
        super();
        init();
    }
    private function init():void
    {
        so = SharedObject.getLocal("yourAppName");
    }
    public function set foo(value:int):void
    {
        so.data.foo = value;
        so.flush();
        dispatchUpdate();
    }
    public function get foo():int
    {
        return so.data.foo;
    }
    public function set bar(value:String):void
    {
        so.data.bar = value;
        so.flush();
        dispatchUpdate();
    }
    public function get foo():String
    {
        return so.data.bar;
    }
    private function dispatchUpdate():void
    {
        dispatchEvent(new ModelEvent(ModelEvent.UPDATE));
    }
    // etc.
}

Get the idea? It might seem like a lot of extra work, but by mapping out all of the values you need, it will be extremely clear what's being stored and what type each property is. It will help you avoid missing things you should be storing (like a checklist), and you will always be able to guarantee that the value you're getting is what you're expecting, avoiding run-time errors.

By listening the model for its update event, you're also guaranteeing that if one thing updates a value in the SharedObject, anyone who cares about that value will be updated that the value has potentially changed.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to