Category Archives: Flex

Adobe Flex Framework

My blog has a new home

Written by Garry Lachman (Admin). Filed under Flex. .

After a long time that my blog suffered from a slow and down times at GoDaddy.
I`m happy to announce that we found new home at XLHost.

Sooo…
We Are Back !!!

Share

Simple MVC in ActionScript 3

Written by Garry Lachman (Admin). Filed under ActionScript 3, Flex. Tagged , , , , , , , , , , , . .

I always used to apply this pattern in most simple way.
Its help me to create few view states use same functionality.

First i create interfaces to Module, Controller and View state:

1
2
3
4
5
6
//Module Interface
package {
flash.events.IEventDispatcher;
public interface IModule extends IEventDispatcher {
}
}
1
2
3
4
5
//Controller Interface
package {
public interface IController {
}
}
1
2
3
4
5
//View Interface
package {
public interface IView {
}
}

Than lets create the MVC:

1
2
3
4
5
6
7
8
9
//Module
package {
flash.events.EventDispatcher;

public class TestModule extends EventDispatcher implements IModule {
public function TestModule(){
}
}
}
1
2
3
4
5
6
7
8
9
10
//Controller
package {
public class TestController implements IController {
private var testModule:IModule;

public function TestController(_module:IModule){
testModule = _module;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//View
package {
import flash.display.Sprite;

public class TestView extends Sprite implements IView {
private var testModule:IModule;
private var testController:IController;

public function TestController(_controller:IController, _module:IModule){
testController = _controller;
testModule = _module;
}
}
}

Now lets connect them all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Test MVC
package {
import flash.display.Sprite;

public class TestApp extends Sprite {

public function TestApp(){
var testModule:IModule = new TestModule();
var testController:IController = new TestControler(testModule);
var testView:IView = new TestView(testController, testModule);
addChild(testView as Sprite);
}
}
}

Share