<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="com.abdulqabiz.utils.*"
layout="absolute"
backgroundColor="#222222"
backgroundGradientColors="[#222222,#222222]"
creationComplete="onCreationComplete()"
viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import flash.net.navigateToURL;
import mx.controls.Alert;
import flash.external.ExternalInterface;
private function onCreationComplete():void{
if(ExternalInterface.available) {
ExternalInterface.addCallback("testForGears",testForGears);
ExternalInterface.call("isGearsInstalled");
}else{
Alert.show("This example needs a browser that supports ExternalInterface");
}
}
private function testForGears(passed:Boolean):void{
if(passed){ currentState = 'gearsPresent';
}else{ currentState = 'gearsNotPresent';
}
}
private function createShortcut():void{
ExternalInterface.call ("createShortcut");
invalidateDisplayList();
}
private function redirectToInstallPage():void{
navigateToURL(new URLRequest("http://gears.google.com/?action=install" +
"&message=Install Gears to checkout Mrinal's Flex Desktop Shortcut example" +
"&return=http://experiments.mrinalwadhwa.com/Gears/FlexDesktopShortcut/FlexGears.html"),"_self");
}
private function viewSource():void{
navigateToURL(new URLRequest("srcview/index.html"));
}
private function moreInfo():void{
navigateToURL(new URLRequest("http://weblog.mrinalwadhwa.com/2008/06/27/flex-and-gears/"),"_self");
}
]]>
</mx:Script>
<JavaScript>
<![CDATA[
// tells the swf if gears is installed
function isGearsInstalled() {
if (window.google && google.gears) { //gears is installed
thisMovie("FlexGears").testForGears(true);
return;
}
//gears is not installed
thisMovie("FlexGears").testForGears(false);
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
// use gears to create a desktop shortcut
function createShortcut() {
var desktop = google.gears.factory.create("beta.desktop");
var description = "This shortcut launches Flex + Gears desktop shortcut example";
var icons = {
"16x16": "assets/icon16.png",
"32x32": "assets/icon32.png",
"48x48": "assets/icon48.png",
"128x128": "assets/icon128.png"
};
desktop.createShortcut("Flex & Gears desktop shortcut example", // name
"FlexGears.html", // url
icons, // icons (must specify at least one)
description); // description (optional)
}
]]>
</JavaScript>
<mx:Style source="styles.css"/>
<mx:states>
<mx:State name="gearsPresent"/>
<mx:State name="gearsNotPresent">
<mx:RemoveChild target="{createShortcutButton}"/>
<mx:AddChild position="lastChild">
<mx:Button label="Install Gears" styleName="install"
horizontalCenter="0" top="150" click="redirectToInstallPage()"/>
</mx:AddChild>
<mx:SetProperty target="{message}" name="text"
value="This sample needs Google Gears to run."/>
</mx:State>
</mx:states>
<mx:Button label="Create Desktop Shortcut"
horizontalCenter="0" top="150"
click="createShortcut()"
id="createShortcutButton"
styleName="shortcut"/>
<mx:Label id="message"
text="Google Gears is installed !"
horizontalCenter="0" top="100"/>
<mx:LinkButton label="View Source" horizontalCenter="0" top="350" click="viewSource()"/>
<mx:LinkButton label="More Info" horizontalCenter="0" top="380" click="moreInfo()"/>
</mx:Application>