(24)【ModelLocatorの作成】

アドレス帳サンプルアプリの続きです。
では、今回はModelLocatorを作成します。
ModelLocatorは、画面データのバインディングが目的ですので、
"[Bindable]"クラスとしてSingletonで作成します。

今回は「一覧DataGridの配列」と「メッセージ」をプロパティにします。

package model
{
    import mx.collections.ArrayCollection;
    import com.adobe.cairngorm.model.ModelLocator;
    [Bindable]
    public class AddressModelLocator implements ModelLocator{
        /** 一覧 */
        public var addressList : ArrayCollection;
        /** メッセージ */
        public var message : String;
        /**
         * インスタンス取得メソッド。(singleton)
         */
        public static function getInstance() : AddressModelLocator{
            if( modelLocator == null ){
                modelLocator = new AddressModelLocator();
            }
            return modelLocator;
        }
        /**
         * コンストラクタ。
         */
        public function AddressModelLocator(){
            addressList = new ArrayCollection();
            
            if( modelLocator != null){
                throw new Error( "Only one ModelLocator instance should be instantiated" );
            }
        }
        private static var modelLocator:AddressModelLocator;
    }
}

次回は、BusinessLogicの作成です。