File tree Expand file tree Collapse file tree 16 files changed +334
-29
lines changed
org/puremvc/as3/multicore/demos/flex/modularity Expand file tree Collapse file tree 16 files changed +334
-29
lines changed Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<mx : Application
3
+ xmlns:view=" org.puremvc.as3.multicore.demos.flex.modularity.view.components.*"
3
4
xmlns:mx=" http://www.adobe.com/2006/mxml"
4
- xmlns:widgetmakers=" com.widgetmakers.coolwidget.view.components.*"
5
- xmlns:widgetworks=" com.widgetworks.superwidget.view.components.*"
6
- layout=" vertical" >
5
+ pageTitle=" Modularity - A PureMVC AS3 MultiCore Demo"
6
+ paddingTop=" 70" paddingBottom =" 0" paddingRight =" 0" paddingLeft =" 0"
7
+ backgroundGradientColors=" [#325EC0,#FFFFFF]"
8
+ viewSourceURL=" srcview/index.html"
9
+ backgroundColor=" #FFFFFF"
10
+ themeColor=" HaloBlue"
11
+ layout=" vertical"
12
+ creationComplete=" facade.startup(this)"
13
+ >
14
+
7
15
<mx : Script >
8
16
<![CDATA[
9
-
17
+ import org.puremvc.as3.multicore.demos.flex.modularity.ApplicationFacade;
18
+ public static const NAME:String = 'Modularity';
19
+ protected var facade:ApplicationFacade = ApplicationFacade.getInstance( NAME );
10
20
]]>
11
21
</mx : Script >
22
+
23
+ <!-- Widget Shell -->
24
+ <view : WidgetShell id =" widgetShell" />
12
25
13
- <mx : ApplicationControlBar dock =" true" >
14
- <mx : Text text =" Modularity" />
15
- <widgetmakers : CoolWidget id =" w1" />
16
- <widgetworks : SuperWidget id =" w2" />
17
- </mx : ApplicationControlBar >
18
-
26
+ <!-- Widget Canvas -->
27
+ <view : WidgetCanvas id =" widgetCanvas" />
28
+
19
29
</mx : Application >
Original file line number Diff line number Diff line change 1
1
package com.widgetmakers.coolwidget
2
2
{
3
+ import org.puremvc.as3.multicore.interfaces.IFacade ;
4
+ import org.puremvc.as3.multicore.patterns.facade.Facade ;
5
+
3
6
import com.widgetmakers.coolwidget.controller.StartupCommand ;
4
7
import com.widgetmakers.coolwidget.view.components.CoolWidget ;
5
8
6
- import org.puremvc.as3.multicore.interfaces.IFacade ;
7
- import org.puremvc.as3.multicore.patterns.facade.Facade ;
8
9
9
10
public class ApplicationFacade extends Facade implements IFacade
10
11
{
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ package com.widgetmakers.coolwidget.controller
14
14
{
15
15
facade. registerProxy( new CoolWidgetProxy() );
16
16
17
- var app : CoolWidget = note. getBody() as CoolWidget;
18
- facade. registerMediator(new CoolWidgetMediator( app ) );
17
+ var coolWidget : CoolWidget = note. getBody() as CoolWidget;
18
+ facade. registerMediator( new CoolWidgetMediator( coolWidget ) );
19
19
}
20
20
21
21
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ package com.widgetmakers.coolwidget.view
6
6
7
7
import flash.events.Event ;
8
8
9
- import mx.controls.Alert ;
9
+ import mx.controls.Label ;
10
10
11
11
import org.puremvc.as3.multicore.interfaces.IMediator ;
12
12
import org.puremvc.as3.multicore.patterns.mediator.Mediator ;
@@ -29,7 +29,10 @@ package com.widgetmakers.coolwidget.view
29
29
30
30
protected function onProd ( event :Event ):void
31
31
{
32
- mx. controls. Alert . show (coolWidgetProxy. getData (). toString (),"You prodded the Cool Widget!" );
32
+ //mx.controls.Alert.show(coolWidgetProxy.getData().toString(),"You prodded the Cool Widget!");
33
+ var label : Label = new Label ();
34
+ label . text = 'You prodded the Cool Widget!' ;
35
+ coolWidget. widgetShell. addComponent( label );
33
36
}
34
37
35
38
protected function get coolWidget ():CoolWidget
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<mx : Module xmlns : mx =" http://www.adobe.com/2006/mxml"
3
3
implements=" org.puremvc.as3.multicore.demos.flex.modularity.interfaces.IWidget"
4
- creationComplete=" initializeWidget( )"
4
+ creationComplete=" initializeWidget()"
5
5
layout=" absolute" >
6
6
7
7
<mx : Metadata >
8
8
[Event('prod')]
9
9
</mx : Metadata >
10
10
11
-
12
11
<mx : Script >
13
12
<![CDATA[
13
+ import org.puremvc.as3.multicore.demos.flex.modularity.interfaces.IWidget;
14
+ import org.puremvc.as3.multicore.demos.flex.modularity.interfaces.IWidgetShell;
14
15
import com.widgetmakers.coolwidget.ApplicationFacade;
15
16
17
+ // URI for this widget. Must be unique
16
18
protected static const WIDGET_URI:String = "http://widgetmakers.com/CoolWidget/";
19
+
20
+ // Constants for the events this component dispatches.
17
21
public static const PROD:String='prod';
18
22
23
+ // This Widget's reference to the WidgetShell
24
+ public var widgetShell:IWidgetShell;
25
+
26
+ // Set the Widget Shell
27
+ public function setWidgetShell( shell:IWidgetShell ):void
28
+ {
29
+ widgetShell=shell;
30
+ }
31
+
32
+ // The unique key for this widget instance
19
33
public function getWidgetKey():String
20
34
{
21
35
return WIDGET_URI+this.id
22
36
}
23
37
24
- /**
25
- * Startup the widget using the multiton key passed in.
26
- */
38
+ // Initialize the widget using the multiton key passed in.
27
39
public function initializeWidget( ):void
28
40
{
29
- ApplicationFacade.getInstance( getWidgetKey() ).startup(this);
41
+ ApplicationFacade.getInstance( this. getWidgetKey() ).startup( this );
30
42
}
31
43
32
44
]]>
Original file line number Diff line number Diff line change 1
1
package com.widgetworks.superwidget
2
2
{
3
- import com.widgetworks.superwidget.controller.StartupCommand ;
4
- import com.widgetworks.superwidget.view.components.SuperWidget ;
5
-
6
3
import org.puremvc.as3.multicore.interfaces.IFacade ;
7
4
import org.puremvc.as3.multicore.patterns.facade.Facade ;
8
5
6
+ import com.widgetworks.superwidget.controller.StartupCommand ;
7
+ import com.widgetworks.superwidget.view.components.SuperWidget ;
8
+
9
9
public class ApplicationFacade extends Facade implements IFacade
10
10
{
11
11
Original file line number Diff line number Diff line change 10
10
11
11
<mx : Script >
12
12
<![CDATA[
13
+ import org.puremvc.as3.multicore.demos.flex.modularity.interfaces.IWidgetShell;
13
14
import com.widgetworks.superwidget.ApplicationFacade;
14
15
16
+ // URI for this widget. Must be unique
15
17
public static const WIDGET_URI:String = "http://widgetworks.com/SuperWidget/";
18
+
19
+ // Constants for the events this component dispatches.
16
20
public static const POKE:String='poke';
17
21
22
+ // This Widget's reference to the WidgetShell
23
+ public var widgetShell:IWidgetShell;
24
+
25
+ // Set the Widget Shell
26
+ public function setWidgetShell( shell:IWidgetShell ):void
27
+ {
28
+ widgetShell=shell;
29
+ }
30
+
31
+ // The unique key for this widget instance
18
32
public function getWidgetKey():String
19
33
{
20
34
return WIDGET_URI+this.id
Original file line number Diff line number Diff line change
1
+ package org.puremvc.as3.multicore.demos.flex.modularity
2
+ {
3
+
4
+ import org.puremvc.as3.multicore.interfaces.IFacade ;
5
+ import org.puremvc.as3.multicore.patterns.facade.Facade ;
6
+ import org.puremvc.as3.multicore.demos.flex.modularity.controller.StartupCommand ;
7
+
8
+ public class ApplicationFacade extends Facade implements IFacade
9
+ {
10
+
11
+ // Notification constants
12
+ public static const STARTUP : String = 'startup' ;
13
+ public static const ADD_COMP : String = 'addComp' ;
14
+
15
+ public function ApplicationFacade ( key :String )
16
+ {
17
+ super (key);
18
+ }
19
+
20
+ /**
21
+ * Singleton ApplicationFacade Factory Method
22
+ */
23
+ public static function getInstance ( key :String ) : ApplicationFacade
24
+ {
25
+ if ( instanceMap[ key ] == null ) instanceMap[ key ] = new ApplicationFacade( key );
26
+ return instanceMap[ key ] as ApplicationFacade;
27
+ }
28
+
29
+ /**
30
+ * Register Commands with the Controller
31
+ */
32
+ override protected function initializeController ( ) : void
33
+ {
34
+ super . initializeController();
35
+ registerCommand( STARTUP , StartupCommand );
36
+ }
37
+
38
+ /**
39
+ * Application startup
40
+ *
41
+ * @param app a reference to the application component
42
+ */
43
+ public function startup ( app :Modularity ):void
44
+ {
45
+ sendNotification( STARTUP , app );
46
+ }
47
+
48
+
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ package org.puremvc.as3.multicore.demos.flex.modularity.controller
2
+ {
3
+ import org.puremvc.as3.multicore.interfaces.ICommand ;
4
+ import org.puremvc.as3.multicore.interfaces.INotification ;
5
+ import org.puremvc.as3.multicore.patterns.command.SimpleCommand ;
6
+
7
+ import org.puremvc.as3.multicore.demos.flex.modularity.view.WidgetCanvasMediator ;
8
+ import org.puremvc.as3.multicore.demos.flex.modularity.view.WidgetShellMediator ;
9
+
10
+ public class StartupCommand extends SimpleCommand implements ICommand
11
+ {
12
+ override public function execute (note :INotification ):void
13
+ {
14
+
15
+
16
+ var app: Modularity = note. getBody() as Modularity;
17
+ facade. registerMediator( new WidgetShellMediator( app. widgetShell ) );
18
+ facade. registerMediator( new WidgetCanvasMediator( app. widgetCanvas ) );
19
+
20
+ }
21
+
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
1
package org.puremvc.as3.multicore.demos.flex.modularity.interfaces
2
2
{
3
3
/**
4
- * Define an interface for communicating with Widgets .
4
+ * Interface for a Widget .
5
5
* <P >
6
- * This app must define an interface by which we will
7
- * communicate with the widget . What we call 'widgets'
6
+ * This is the API that must be implemented by a
7
+ * Widget . What we are calling 'widgets'
8
8
* in this demo application are Flex Modules, but they
9
9
* could also be Flash based apps using the PureMVC
10
10
* AS3 MultiCore framework.</P >
@@ -16,8 +16,17 @@ package org.puremvc.as3.multicore.demos.flex.modularity.interfaces
16
16
* <P >
17
17
* This will be a unique string. Generally created
18
18
* by adding a unique URI for the widget to the
19
- * id property of the IWidget instance.</P >
19
+ * id property of the IWidget instance.</P >
20
20
*/
21
21
function getWidgetKey ( ):String ;
22
+
23
+ /**
24
+ * Set the Widget's reference to the WidgetShell.
25
+ * <P >
26
+ * The Widget communicates with the rest of the
27
+ * application via the API exposed by the
28
+ * WidgetShell.
29
+ */
30
+ function setWidgetShell ( shell :IWidgetShell ):void ;
22
31
}
23
32
}
Original file line number Diff line number Diff line change
1
+ package org.puremvc.as3.multicore.demos.flex.modularity.interfaces
2
+ {
3
+ import flash.display.DisplayObject ;
4
+
5
+ /**
6
+ * Interface for the WidgetShell
7
+ * <P >
8
+ * This is the API that the WidgetShell
9
+ * exposes to Widgets for communication.
10
+ * Through this interface alone the IWidget
11
+ * is able to communicate its wishes to the
12
+ * application into which it is loaded.</P >
13
+ * <P >
14
+ * Since third-parties may develop widgets
15
+ * to run inside the app, we want to limit
16
+ * their access to the application and its
17
+ * resources.</P >
18
+ *
19
+ */
20
+ public interface IWidgetShell
21
+ {
22
+
23
+ /**
24
+ * A widget may add a view component to the canvas.
25
+ * <P >
26
+ * Though the display object reference is added to
27
+ * the view hierarchy of the app, it is still managed
28
+ * by a mediator running inside the widget itself.</P >
29
+ *
30
+ * @param displayObject to add to the canvas
31
+ */
32
+ function addComponent ( component :DisplayObject ):void ;
33
+
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ package org.puremvc.as3.multicore.demos.flex.modularity.view
2
+ {
3
+ import flash.display.DisplayObject ;
4
+
5
+ import org.puremvc.as3.multicore.demos.flex.modularity.ApplicationFacade ;
6
+ import org.puremvc.as3.multicore.demos.flex.modularity.view.components.WidgetCanvas ;
7
+ import org.puremvc.as3.multicore.interfaces.INotification ;
8
+ import org.puremvc.as3.multicore.patterns.mediator.Mediator ;
9
+
10
+ public class WidgetCanvasMediator extends Mediator
11
+ {
12
+ public static const NAME : String = 'WidgetCanvasMediator' ;
13
+
14
+ public function WidgetCanvasMediator ( viewComponent :WidgetCanvas )
15
+ {
16
+ super ( NAME , viewComponent );
17
+ }
18
+
19
+ override public function listNotificationInterests ():Array
20
+ {
21
+ return [ ApplicationFacade. ADD_COMP ];
22
+ }
23
+
24
+ override public function handleNotification (note :INotification ):void
25
+ {
26
+ switch ( note. getName() )
27
+ {
28
+ case ApplicationFacade. ADD_COMP :
29
+ widgetCanvas. addChild ( note. getBody() as DisplayObject );
30
+ break ;
31
+ }
32
+ }
33
+
34
+ protected function get widgetCanvas ():WidgetCanvas
35
+ {
36
+ return viewComponent as WidgetCanvas;
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ package org.puremvc.as3.multicore.demos.flex.modularity.view
2
+ {
3
+
4
+ import org.puremvc.as3.multicore.patterns.mediator.Mediator ;
5
+
6
+ import org.puremvc.as3.multicore.demos.flex.modularity.ApplicationFacade ;
7
+ import org.puremvc.as3.multicore.demos.flex.modularity.view.components.WidgetShell ;
8
+ import org.puremvc.as3.multicore.demos.flex.modularity.view.events.AddComponentEvent ;
9
+
10
+ public class WidgetShellMediator extends Mediator
11
+ {
12
+ public static const NAME : String = 'WidgetShellMediator' ;
13
+
14
+ public function WidgetShellMediator ( viewComponent :WidgetShell )
15
+ {
16
+ super ( NAME , viewComponent );
17
+ shell. addEventListener ( AddComponentEvent. NAME , onAddComponent );
18
+ }
19
+
20
+ protected function onAddComponent ( event :AddComponentEvent ):void
21
+ {
22
+ sendNotification( ApplicationFacade. ADD_COMP , event. component );
23
+ }
24
+
25
+ protected function get shell ():WidgetShell
26
+ {
27
+ return viewComponent as WidgetShell;
28
+ }
29
+
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments