Swfobject 2.1 Flex template. HistoryManager and DeepLinking supported as well

[UPDATE] I've updated template to SWFObject 2.1
And there is a bit smarter way to register flexApplication with BrowserHistory:

var flashvars = {
name1: "hello",
name2: "world",
name3: "foobar"
};
var params = {
menu: "false"
};
var attributes = {
id: "${application}",
name: "${application}"
};

swfobject.embedSWF ( "${swf}.swf", "${application}_div", "${width}", "${height}", "${version_major}", "expressInstall.swf", flashvars, params, attributes );
swfobject.addLoadEvent(loadEventHandler);
function loadEventHandler() {
BrowserHistory.flexApplication = swfobject.getObjectById("${application}");
}



I have been using Geoff Stearns' SWFObject for a long time. I think it will be useful to share my index.template.html that tuned for using with SWFObject 2 2.1. I was inspired with Ted Patrick's FXWidget project that uses SWFObject 1.5 for embedding flex content to html page. So now it supports HistoryManager and DeepLinking.
I've made few little changes in history.js to let content embed with SWFObject work with HistoryManager and Deeplinking - I've replaced 'embed' with 'object' at lines 115 and 131 due to the fact that
SWFObject's base markup uses the nested-objects method.

Project Archive [updated - 07-07-2008] ( broken link has been fixed)


Have fun with it!
Cheers!

Air update manager

I had to implement update mechanism into one of my Air applications. After searching in Flex help and googling the only reasonable solution I've found was one from Rich Tretola (everythingflex.com). It is really easy to use library but with that simplicity I missed some freedom while using it:

  1. no events - main application that uses Rich's UpdateManager doesn't know if update required or not, if UpdateManager started downloading update etc...
  2. notifying user about update file downloading progress
So I've decided to write my own UpdateManager and there is the result:
The API is quite simple
  1. Constructor has 3 arguments
    1. _versionXmlUrl: String
    2. autoUpdate: Boolean = true ( optional)
    3. autoCheck: Boolean = false (optional)
  2. Public methods:
    1. checkForUpdate (): void
    2. update (): void
  3. Events:
    1. public static const EVENT_UPDATE_AVAILABLE: String;
    2. public static const EVENT_UPDATE_DOWNLOAD_STARTED: String;
    3. public static const EVENT_UPDATE_DOWNLOAD_COMPLETE: String;
    4. public static const EVENT_UPDATE_DOWNLOAD_PROGRESS: String;
    5. public static const EVENT_UPDATE_NOT_REQUIRED: String;
    6. public static const EVENT_UPDATE_FAULT: String;
  4. Read only properties:
    1. get currentVersionString (): String
    2. get newVersionString (): String
    3. get updateType (): String - critical, major, minor
    4. get updateMessage (): String
    5. get bytesLoaded (): int
    6. get bytesTotal (): int

Simple (silent update) example:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="doInit ()"/>

<mx:Script>
<![CDATA[
import com.cloud17.air.managers.UpdateManager;

private var um: UpdateManager;

private function doInit(): void
{
um = new UpdateManager ( "http://mysite.com/air/getlatestversion.xml", true, true );
um.addEventListener ( UpdateManager.EVENT_UPDATE_FAULT, start );
um.addEventListener ( UpdateManager.EVENT_UPDATE_NOT_REQUIRED, start );

}

private function start ( evt: Event = null ): void
{
//main app logic
}
]]>
</mx:Script>
<mx:WindowedApplication>


Complex example:
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="doInit ()"/>
<mx:Script>
<![CDATA[
import com.cloud17.air.managers.UpdateManager;
import com.justversus.controls.ProgressWindow;
import com.justversus.utils.Prompt;
import mx.managers.PopUpManager;

private var um: UpdateManager;
private var progressWindow: ProgressWindow;

private function doInit(): void
{
um = new UpdateManager ( "http://mysite.com/air/getlatestversion.xml", false, true );
um.addEventListener ( UpdateManager.EVENT_UPDATE_AVAILABLE, updateAvailableHandler );
um.addEventListener ( UpdateManager.EVENT_UPDATE_DOWNLOAD_STARTED, updateDownloadStartedHandler );
um.addEventListener ( UpdateManager.EVENT_UPDATE_DOWNLOAD_PROGRESS, updateDownloadProgressHandler );
um.addEventListener ( UpdateManager.EVENT_UPDATE_DOWNLOAD_COMPLETE, updateDownloadCompleHandler );
um.addEventListener ( UpdateManager.EVENT_UPDATE_FAULT, start );
um.addEventListener ( UpdateManager.EVENT_UPDATE_NOT_REQUIRED, start );

}

private function updateAvailableHandler ( evt: Event ): void
{
Prompt.show( "You have installed " + um.currentVersionString + " version of application. \n" +
"Would you like to update your application to " + um.newVersionString + "?\n\n" + um.updateMessage,
"New version available -- " + um.newVersionString, doUpdate );
}

private function doUpdate(): void
{
um.update();
}


private function updateDownloadStartedHandler ( evt: Event ): void
{
progressWindow = PopUpManager.createPopUp ( this, ProgressWindow, true ) as ProgressWindow;
progressWindow.title = "Updating application...";
PopUpManager.centerPopUp( progressWindow );
}

private function updateDownloadCompleHandler ( evt: Event ): void
{
PopUpManager.removePopUp( progressWindow );
}

private function updateDownloadProgressHandler ( evt: Event ): void
{
progressWindow.setProgress ( um.bytesLoaded, um.bytesTotal );
}



public function start( event: Event = null): void
{
//do some application logic

}
]]>
</mx:Script>
<mx:WindowedApplication>

Feel free to use it...