Follow me Stepbystep Flex tutorial

Source: Internet
Author: User
Tags variables

The concept of Model locator has been said to store all the value objects (valueobjects, data) in one place and share variables.

In other words, Model Locator is used to centralize the variables needed to manage the program.

The following DEMO15 modellocator.as code is as follows: (the author adds the corresponding annotation)

import mx.collections.ArrayCollection;

 [Bindable]
 public class ModelLocator
 {

  //定义程序需要的变量,作者建 议读者把该部分定义放在最下边,而不是示例中的上边,原因就是在于代码更整 齐(因人而异,仅作者的个人建议,呵呵)
  public var photoData:ArrayCollection=new ArrayCollection();
  public var purchasedPhotos:ArrayCollection=new ArrayCollection();

  //定义ModelLocator的Single Instance,这就是设计模式的单例模式(不明白 的读者可以看设计模式中的该模式讲解)
  static private var __instance:ModelLocator=null;
  //返回single instance
   static public function getInstance():ModelLocator
  {
    if(__instance == null)
   {
    __instance=new ModelLocator();
   }
   return __instance;
  }
 }

For Modellocator's instance and getinstance code, this part of the code is written in the process of writing new code, unless you redefine one of your own modellocator (based on the Imodellocator interface implementation), This part of the code is so written, hehe, even its own definition, it is similar.

For getinstance, it will be judged whether the program already has an instance of Modellocator, and if it is read, it is not created.

The [bindable] feature makes the variable that you define automatically updated wherever you use the defined variable, which is also the concept of modellocator shared variables.

Valueobject under the Photo.as object author does not explain, really no explanation, hehe.

The next talk about the core of the Cairngorm control process, that is, bussiness under the various parts and the complex relationship between the event, may be the reader just contact will feel very winding, it does not matter, oh, step by step, the author explained, the reader will not have that feeling.

The author is very grateful to the broad masses of the reader's support, see everyone's evaluation, the heart is very gratified, hehe.

Article Source: http://wangyisong.javaeye.com/blog/451924

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.