<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" preinitialize="onPreinitialize (event)" applicationComplete="setWindow()" showFlexChrome="false" width="600" height="500" layout="absolute" xmlns:techlabs="com.justinimhoff.techlabs.*" viewSourceURL="srcview/index.html">
<mx:states>
<mx:State name="MAC">
<mx:RemoveChild target="{button1}"/>
<mx:SetStyle target="{userPlatformControl}" name="top" value="50"/>
<mx:SetStyle target="{techLabsFooter}" name="bottom" value="79"/>
<mx:SetStyle target="{techLabsFooter}" name="left" value="40"/>
<mx:SetStyle target="{techLabsFooter}" name="right" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="top" value="79"/>
<mx:SetStyle target="{capabilitiesList}" name="right" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="bottom" value="129"/>
<mx:SetStyle target="{capabilitiesList}" name="left" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="left" value="40"/>
<mx:SetStyle target="{userPlatformControl}" name="left" value="48"/>
<mx:SetStyle target="{label1}" name="fontSize" value="16"/>
<mx:SetStyle target="{label1}" name="fontWeight" value="bold"/>
<mx:SetStyle target="{label1}" name="horizontalCenter" value="0"/>
<mx:SetStyle target="{label1}" name="top" value="40"/>
<mx:SetStyle target="{label1}" name="color" value="#333333"/>
<mx:SetStyle target="{techLabsFooter}" name="verticalAlign" value="middle"/>
<mx:SetProperty target="{techLabsFooter}" name="height" value="51"/>
<mx:SetProperty target="{button2}" name="styleName" value="toolBarButtons"/>
<mx:SetProperty target="{button2}" name="label"/>
</mx:State>
<mx:State name="WIN">
<mx:RemoveChild target="{button2}"/>
<mx:SetStyle target="{userPlatformControl}" name="left" value="40"/>
<mx:SetStyle target="{userPlatformControl}" name="right" value="40"/>
<mx:SetStyle target="{userPlatformControl}" name="top" value="78"/>
<mx:SetStyle target="{techLabsFooter}" name="bottom" value="79"/>
<mx:SetStyle target="{techLabsFooter}" name="left" value="40"/>
<mx:SetStyle target="{techLabsFooter}" name="right" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="top" value="107"/>
<mx:SetStyle target="{capabilitiesList}" name="right" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="bottom" value="129"/>
<mx:SetStyle target="{capabilitiesList}" name="left" value="40"/>
<mx:SetStyle target="{capabilitiesList}" name="left" value="40"/>
<mx:SetStyle target="{techLabsFooter}" name="verticalAlign" value="middle"/>
<mx:SetStyle target="{label1}" name="horizontalCenter" value="0"/>
<mx:SetStyle target="{label1}" name="top" value="40"/>
<mx:SetStyle target="{label1}" name="fontSize" value="16"/>
<mx:SetStyle target="{label1}" name="fontWeight" value="bold"/>
<mx:SetStyle target="{label1}" name="color" value="#FFFFFF"/>
<mx:SetProperty target="{userPlatformControl}" name="styleName" value="toolBar"/>
<mx:SetProperty target="{button1}" name="styleName" value="toolBarButtons"/>
<mx:SetProperty target="{userPlatformControl}" name="height" value="30"/>
<mx:SetProperty target="{button1}" name="height" value="25"/>
<mx:SetProperty target="{techLabsFooter}" name="height" value="51"/>
</mx:State>
</mx:states>
<techlabs:AppWindow width="100%" height="100%" id="appWindow">
<mx:Label text="Native Window Explorer" id="label1"/>
<mx:DataGrid id="capabilitiesList"/>
<mx:HBox id="techLabsFooter" backgroundColor="#333333">
<mx:Image source="@Embed(source='images/logo-trans1.png')" id="techLabsLogo" left="15"/>
</mx:HBox>
<mx:HBox id="userPlatformControl">
<mx:Button label="MAC Style" click="switchPlatform('MAC')" enabled="{platform == 'WIN'}" id="button1"/>
<mx:Button label="PC Style" click="switchPlatform('WIN')" enabled="{platform == 'MAC'}" id="button2"/>
</mx:HBox>
</techlabs:AppWindow>
<mx:Style source="skins/Default.css"/>
<mx:Script>
<![CDATA[
import mx.core.Container;
import mx.controls.Text;
import flash.utils.describeType;
import mx.collections.ArrayCollection;
import mx.events.StyleEvent;
import mx.events.FlexEvent;
import mx.managers.SystemManager;
import mx.events.AIREvent;
import flash.utils.*;
[Bindable]
private var platform:String;
private function onPreinitialize(event:FlexEvent):void {
var findPlatform:Array=Capabilities.version.split(" ", 1);
platform=findPlatform[0];
if (platform != "MAC") {
platform="WIN"
}
var eventDispatcher:IEventDispatcher;
eventDispatcher=StyleManager.loadStyleDeclarations("skins/" + platform + ".swf");
eventDispatcher.addEventListener(StyleEvent.COMPLETE, onStyleComplete);
}
override public function set initialized(value:Boolean):void {
}
private function onStyleComplete(event:StyleEvent):void {
event.stopImmediatePropagation();
super.initialized=true;
}
private function setWindow():void {
appWindow.os=platform;
currentState=platform;
nativeWindow.x=Capabilities.screenResolutionX / 4;
nativeWindow.y=Capabilities.screenResolutionY / 4;
addEventListener(AIREvent.APPLICATION_ACTIVATE, setApplicationFoucs);
addEventListener(AIREvent.APPLICATION_DEACTIVATE, setApplicationFoucs);
printCapabilities(Capabilities);
}
private function setApplicationFoucs(event:AIREvent):void {
event.stopImmediatePropagation();
if (event.type == "applicationDeactivate") {
appWindow.active=false;
} else {
appWindow.active=true;
}
}
private function printCapabilities(o:Object):void {
var def:XML=describeType(o);
var props:XMLList=def..variable.@name;
props+=def..accessor.@name;
var capArray:Array=new Array();
for each (var prop:String in props) {
var capObj:Object=new Object();
capObj.propName=prop;
capObj.propValue=o[prop]
capArray.push(capObj);
}
capabilitiesList.dataProvider=capArray;
}
private function switchPlatform(os:String):void {
StyleManager.loadStyleDeclarations("skins/" + os + ".swf");
appWindow.os=os;
platform=os;
currentState=os;
}
]]>
</mx:Script>
</mx:WindowedApplication>