xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:generated="<%= base_package %>.components.generated.*" paddingBottom="8" paddingLeft="8" paddingRight="8" paddingTop="8" layout="horizontal" styleName="plain" initialize="init()"> <% if distributed -%> import air.net.SocketMonitor; import org.restfulx.events.PullEndEvent; import org.restfulx.events.PullStartEvent; import org.restfulx.events.PushEndEvent; import org.restfulx.events.PushStartEvent; import org.restfulx.controllers.ChangeController; import org.restfulx.services.ISyncingServiceProvider; <% end -%> import org.restfulx.services.air.AIRServiceProvider; <% end -%> <% if use_gae -%> import org.restfulx.services.http.GAEHTTPServiceProvider; <% else -%> import org.restfulx.services.http.XMLHTTPServiceProvider; <% end -%> import org.restfulx.Rx; import <%= base_package %>.controllers.<%= command_controller_name %>; <% if use_air -%> <% if distributed -%> [Bindable] private var socketMonitor:SocketMonitor; [Bindable] private var online:Boolean; [Bindable] private var syncStatus:String; <% end -%> <% end -%> private function init():void { <% if use_air -%> <% if distributed -%> Rx.httpRootUrl = "http://localhost:3000/"; Rx.enableSync = true; socketMonitor = new SocketMonitor("localhost", 3000); socketMonitor.pollInterval = 2000; /* miliseconds */ socketMonitor.addEventListener(StatusEvent.STATUS, onNetworkStatusChange); socketMonitor.start(); <% end -%> <%= command_controller_name %>.initialize([AIRServiceProvider], AIRServiceProvider.ID, "<%= base_package %>"); <% if distributed -%> <% if use_gae -%> Rx.changes.setSyncProviders( ISyncingServiceProvider(Rx.services.getServiceProvider(AIRServiceProvider.ID)), Rx.services.getServiceProvider(GAEHTTPServiceProvider.ID)); <% else -%> Rx.changes.setSyncProviders( ISyncingServiceProvider(Rx.services.getServiceProvider(AIRServiceProvider.ID)), Rx.services.getServiceProvider(XMLHTTPServiceProvider.ID)); <% end -%> Rx.changes.addEventListener(PushStartEvent.ID, onPushStart); Rx.changes.addEventListener(PushEndEvent.ID, onPushEnd); Rx.changes.addEventListener(PullStartEvent.ID, onPullStart); Rx.changes.addEventListener(PullEndEvent.ID, onPullEnd); <% end -%> <% else -%> <% if use_gae -%> <%= command_controller_name %>.initialize([GAEHTTPServiceProvider], GAEHTTPServiceProvider.ID); <% else -%> <%= command_controller_name %>.initialize(); <% end -%> <% end -%> } <% if use_air -%> <% if distributed -%> private function onPushStart(event:Event):void { syncStatus = "Pushing changes ..."; } private function onPushEnd(event:Event):void { syncStatus = "Push complete."; } private function onPullStart(event:Event):void { syncStatus = "Pulling data..."; } private function onPullEnd(event:Event):void { syncStatus = "Pull complete."; } private function onNetworkStatusChange(event:StatusEvent):void { online = (socketMonitor.available) ? true : false; if (online) { <% if use_gae -%> Rx.defaultServiceId = GAEHTTPServiceProvider.ID; <% else -%> Rx.defaultServiceId = XMLHTTPServiceProvider.ID; <% end -%> } else { Rx.defaultServiceId = AIRServiceProvider.ID; } } private function getCurrentProviderName(id:int):String { switch (id) { <% if use_gae -%> case GAEHTTPServiceProvider.ID: return "GAE"; <% else -%> case XMLHTTPServiceProvider.ID: return "XML/HTTP"; <% end -%> case AIRServiceProvider.ID: return "AIR (SQLite)"; default : return "No idea"; } } <% end -%> <% end -%> ]]> <% if use_air -%> <% if distributed -%> <% end -%> <% end -%> <% for component in component_names -%> /> <% end -%> >