国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 辦公 > Flash > 正文

flash PureMVC 使用例子

2024-09-12 17:51:03
字體:
供稿:網(wǎng)友
此例環(huán)境:
flash cs3
鏈接PureMVC類<編輯->首選參數(shù)->ActionScript->ActioScript 3.0 設(shè)置(加上你的下載的PureMVC類包), PureMVC下載地址>
開始動手嘍~
1, 在flash里準(zhǔn)備一下要顯示層的東東:
此例就畫了一個背景方框, 添加一個動態(tài)的TextField命名為txt, 然后綁定一個類AppTextField.as;
AppTextField.as里需要接收一個字符串并顯示出來, 些字符串?dāng)?shù)據(jù)就是來自于數(shù)據(jù)層的(后面有介紹)
復(fù)制代碼 代碼如下:

AppTextField.as

package myapp.view.component{
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.TextField;

public class AppTextField extends Sprite{

public function AppTextField(str:String):void{
txt.text = str;
}
}
}

2, 準(zhǔn)備數(shù)據(jù)
建立一個DataProxy.as文件用于存放數(shù)據(jù)(此例只是一個字符串),此類要繼承Proxy實現(xiàn)接口IProxy.
復(fù)制代碼 代碼如下:

DataProxy.as

package myapp.model{
import org.puremvc.as3.patterns.proxy.Proxy;
import org.puremvc.as3.interfaces.IProxy;

public class DataProxy extends Proxy implements IProxy{
private var _info:String;
static public const NAME:String = "DataProxy";

public function DataProxy() {
super(NAME);
return;
}

public function get info():String {
return "Ok! Is very good!";
}
}
}

3.注冊啟動命令(復(fù)合):StartupCommand和兩個子命令ModelPrepCommand, ViewPrepCommand(數(shù)據(jù)初始化和顯示層初始化)
復(fù)制代碼 代碼如下:

StartupCommand.as

package myapp.controller{
import org.puremvc.as3.patterns.command.MacroCommand;

public class StartupCommand extends MacroCommand {
// 程序開始時執(zhí)行的 MacroCommand.
public function StartupCommand() {
return;
}
//添加子Command 初始化 MacroCommand.
override protected function initializeMacroCommand():void {
//以下兩個命令按先進(jìn)先出順序執(zhí)行;
addSubCommand(ModelPrepCommand);
addSubCommand(ViewPrepCommand);
return;
}
}
}

復(fù)制代碼 代碼如下:

ModelPrepCommand.as

package myapp.controller{
import myapp.model.*;
import org.puremvc.as3.interfaces.ICommand;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand;

public class ModelPrepCommand extends SimpleCommand implements ICommand {
//創(chuàng)建 Proxy 對象,并注冊;
public function ModelPrepCommand() {
return;
}
//由MacroCommand 調(diào)用;
public override function execute(sender:INotification):void {
facade.registerProxy(new DataProxy());
return;
}
}
}

復(fù)制代碼 代碼如下:

ViewPrepCommand.as

package myapp.controller{
import myapp.view.*;
import org.puremvc.as3.interfaces.ICommand;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand;

public class ViewPrepCommand extends SimpleCommand implements ICommand {

public function ViewPrepCommand() {
return;
}
// 創(chuàng)建 Mediator, 并把它們注冊到View;
public override function execute(sender:INotification):void {
var obj:Main;
obj = sender.getBody() as Main;
facade.registerMediator(new AlertMediator(obj));
return;
}
}
}


4.創(chuàng)建Mediator對象類AlertMediator.as用于操作具體顯示層組件(此例是AppTextField.as)
復(fù)制代碼 代碼如下:

AlertMediator.as

package myapp.view{
import myapp.MyappFacade;
import myapp.model.DataProxy;
import myapp.view.component.AppTextField;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.Event;
import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.patterns.mediator.Mediator;

public class AlertMediator extends Mediator implements IMediator {
private var data:DataProxy;
static public const NAME:String = "AlertMediator";

public function AlertMediator(obj:Object) {
super(NAME, obj);
data = facade.retrieveProxy(DataProxy.NAME) as DataProxy;
var t:AppTextField = new AppTextField(data.info);
main.addChild(t);
}
function get main():Main {
return viewComponent as Main;
}
}
}


5.創(chuàng)建建立Command與Notification之間的映射關(guān)系類MyappFacade.as
復(fù)制代碼 代碼如下:

MyappFacade.as

package myapp{
import org.puremvc.as3.interfaces.IFacade;
import org.puremvc.as3.patterns.facade.Facade;

import myapp.view.*;
import myapp.model.*;
import myapp.controller.*;

// MyApp 程序的 Facade 類
public class MyappFacade extends Facade implements IFacade {
//定義 Notification (通知)常量
public static const STARTUP:String = "startup";
public static const LOGIN:String = "login";

//得到ApplicationFacade 單例的工廠方法
public static function getInstance():MyappFacade {
if ( instance == null ) {
instance = new MyappFacade( );
}
return instance as MyappFacade;
}

//注冊 Command,建立Command 與 Notification 之間的映射
override protected function initializeController( ):void {
super.initializeController();
registerCommand( STARTUP, StartupCommand );
}

//啟動 PureMVC,在應(yīng)用程序中調(diào)用此方法,并傳遞應(yīng)用程序本身的引用
public function startup( app:Main ):void {
sendNotification( STARTUP, app );
}
}
}


6.創(chuàng)建主文檔類Main.as(啟動命名)
復(fù)制代碼 代碼如下:

Main.as

package {
import myapp.*;
import flash.display.*;

public class Main extends Sprite {
private var facade:MyappFacade;

public function Main() {
facade = MyappFacade.getInstance();
//執(zhí)行開始命令;
facade.startup(this);
return;
}
}
}

可能寫的不清不楚啊, 哈~~ 有問題請留言一起探討吧!
文件打包下載(www.survivalescaperooms.com)
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 木兰县| 上饶市| 浦城县| 新龙县| 包头市| 肃北| 南郑县| 宁夏| 四川省| 张家港市| 绍兴市| 兴安县| 高雄市| 阿荣旗| 彩票| 梅河口市| 临夏县| 巴塘县| 南安市| 庆元县| 基隆市| 淮南市| 蒲江县| 台北县| 淳安县| 巴东县| 邢台县| 天门市| 富阳市| 望江县| 松阳县| 宁河县| 新建县| 玉门市| 收藏| 舒城县| 青河县| 平南县| 洛隆县| 前郭尔| 洛浦县|