2 Replies Latest reply on Dec 17, 2010 1:39 AM by JockMahon

    Best use of a model in cairngorm

    JockMahon Level 1

      I am a little confused about the use of a model , ModelLocator, in cairngorm

       

      I have it created and it all works fine but whats the best way to access it, Currently i have numerous forms that all do something like

       

          <fx:Script>
              <![CDATA[
               
                  import com.model.ModelLocator;
               
                  [Bindable] private var model:ModelLocator = ModelLocator.getInstance();

       

      and then later on

       

                  private function fun1(evt:Event):void
                  {

                     model.something = "blah"

                     var s1:String = model.anotherSomething;

                  }

       

      or whatever

       

      Is it ok to have varibles all over the place in different mxml files all creating a private var model, does this comsume resouces or is it ok because its static

       

      Also i have several arrayCollections 11+ , plus other stuff in the model, is this ok

        • 1. Re: Best use of a model in cairngorm
          BhaskerChari Level 4

          Hi JockMahon,

           

          Its ok fine you can go with that..

           

          However remember one thing you will be declaring any variables in the ModelLocator class only if you are using them through out your application .. I mean more than one mxml page or AS files. However if you require any property or variable only within a single file then you can declare it locally within the file instead of decalring it in

          ModelLocator.

           

          The ModelLocator class in cairngorm framework is a singleton class so in how many files you have a model variable it will actually refer or return only single static instance of the ModelLocator class.

           

          [Bindable] private var model:ModelLocator = ModelLocator.getInstance();

           

          So how many times you have a variable by using the above style of decalring you will only get a single static reference to the instance of ModelLocator class. No ne instances are created. Its like you get a pointer to the model variable.

           

          Hope it is clear now.

           

          Thanks,

          Bhasker

          • 2. Re: Best use of a model in cairngorm
            JockMahon Level 1

            That's great thanks