forked from joelhooks/robotlegs-examples-ModularDoodads
/
ModularDoodads.mxml
109 lines (95 loc) · 3.84 KB
/
ModularDoodads.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:modulardoodads="robotlegs.examples.modulardoodads.*"
xmlns:logger="robotlegs.examples.modulardoodads.modules.logger.*"
width="450" height="700" xmlns:doodad="robotlegs.examples.modulardoodads.modules.doodad.*" xmlns:view="robotlegs.examples.modulardoodads.view.*">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.IVisualElement;
import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;
import mx.modules.ModuleManager;
import robotlegs.examples.modulardoodads.common.events.LoggingEvent;
import robotlegs.examples.modulardoodads.common.events.ModuleCommandTriggerEvent;
// This is only a linkage so the LoggingEvent class gets compiled into the main swf.
// If this isn't linked into the main swf an error will be thrown.
protected var loggingEventLinkage:LoggingEvent;
protected var info:IModuleInfo;
protected function addDoodad_clickHandler(event:MouseEvent):void
{
if (createModuleInfo())
{
info.load(ApplicationDomain.currentDomain, null, null, moduleFactory);
}
}
protected function createModuleInfo():Boolean
{
if (!info)
{
info = ModuleManager.getModule('robotlegs/examples/modulardoodads/modules/doodad/DoodadModule.swf');
info.addEventListener(ModuleEvent.READY, moduleInfo_readyHandler);
info.addEventListener(ModuleEvent.ERROR, moduleInfo_errorHandler);
return true;
}
return false;
}
protected function destroyModuleInfo():void
{
if (info)
{
info.removeEventListener(ModuleEvent.READY, moduleInfo_readyHandler);
info.removeEventListener(ModuleEvent.ERROR, moduleInfo_errorHandler);
info = null;
}
}
protected function moduleInfo_readyHandler(event:ModuleEvent):void
{
doodadHolder.addElement(info.factory.create() as IVisualElement);
destroyModuleInfo();
}
protected function moduleInfo_errorHandler(event:ModuleEvent):void
{
Alert.show(event.errorText);
destroyModuleInfo();
}
public function setFocusOnAddDoodadButton():void
{
focusManager.setFocus(addDoodad);
}
protected function triggerCommand_clickHandler(event:MouseEvent):void
{
dispatchEvent(new ModuleCommandTriggerEvent(ModuleCommandTriggerEvent.TRIGGER_MODULE_COMMAND));
}
]]>
</fx:Script>
<fx:Declarations>
<modulardoodads:ModularDoodadsContext contextView="{this}"/>
</fx:Declarations>
<s:layout>
<s:VerticalLayout paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5"/>
</s:layout>
<s:HGroup width="100%">
<s:Button id="addDoodad" label="Add a Doodad" click="addDoodad_clickHandler(event)"/>
<s:Button id="triggerCommand" label="Trigger" click="triggerCommand_clickHandler(event)"/>
</s:HGroup>
<s:Scroller width="440" height="100%" horizontalScrollPolicy="off">
<s:Group height="100%" width="440">
<s:Group id="doodadHolder" width="440">
<s:layout>
<s:TileLayout />
</s:layout>
</s:Group>
<s:Rect width="100%" height="100%">
<s:stroke>
<s:SolidColorStroke color="#C7C7C7"/>
</s:stroke>
</s:Rect>
</s:Group>
</s:Scroller>
<mx:ModuleLoader url="robotlegs/examples/modulardoodads/modules/logger/LoggerModule.swf"
applicationDomain="{ApplicationDomain.currentDomain}" width="100%"
error="Alert.show(event.errorText)"/>
</s:Application>