最简puremvc
工程如下,看来sendNotification是像comand和mediator发消息的
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField; public class Main extends Sprite
{
public var txt:TextField;
public var btn:MyButton;
public function Main()
{
if(stage) init();
else addEventListener(Event.ADDED_TO_STAGE,init);
}
private function init(e:Event=null):void
{
this.removeEventListener(Event.ADDED_TO_STAGE,init);
txt = new TextField();
txt.text = "hellopuremvc";
this.addChild(txt);
btn = new MyButton();
btn.y = 90;
this.addChild(btn) MyFacade.getInstance().startup(this);
}
}
}
package
{
import controller.MyCommand;
import org.puremvc.as3.interfaces.IFacade;
import org.puremvc.as3.patterns.facade.Facade;
public class MyFacade extends Facade implements IFacade
{
public static const STARTUP:String = "startup";
public static const CHANGETEXT:String = "changetext";
public static const CHANGECOMMAND:String = "changecommand";
public function MyFacade()
{
}
public static function getInstance():MyFacade
{
if(instance == null){
instance = new MyFacade();
}
return instance as MyFacade;
}
override protected function initializeController():void
{
super.initializeController();
registerCommand(STARTUP,MyCommand); }
public function startup(_main:Main):void
{
//启动puremvc环境
sendNotification(STARTUP,_main);
}
}
}
package controller
{
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand; public class ChangeCommand extends SimpleCommand
{
public function ChangeCommand()
{
super();
}
override public function execute(note:INotification):void{
trace("ChangeCommand执行了");
}
}
}
package controller
{
import model.MyProxy;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.command.SimpleCommand;
import view.BtnMediator;
import view.TextMediator; public class MyCommand extends SimpleCommand
{
public function MyCommand()
{
super();
}
override public function execute(note:INotification):void
{
var _main:Main = note.getBody() as Main;
this.facade.registerProxy(new MyProxy());
this.facade.registerMediator(new TextMediator(_main.txt));
this.facade.registerMediator(new BtnMediator(_main.btn));
this.facade.registerCommand(MyFacade.CHANGECOMMAND,ChangeCommand);
}
}
}
package model
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import org.puremvc.as3.interfaces.IProxy;
import org.puremvc.as3.patterns.proxy.Proxy; public class MyProxy extends Proxy implements IProxy
{
public static const NAME:String = "MyProxy";
public function MyProxy(proxyName:String = null,data:Object = null)
{
super(NAME,data);
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onComplete);
loader.addEventListener(IOErrorEvent.IO_ERROR,onError);
loader.load(new URLRequest("data.xml"));
}
private function onComplete(e:Event):void
{
var xml:XML = XML(e.target.data);
this.setData(xml);
}
private function onError(e:IOErrorEvent):void
{
trace("数据获取失败");
}
}
}
package view
{
import flash.display.SimpleButton;
import flash.events.MouseEvent; import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.patterns.mediator.Mediator; public class BtnMediator extends Mediator implements IMediator
{
public static const NAME:String = "BtnMediator";
public function BtnMediator(viewComponent:SimpleButton)
{
super(NAME,viewComponent);
btn.addEventListener(MouseEvent.CLICK,onClick);
}
private function onClick(evt:MouseEvent):void
{
sendNotification(MyFacade.CHANGETEXT);
sendNotification(MyFacade.CHANGECOMMAND);
//sendNotification 看来是给command和mediator发消息的
}
public function get btn():SimpleButton
{
return viewComponent as SimpleButton;
}
}
}
package view
{
import flash.text.TextField; import model.MyProxy; import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.mediator.Mediator; public class TextMediator extends Mediator implements IMediator
{
public static const NAME:String = "TextMediator";
public function TextMediator(viewComponent:TextField)
{
super(NAME,viewComponent);
}
override public function listNotificationInterests():Array
{
return [MyFacade.CHANGETEXT,MyFacade.CHANGECOMMAND];//对MyFacade.CHANGETEXT感兴趣
}
override public function handleNotification(note:INotification):void
{
switch(note.getName()){
case MyFacade.CHANGETEXT:
var proxy:MyProxy = facade.retrieveProxy(MyProxy.NAME) as MyProxy;
var xml:XML = XML(proxy.getData());
txt.text = xml.msg; break;
case MyFacade.CHANGECOMMAND:
trace("mediator侦听command的命令也执行了");
break;
}
}
public function get txt():TextField
{
return viewComponent as TextField;
}
}
}
最简puremvc的更多相关文章
- CSharpGL(28)得到高精度可定制字形贴图的极简方法
CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...
- Lua pureMVC
分享一个lua语言版本的pureMVC. 这个是一个根据AS3(ActionScript 3) pureMVC而转换过来的lua pureMVC.所有的接口完全跟AS3版本一致,本来是想用在项目之中的 ...
- 简析.NET Core 以及与 .NET Framework的关系
简析.NET Core 以及与 .NET Framework的关系 一 .NET 的 Framework 们 二 .NET Core的到来 1. Runtime 2. Unified BCL 3. W ...
- 第三十章 elk(1) - 第一种架构(最简架构)
软件版本: es:2.4.0 logstash:2.4.0 kibana:4.6.1 一.logstash安装(收集.过滤日志.构建索引) 1.下载:https://www.elastic.co/do ...
- 简析 .NET Core 构成体系
简析 .NET Core 构成体系 Roslyn 编译器 RyuJIT 编译器 CoreCLR & CoreRT CoreFX(.NET Core Libraries) .NET Core 代 ...
- 《大道至简》第一章读后感--JAVA语言伪代码形式
import.java.大道至简.*; //一·愚公移山 import.java.愚公移山.*; public class YuGongYiShan { //原始需求:惩山北之塞,出入之迂 //项目沟 ...
- iOS离屏渲染简书
更详细地址https://zsisme.gitbooks.io/ios-/content/chapter15/offscreen-rendering.html(包含了核心动画) GPU渲染机制: CP ...
- .NET简谈接口
自从面向对象开发方式的出现,抽象的概念就开始日新月异的发展,面向对象编程.面向接口编程.面向组件编程等等:这一系列的概念都是软件工程所追求的思想范畴,高类聚低耦合. 今天我要简谈的是面向对象里面非常重 ...
- 《大道至简》第一章——编程的精义_读后感(Java伪代码形式)
<大道至简>第一章——编程的精义_读后感(Java伪代码形式)1.愚公移山//愚公为团体的项目组织者.团体经理.编程人员.技术分析师等//子孙荷担者三人为三名技术人员//遗男为外协//目标 ...
随机推荐
- key 4v4
#include "key4v4.h" #include "stm32f10x.h" #include "delay.h" /* PA4-L ...
- SharePoint 2013 Nintex Workflow 工作流帮助(十三)
博客地址 http://blog.csdn.net/foxdave 工作流动作 35. Delegate Workflow Task(User interaction分组) 该操作将委托未处理的工作流 ...
- 面向对象之prototype,__proto__
var person = function(name) { this.name = name }; person.prototype.getName = function() { return thi ...
- 有关PHP安装,基础学习
首先要安装 wamp 和 NavicatMySQLFront (要在非中文目录下) 打开DW 点击站点 ——新建站点:设置站点名称,选择本地站点文件夹:wap\www 服务器:添加 + 服务器名 ...
- poj2392 多重背包
//Accepted 868 KB 188 ms //多重背包 #include <cstdio> #include <cstring> #include <iostre ...
- jQuery中 判断事件
$('button.top').on('mousedown', function() { var $this = $(this); if ($this.hasClass('settop')) { $t ...
- mp3文件 ID3v2 帧标识的含义
mp3文件 ID3v2 帧标识的含义 Declared ID3v2 frames The following frames are declared in this draft. 4.20 AENC ...
- Note_Master-Detail Application(iOS template)_01_YJYAppDelegate.h
//YJYAppDelegate.h #import <UIKit/UIKit.h> @interface YJYAppDelegate : UIResponder <UIAppli ...
- Git ~ 回到过去 , 进入未来 ~ Git
概述 我们已经成功的添加了一个 readme.txt文件 , 现在是时候 继续工作了 , 于是 我们开始尝试一下 Git给我们所带来的便利下面修改read.txt 改成如下内容 为了尝试 Git 给我 ...
- PHP Forms
<html><body><form action="welcome.php" method="post">Name: < ...