This example environment:
flash cs3
Link to PureMVC class <Edit->Preferred parameters->ActionScript->ActivoScript 3.0 settings (plus your downloaded PureMVC class package),PureMVC download address>
Let's start doing it ~
1. Prepare what you want to display the layer in flash:
This example draws a background box, add a dynamic TextField named txt, and then binds a class;
You need to receive a string and display it. Some string data comes from the data layer (introduced later)
package {
import ;
import ;
import ;
public class AppTextField extends Sprite{
public function AppTextField(str:String):void{
= str;
}
}
}
2. Prepare data
Create a file to store data (this example is just a string). This class must inherit Proxy to implement the interface IProxy.
package {
import .;
import .;
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. Register the startup command (composite): StartupCommand and two subcommands ModelPrepCommand, ViewPrepCommand (data initialization and display layer initialization)
package {
import .;
public class StartupCommand extends MacroCommand {
// MacroCommand executed at the beginning of the program.
public function StartupCommand() {
return;
}
//Add child Command to initialize MacroCommand.
override protected function initializeMacroCommand():void {
//The following two commands are executed in first-in-first-out order;
addSubCommand(ModelPrepCommand);
addSubCommand(ViewPrepCommand);
return;
}
}
}
package {
import .*;
import .;
import .;
import .;
public class ModelPrepCommand extends SimpleCommand implements ICommand {
//Create Proxy object and register;
public function ModelPrepCommand() {
return;
}
//Called by MacroCommand;
public override function execute(sender:INotification):void {
(new DataProxy());
return;
}
}
}
package {
import .*;
import .;
import .;
import .;
public class ViewPrepCommand extends SimpleCommand implements ICommand {
public function ViewPrepCommand() {
return;
}
// Create Mediators and register them to the View;
public override function execute(sender:INotification):void {
var obj:Main;
obj = () as Main;
(new AlertMediator(obj));
return;
}
}
}
4. Create a Mediator object class to operate specific display layer components (this example is)
package {
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .;
import .;
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 = () as DataProxy;
var t:AppTextField = new AppTextField();
(t);
}
function get main():Main {
return viewComponent as Main;
}
}
}
5. Create a mapping relationship between Command and Notification
package myapp{
import .;
import .;
import .*;
import .*;
import .*;
// MyApp program's Facade class
public class MyappFacade extends Facade implements IFacade {
//Definition Notification constant
public static const STARTUP:String = "startup";
public static const LOGIN:String = "login";
//Factory method for obtaining ApplicationFacade singleton
public static function getInstance():MyappFacade {
if ( instance == null ) {
instance = new MyappFacade( );
}
return instance as MyappFacade;
}
//Register Command and establish a mapping between Command and Notification
override protected function initializeController( ):void {
();
registerCommand( STARTUP, StartupCommand );
}
//Start PureMVC, call this method in the application, and pass a reference to the application itself
public function startup( app:Main ):void {
sendNotification( STARTUP, app );
}
}
}
6. Create the main document class (start naming)
package {
import myapp.*;
import .*;
public class Main extends Sprite {
private var facade:MyappFacade;
public function Main() {
facade = ();
//Execute the start command;
(this);
return;
}
}
}
Maybe I can’t write it clearly, haha~~ If you have any questions, please leave a message to discuss it together!
File packaging download()
flash cs3
Link to PureMVC class <Edit->Preferred parameters->ActionScript->ActivoScript 3.0 settings (plus your downloaded PureMVC class package),PureMVC download address>
Let's start doing it ~
1. Prepare what you want to display the layer in flash:
This example draws a background box, add a dynamic TextField named txt, and then binds a class;
You need to receive a string and display it. Some string data comes from the data layer (introduced later)
Copy the codeThe code is as follows:
package {
import ;
import ;
import ;
public class AppTextField extends Sprite{
public function AppTextField(str:String):void{
= str;
}
}
}
2. Prepare data
Create a file to store data (this example is just a string). This class must inherit Proxy to implement the interface IProxy.
Copy the codeThe code is as follows:
package {
import .;
import .;
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. Register the startup command (composite): StartupCommand and two subcommands ModelPrepCommand, ViewPrepCommand (data initialization and display layer initialization)
Copy the codeThe code is as follows:
package {
import .;
public class StartupCommand extends MacroCommand {
// MacroCommand executed at the beginning of the program.
public function StartupCommand() {
return;
}
//Add child Command to initialize MacroCommand.
override protected function initializeMacroCommand():void {
//The following two commands are executed in first-in-first-out order;
addSubCommand(ModelPrepCommand);
addSubCommand(ViewPrepCommand);
return;
}
}
}
Copy the codeThe code is as follows:
package {
import .*;
import .;
import .;
import .;
public class ModelPrepCommand extends SimpleCommand implements ICommand {
//Create Proxy object and register;
public function ModelPrepCommand() {
return;
}
//Called by MacroCommand;
public override function execute(sender:INotification):void {
(new DataProxy());
return;
}
}
}
Copy the codeThe code is as follows:
package {
import .*;
import .;
import .;
import .;
public class ViewPrepCommand extends SimpleCommand implements ICommand {
public function ViewPrepCommand() {
return;
}
// Create Mediators and register them to the View;
public override function execute(sender:INotification):void {
var obj:Main;
obj = () as Main;
(new AlertMediator(obj));
return;
}
}
}
4. Create a Mediator object class to operate specific display layer components (this example is)
Copy the codeThe code is as follows:
package {
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .;
import .;
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 = () as DataProxy;
var t:AppTextField = new AppTextField();
(t);
}
function get main():Main {
return viewComponent as Main;
}
}
}
5. Create a mapping relationship between Command and Notification
Copy the codeThe code is as follows:
package myapp{
import .;
import .;
import .*;
import .*;
import .*;
// MyApp program's Facade class
public class MyappFacade extends Facade implements IFacade {
//Definition Notification constant
public static const STARTUP:String = "startup";
public static const LOGIN:String = "login";
//Factory method for obtaining ApplicationFacade singleton
public static function getInstance():MyappFacade {
if ( instance == null ) {
instance = new MyappFacade( );
}
return instance as MyappFacade;
}
//Register Command and establish a mapping between Command and Notification
override protected function initializeController( ):void {
();
registerCommand( STARTUP, StartupCommand );
}
//Start PureMVC, call this method in the application, and pass a reference to the application itself
public function startup( app:Main ):void {
sendNotification( STARTUP, app );
}
}
}
6. Create the main document class (start naming)
Copy the codeThe code is as follows:
package {
import myapp.*;
import .*;
public class Main extends Sprite {
private var facade:MyappFacade;
public function Main() {
facade = ();
//Execute the start command;
(this);
return;
}
}
}
Maybe I can’t write it clearly, haha~~ If you have any questions, please leave a message to discuss it together!
File packaging download()