O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.4. How Do You Use It?

Once you have your ModelLocator class created, the next step is to add public properties representing the data that needs to be accessed to the ModelLocator. As mentioned previously, in many cases this data consists either of one of the Flex mx.collections classes or instances of value object classes, as can be seen in the following:

package com.cairngormexample.model
{
    import mx.collections.ArrayCollection;
    import com.someproject.vo.UserVO;

    public class CairngormExampleModel
    {
        private static var instance:CairngormExampleModel;
        public var user:UserVO;
        public var items:ArrayCollection=new ArrayCollection();
        public var purchasedItems:ArrayCollection=new ArrayCollection();
        public function CairngormExampleModel(se:SingletonEnforcer)
        {
        }
        public static function getInstance():CairngormExampleModel{
            if (CairngormExampleModel.instance == null){
                CairngormExampleModel.instance = new CairngormExampleModel(new
SingletonEnforcer());
            }
            return CairngormExampleModel.instance;
        }
    }
}
class SingletonEnforcer{};

Once these properties have been added you simply need to get a reference to the ModelLocator and then reference the properties, as in the following:

var model: CairngormExampleModel = CairngormExampleModel.getInstance();
//user
model.user;
//items
model.items
//purchased items
model.purchasedItems

Once you have this reference you can use the properties of the ModelLocator for data binding in components. The following example is again from the Cairngorm store application. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required