<?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:screens="screens.*"
minWidth="500" minHeight="400"
width="500" height="400"
initialize="_initializeHandler(event)"
applicationComplete="_applicationCompleteHandler(event)"
viewSourceURL="srcview/index.html">
<s:states>
<s:State name="init" />
<s:State name="roleChoice" />
<s:State name="voteManager" />
<s:State name="voteClient" />
</s:states>
<fx:Script>
<![CDATA[
import controllers.VoteController;
import events.VoteEvent;
import mx.events.FlexEvent;
import netgroup.NetGroupEvent;
protected function _initializeHandler(event:FlexEvent):void
{
var voteCtrl:VoteController = VoteController.instance;
voteCtrl.addEventListener(NetGroupEvent.CONNECTED_TO_GROUP, initDone);
voteCtrl.addEventListener(VoteEvent.ROLE_SET, onRoleSet);
}
protected function _applicationCompleteHandler(event:FlexEvent):void
{
}
protected function initDone(event:Event):void
{
currentState = 'roleChoice';
}
protected function onRoleSet(event:VoteEvent):void
{
switch(VoteController.instance.role)
{
case VoteController.ROLE_CLIENT:
currentState = 'voteClient';
break;
case VoteController.ROLE_MANAGER:
currentState = 'voteManager';
break;
}
}
protected function btnRole_clickHandler(role:String):void
{
VoteController.instance.role = role;
}
]]>
</fx:Script>
<fx:Style source="styles.css" />
<fx:Declarations />
<!--- Initialization process info -->
<s:Group includeIn="init" >
<s:Label text="Connecting..." visible="{!VoteController.instance.connected}"/>
</s:Group>
<s:VGroup
includeIn="roleChoice"
visible="{!VoteController.instance.role}"
horizontalCenter="0" verticalCenter="0"
horizontalAlign="center"
>
<s:Label text="Choose your role "/>
<s:Button id="btnManager"
label="I'm a vote manager" width="250" height="40"
click="btnRole_clickHandler(VoteController.ROLE_MANAGER)"
/>
<s:Button id="btnClient"
label="I'm a vote client" width="250" height="40"
click="btnRole_clickHandler(VoteController.ROLE_CLIENT)"
/>
</s:VGroup>
<!--- Vote Client UI -->
<screens:Client_Vote includeIn="voteClient" />
<!--- Vote Manager UI -->
<screens:Manager_Vote includeIn="voteManager" />
</s:Application>