Cairngorm开发步骤

1、编写控制器
package com.forbeauty.store.control
{
import com.adobe.cairngorm.control.FrontController;


/**
* @version $Revision: $
*/
public class ShopController extends FrontController
{
public function ShopController()
{
initialiseCommands();
}

public function initialiseCommands() : void
{

}
}

}

2、编写ModelLocator
package com.forbeauty.store.model
{
import com.adobe.cairngorm.model.ModelLocator;

[Bindable]
public class MenuModelLocator implements ModelLocator
{
private static var menumodelLocator : MenuModelLocator;

public static function getInstance() : MenuModelLocator
        {
         if ( menumodelLocator == null )
         {
         menumodelLocator = new MenuModelLocator();
         }
     
         return menumodelLocator;
        }
       
        public function MenuModelLocator()
        {
           if ( menumodelLocator != null )
           {
           throw new Error( "Only one ShopModelLocator instance should be instantiated" );
           }
        }
       
        public var xmlData:String;
}
}
其中包括需要处理或使用的数据,并使用单例模式

3、编写Service.mxml
<?xml version="1.0" encoding="utf-8"?>

<cairngorm:ServiceLocator
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:cairngorm="http://www.adobe.com/2006/cairngorm">
<!--
    <mx:RemoteObject id="productService" destination="productServiceImpl"
showBusyCursor="true">
    </mx:RemoteObject>

    <mx:RemoteObject id="creditCardService" destination="creditCardServiceImpl"
showBusyCursor="true">
    </mx:RemoteObject>
-->
    <mx:HTTPService id="menuDelegate"
resultFormat="e4x"
showBusyCursor="true"
url="../datas/menus.xml">
</mx:HTTPService> 

</cairngorm:ServiceLocator>

4、编写Command

package com.forbeauty.store.command
{
import mx.rpc.IResponder;
import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;
import com.forbeauty.store.model.MenuModelLocator;
import com.forbeauty.store.business.MenuDelegate;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.collections.ICollectionView;
import mx.collections.Sort;
import mx.collections.SortField;
import mx.utils.ArrayUtil;
import flash.events.Event;

public class MenuDataCommand implements ICommand, IResponder
{
public function MenuDataCommand()
{
}

public function execute( event : CairngormEvent ): void
{
if( MenuModelLocator.getInstance().xmlData == null )
{
    var delegate : MenuDelegate = new MenuDelegate( this );
    delegate.getMenus();
}
else
{
Alert.show( "Products already retrieved!" );
return;
}
}
public function result( event : Object ) : void
{
Alert.show((event as ResultEvent).result.toString());
}
public function fault( event : Object ) : void
{
var faultEvent : FaultEvent = FaultEvent( event );
Alert.show( faultEvent.toString() );
Alert.show( "Can not get menus" );
}
}
}

5、编写Event

package com.forbeauty.store.event
{
import flash.events.Event;
import com.adobe.cairngorm.control.CairngormEvent;

public class GetMenuEvent extends CairngormEvent
{
public static var EVENT_GET_MENUS : String = "getMenus";

/**
* Constructor.
*/
public function GetMenuEvent()
{
super( EVENT_GET_MENUS );
}
    
     /**
     * Override the inherited clone() method, but don't return any state.
     */
override public function clone() : Event
{
return new GetMenuEvent();
}
}
}

6、在View中发送事件
var event:CairngormEvent=new CairngormEvent(GetMenuEvent.EVENT_GET_MENUS);

CairngormEventDispatcher.getInstance().dispatchEvent(event);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值