Flash_and_Flex_03_2009

ActionScript Development

Model Locator The ModelLocator acts as a central data bank for all of your applications data; any data that is required to live inside of the application should be placed inside of the ModelLocator. The

Singleton class is used to restrict instantiation of a class to one object, and one object alone. There will only be one ModelLocator per application. For instance if you were to deposit money at an ATM machine, that money is going to be

accessible everywhere, not just at that particular ATM machine. That is because you are storing your money inside of your bank. Think of a ModelLocator as a bank, you only need one bank to store all of your data (money),

Listing 2. ModelLocator.as

package com.jonniespratley.flexcontacts.model {

import com.adobe.cairngorm.model.IModelLocator; import com.jonniespratley.flexcontacts.vo.ContactVO; import mx.collections.ArrayCollection;

[Bindable] public final class FlexContactsModelLocator implements IModelLocator { private static var instance:FlexContactsModelLocator; public function FlexContactsModelLocator() { if ( instance != null ) { throw new Error( "Error: " + } public static function getInstance():FlexContactsModelLocator { if ( instance == null ) { instance = new FlexContactsModelLocator(); } return instance; } public var contactsCollection:ArrayCollection; } FlexContactsModelLocator.instance = this ;

"FlexContactsModelLocator can only be instantiated via getInstance() method!" );

public var selectedContact:ContactVO; public var isLoggedIn:Boolean = false ; public var workflowState:uint = 0; public static const LOGIN_SCREEN:uint = 0; public static const MAIN_SCREEN:uint = 1;

}

}

Listing 3. Services.mxml

xmlns:cairngorm="com.adobe.cairngorm.business.*" >

id="AmfphpService" destination="amfphp" endpoint="http://codegen/amfphp/gateway.php"

source="ContactsService" makeObjectsBindable="true" showBusyCursor="true"/>

03/2009 (5)

54

Made with FlippingBook HTML5