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);

阅读更多
个人分类: FLEX
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭