cairngorm入门案例.docVIP

  • 2
  • 0
  • 约6.15千字
  • 约 9页
  • 2018-03-23 发布于河南
  • 举报
cairngorm入门案例

Flex开发框架cairngorm入门实例 2010-05-27 19:51 ?Cairngorm是flex开发的mvc框架,现在在 adobe旗下。它架构和eclipse插件开发gef架构很相似,具体工作原理如下: ? ? ? 该框架就是一个Cairngorm.swc文件,大家可以到Cairngrom的官方网站上去下载,我在这里提供地址:/wiki/display/cairngorm/Cairngorm 然后新建一个Flex工程,有一个Cairngrom.swc包一定要引进去才行(一般放在libs文件夹里面),或者直接 在build path中加入该包。 ? 下面通过一个实例来说明Cairngorm框架如何使用。我们做一个简单的图书录入显示功能,做完后界面如下: ? ? flex工程结构如下: ? ? 第1步:定义VO,不妨假定一本书包含书名,作者,和单价。代码如下,文件名为BookVO.as package com.dobodo.vo { public class BookVO { public var bookName:String; public var bookAuthor:String; public var bookPrice:String; public function BookVO() { } } } 第 2步:创建ModelLocator,该类为单例模式,用来放整个应用的数据。 package com.dobodo.model { import mx.collections.ArrayCollection; public class ModelLocator { static private var __instance:ModelLocator=null; [Bindable] public var BookAC:ArrayCollection = new ArrayCollection(); static public function getInstance():ModelLocator { if(__instance == null) { __instance=new ModelLocator(); } return __instance; } } } 第3步:现在我们就要开始设计我们的视图了,即我们的界面效果,它是一个Component,。 文件名为:BookAdd.mxml ?xml version=1.0 encoding=utf-8? mx:Panel xmlns:mx=/2006/mxml width=562 height=306 horizontalAlign=left title=添加图书 mx:Script ![CDATA[ import com.dobodo.event.AddBookEvent; import com.adobe.cairngorm.control.CairngormEventDispatcher; import com.dobodo.vo.BookVO; import mx.collections.ArrayCollection; [Bindable] public var bookAC:ArrayCollection = new ArrayCollection(); public function addBook():void { var bookVO:BookVO = new BookVO(); bookVO.bookName = this.bookName.text; bookVO.bookAuthor = this.bookAuthor.text; bookVO.bookPrice = this.bookPrice.text; var event:AddBookEvent = new AddBookEvent(bookVO); CairngormEventDispatcher.getInstance().dispatchEvent(event); this.bookName.text = ; this.bookAuthor.text = ; this.bookPrice.text = ; } ]] /mx:Script mx:HBox width=100% height=258 horizontalScrollPolicy=off mx:VBox width=250 mx:Form width=233 height=212 mx:FormItem label=书名: mx:TextInput width=118 id=bookName/ /mx:FormItem mx:FormItem label=作者: mx:TextInput

文档评论(0)

1亿VIP精品文档

相关文档