The Flash Player contains a number of APIs for handling collision detection within Flash content. The DisplayObject class contains hitTest and hitTestPoint which can be useful if you need to detect bounding box collisions, or detect collisions between an individual point and bounding boxes or shapes.
However, BitmapData also contains a hitTest API, which can check collisions on BitmapData. Where the API really shines, is when you need to detect collisions between the visible areas of DisplayObjects (and not just of their bounding boxes). The API contains functionality for testing collisions between BitmapData and a Point, BitmapData and a Rectangle, and BitmapData and another BitmapData. It is the last item that I will focus on in this post.
Since you can get BitmapData from a DisplayObject the API can be used to detect very exact collisions between the visible areas of DisplayObjects, even if the DisplayObjects have irregular shapes.
Here is a simple example that uses the API to detect collisions between the visible areas of two MovieClips using BitmapData.hitTest.

And here is the code
var redRect:Rectangle = redClip.getBounds(this); var redClipBmpData = new BitmapData(redRect.width, redRect.height, true, 0); redClipBmpData.draw(redClip); var blueRect:Rectangle = blueClip.getBounds(this); var blueClipBmpData = new BitmapData(blueRect.width, blueRect.height, true, 0); blueClipBmpData.draw(blueClip); addEventListener(Event.ENTER_FRAME, enterFrame); function enterFrame(e:Event):void { blueClip.x = mouseX; blueClip.y = mouseY; if(redClipBmpData.hitTest(new Point(redClip.x, redClip.y), 255, blueClipBmpData, new Point(blueClip.x, blueClip.y), 255 )) { trace("hit"); redClip.filters = [new GlowFilter()]; } else { redClip.filters = []; } }
Basically, the content contains two MovieClips on the timeline. We draw the graphics for each MovieClip into a BitmapData instance, and then use the BitmapData.hitTest API to see if the visible parts of the MovieClip (non-transparent) instances collide.
Couple of notes on the example:
1. The initial fill for the BitmapData is transparent pixels. This is necessary to detect just the visible areas of the DisplayObject.
2. The Point instances passed to hitTest are used to align the BitmapData instances for the comparisons.
This example works regardless of the contents or shape of the DisplayObjects. However, if either of the DisplayObjects have had any transformations applied to them (such as rotation), then the collision detection wont work correctly.
In order to get it to work, you need to apply a Matrix when drawing the BitmapData to account for the transformation applied to one or both DisplayObjects. If you haven’t worked with Matrices and DisplayObject transformations, this can be a little daunting at first (it was for me). If you are new to using Matrices, I suggest reading this excellent article on Matrices in Flash over at senocular.com.
Luckily for me, Trevor McCauley, who runs senocular.com, also happens to works for Adobe on the Flash Player team. He really helped me understand how how to get the hit detection to work when the DisplayObjects have had transformations applied to them.
Here is the example:

and the code:
addEventListener(Event.ENTER_FRAME, enterFrame); function enterFrame(e:Event):void { blueClip.x = mouseX; blueClip.y = mouseY; redClip.rotation++; var blueRect:Rectangle = blueClip.getBounds(this); var blueOffset:Matrix = blueClip.transform.matrix; blueOffset.tx = blueClip.x - blueRect.x; blueOffset.ty = blueClip.y - blueRect.y; var blueClipBmpData = new BitmapData(blueRect.width, blueRect.height, true, 0); blueClipBmpData.draw(blueClip, blueOffset); var redRect:Rectangle = redClip.getBounds(this); var redClipBmpData = new BitmapData(redRect.width, redRect.height, true, 0); var redOffset:Matrix = redClip.transform.matrix; redOffset.tx = redClip.x - redRect.x; redOffset.ty = redClip.y - redRect.y; redClipBmpData.draw(redClip, redOffset); var rLoc:Point = new Point(redRect.x, redRect.y); var bLoc:Point = new Point(blueRect.x, blueRect.y); if(redClipBmpData.hitTest(rLoc, 255, blueClipBmpData, bLoc, 255 )) { trace("hit"); redClip.filters = [new GlowFilter()]; } else { redClip.filters = []; } blueClipBmpData.dispose(); redClipBmpData.dispose(); }
Note that we use the bounds of each DisplayObject to determine the BitmapData size and not the height / width of the DisplayObject. This is because the transformation will most likely modify the bounds, and we need to take this into account. In the first example, we could have just used the height and width of the DisplayObjects since they were the same as the bounds, but in general you should get in the habit of using the bounds.
We also pass a Matrix to each BitmapData.draw call to account for any transformations that may have been applied to the DisplayObjects (in this case rotations). I could try and explain what the Matrix is doing, but to be honest, im still trying to get my head around it. Instead, Ill let Trevor explain it (from an email he sent to me):
For this you need the transformation of the object as defined by DisplayObject.transform.matrix. Since everything is in the same container, we still won’t have to worry about walking up hierarchies to get contcatenated/global matrices – we can just use that which is directly applied to the target object (transform.matrix). This gives you the full transform of that object. But for the purposes of capturing a bitmap, we only want the non-translation parts of that transform. This is because when a bitmap is captured, it’s captured from the 0,0 location in the coordinate space of the captured object outward into positive space. The translation of the matrix of the desired object is its position in its parent coordinate space, not its own. HOWEVER, if that object’s own 0,0 location is within the middle of its graphic elements, drawing it into a Bitmap directly from 0,0 could cause cropping. So in terms of that translation as it is to be used with BitmapData.draw(), it’s still important to make sure everything in the target object is captured. And in doing that, it means shifting everything that would appear in negative coordinate space over into positive coordinate space.
Luckily, using getBounds (again) this is quite simple. We can use getBounds to determine the bounds of an object in its parent coordinate space – this includes its transformations. We also know the location of 0,0 within the parent coordinate space because that is the same location it places the target object using its x and y properties. With that, we can get the needed bitmap translation by simply subtracting the bounds x,y from the object’s own x,y. In code that essentially becomes
var b = t.getBounds(t.parent);
var m = t.transform.matrix;
m.tx = t.x – b.x;
m.ty = t.y – b.y;
var bmp = new BitmapData(b.width, b.height, true, 0);
bmp.draw(t, m);
where ‘t’ is the target display object.
Now, I will be the first to admit that I am still wrapping my head around some of this stuff, especially with the use of the Matrices to offset the transformation. However, the second example above is generic and robust enough to be used for general pixel perfect collision detection on visible portions of DisplayObjects.
One note, is that the examples above assumes that the items being compared share the same parent. If they don’t you need to make some additional adjustments (to take into consideration other transformations), but that is a post for another day.
Btw, if you don’t already, you need to read senocular.com. This is one of the best resources on understanding ActionScript 3 and the Flash Player.
Update : One optimzation which you can make is to first check if the bounding boxes of the DisplayObjects overlap (using DisplayObject.hitTestObject), and only if they do, use BitmapData.hitTest to see if their visible areas are touching.
"Supported Operating Systems: Windows Server 2003 Service Pack 2; Windows Server 2008; Windows Vista Service Pack 1; Windows XP Service Pack 3"
The client also supports a range of SQL database versions....
"Microsoft SQL Server 2008 Native Client (SQL Native Client) is a single dynamic-link library (DLL) containing both the SQL OLE DB provider and SQL ODBC driver. It contains run-time support for applications using native-code APIs (ODBC, OLE DB and ADO) to connect to Microsoft SQL Server 2000, 2005, or 2008"
Support tells me that there's only two ways to manage the updates on ESXi embedded systems, using the "VMware Infrastructure Update" application (which requires manually logging into each and every ESXi host), or using some command-line tool. This, frankly, seems insane to me considering the Update Manager seems to be orders of magnitude more powerful in terms of what it can do, and I can't picture ESXi users being forced to do things "the very hard way" like that.
Does anyone have experience with this they'd like to share? I'm beginning to get very frustrated....
Cheers,
Derek
In continuation to the Library VMware Icons and Diagrams posted on VIOPS recently several people have made requests for using these wonderful graphics for designing Visio documents. These are the same Graphics from the official VMware Branding Team.
20/March/08 - Small Icons now available for documentation - Small VMware Icons
Intended Audience
Virtualization professionals that need to present documents and designs.
Outline
The Stencils have been separated into groups
ThinApp-Stencil- Objects for ThinApp
Build your Own-Stencil - Stand-alone objectsto create your own diagrams
VM-STencil - Objects that are related Virtual Machines
VMware-Stencil - General Objects for VMware
Products-Stencil - Diagrams and objects that are related to VMware products or technologies
Method
1. Download the Attached Files below.
2. Extract the Stencils from both files.
3. Open Visio and open the all the Stencils.
4. Use the Stencils to create a visio diagram of your infrastructure
Resources
This doc on the web @ VMware Icons and Diagrams - Visio Stencils
Original PowerPoint Presentation with Graphics - Library VMware Icons and Diagrams.
Visio Stencils Bundle - 1 (zip file) for your use - Attached to this document.
Small VMware Icons
Author
Stencils Created and sorted by Maish Saidel-Keesing
All Graphics are from - VMware Corporate Branding
VMware (NYSE: VMW) is the global leader in virtualization solutions from the desktop to the datacenter. Customers of all sizes rely on VMware to reduce capital and operating expenses, ensure business continuity, strengthen security and go green. With 2008 revenues of $1.9 billion, more than 130,000 customers and more than 22,000 partners, VMware is one of the fastest-growing public software companies. Headquartered in Palo Alto, California, VMware is majority-owned by EMC Corporation (NYSE: EMC). For more information, visit www.vmware.com.
Disclaimer
You use this proven practice at your discretion. VMware and the author do not guarantee any results from the use of this proven practice. This proven practice is provided on an as-is basis and is for demonstration purposes only.
These graphics have not been optimized for Visio. They are not vector-based and are not guaranteed to resize at best quality.
I finally got around to trying out the new hardware overlay support in Windows 7:
http://msdn.microsoft.com/en-us/library/dd797814(VS.85).aspx
Hardware overlays are a quirk of video hardware that have survived in spite of their lack of evolution. They're essentially a secondary display scan out path in the video chip and are intended for video display, so that a video in a window can use a more optimized display format instead of the rest of the desktop for better playback performance. The biggest advantages of a hardware overlay are hardware accelerated scaling and color conversion from YCbCr to RGB, formerly very expensive operations; in some cases, you also got primitive deinterlacing and some additional TV-out support. Unfortunately, they were often also buggy in drivers. Windows Vista appeared to be the end of the line for overlays, as they were not supported in desktop composition mode, but guess what... they're back in Windows 7. As it turns out, hardware overlays are still valuable for a couple of reasons, one being that you can flip them faster and asynchronously from the composited desktop (good for performance) and because you can't capture their image in a screen grab operation (good for the paranoid). And this time, they have a few improvements, too.
The way you get to overlays is a bit different in Windows 7. In older versions, they were a feature of DirectDraw, and that meant you basically couldn't do anything other than lock-and-load -- DirectDraw couldn't even do color conversion, other than what the hardware overlay itself supported. This time, they're hooked up to Direct3D, which makes them a lot more useful since you can process video through DXVA and shader hardware and push the result into the overlay. The color space is now better defined, as there are flags for whether RGB output is computer RGB (0-255) or studio RGB (16-235), and whether YCbCr output is Rec.601/709 or xvYcc. So far, so good -- time to try it!
Now, it's not easy to get VirtualDub talking to the new overlays yet, for two reasons: the existing overlay code uses DirectDraw, and the Direct3D path only supports D3D9, whereas you need Direct3D9Ex in order to use the overlays. Therefore, I ended up just writing a one-off application to test it. Well, having gotten overlays to work and tested them a bit, I have to say they're a bit underwhelming. The good news:
Now, the bad news:
Disclaimer: I used Windows 7 RC for testing, since I don't have RTM.
So, what do we have at this point? Well, you can create a non-stretched RGB overlay with regular 0-255 range. That means unless you are either in a situation where you are being hampered by a low desktop composition rate or you need to prevent your image from being grabbed, it's unlikely that the overlay will have any advantages over plain blitting to the desktop. And of course, you need to use Direct3D9Ex to access them, which is juuuust different enough from regular Direct3D9 to be annoying. The situation might get better over time, and it may just be my crappy video card... but I'll wait until I actually see improvement.
If anyone wants to experiment with WDDM 1.1 overlays, here's the code I used to test them: d3doverlay.cpp. It's obviously not production code, but I assume if you're trying to build it you have some familiarity with setting up a project and with D3D9.
typetext/htmlbasehttp://virtualdub.org/blog/pivot/entry.php?id=282I was working on a project recently, where I wanted to offer the user some fine grained control over transformation of display objects. A quick search led me to Green Sock, run by Jack Doyle. What can I say other than that Jack has tweening libraries for every flavor project and task. He also has a transform manager library, which at the time was only ActionScript 2. After an email exchange, Jack graciously provided me with an advance copy of his ActionScript 3 code base. That ActionScript 3 version is now done and you can purchase a license by heading over to the Green Sock web site.
(more?)
Wallace Tait has just posted a review on his Visualmapper blog: http://visualmapper.blogspot.com/2010/04/novamind-5-wow.html
Wallace is a well known information management specialist, and expert in all forms of visual mapping tools. He says:
Gideon King, the creator of NovaMind delivers an awesome and totally new framework for version 5. It delivers numerous new tools, methods and expands upon the mindset associated with NovaMind.
The information manager of this century now has a Mind mapping product in NovaMind 5 that is graphically sophisticated, extremely professional and effective to the nth degree.
I really do believe NovaMind 5 raises the bar for professional Mind mapping, and the many competing benchmarks in this arena are being eclipsed by this latest release.
Head on over to his blog to see the full review.
typetext/htmlbasehttp://feeds2.feedburner.com/NovamindNews
Before I get to the point let me remind you about previous word on catalogues, where I’ve covered most of general informations about where to find packages I’m writing about. I will also remind that applications from extras-devel and extras-testing are there because they’re not completely ’safe’ for your N900. This time I will give you step-by-step tutorial how to add them to your device. This thing was mentioned here and there many times, but some of you may have missed it.
First of all run your App manager as usual. Then open menu from toolbar and choose Application catalogues option, which will give you possibility to add new software download sources.

App manager menu
When you have it opened look if you already have extras catalogue, should be installed by default but may be disabled.

Catalogues list in App manager

Catalogue details in App manager
Open catalogue settings and uncheck Disabled field. If you don’t have this catalogue(s) add new with one of following settings:
For extras:
Catalogue name: Maemo Extras
Web address: http://repository.maemo.org/extras/
Distribution: fremantle
Components: free non-free
For extras-testing:
Catalogue name: Maemo Extras-Testing
Web address: http://repository.maemo.org/extras-testing/
Distribution: fremantle
Components: free non-free
For extras-devel:
Catalogue name: Maemo Extras-Devel
Web address: http://repository.maemo.org/extras-devel/
Distribution: fremantle
Components: free non-free
You can check weather package you’re looking for is available in extras, extras-testing or extras-devel using maemo.org Package Interface, which I’ve mentioned before. Just type word from package name and examine findings, package details will give you clue on where to look releases of what you need.

maemo.org Package Interface
From now on I will try to include link to this tutorial every time I post info on extras-testing or extras-devel packages, I hope it will help you.
–
Please visit Nokia N900 Forum
Related Posts:Hi,
Today I’m going to talk a little more about PowerShell by answering some of the frequently asked questions I hear.
1) Why is PowerShell better?
2) How do I get started using PowerShell?
3) Where are the properties?
4) Where are the private properties?
5) How do I enable CSV?
1) Why is PowerShell better?
To get you excited I will talk about some cool stuff in our cmdlets. When you compare the functionality to that of Cluster.exe you will see that PowerShell is much better. All the pointers below could be topic in themselves, so for now I am not getting into details.
1) Failover Cluster Manager has been liked by many users, and the best part of cluster administrator is its simplicity of use, including wizards which walk you through many common operations.
However our cmdlets do not show any GUI or wizards, they are purely CLI and scriptable.
What is my point? Well we have tried to provide the Failover Cluster Manager type of experience in PowerShell. For now, I would leave this for you to discover what I am talking about :)
2) Running Validation. Using PowerShell cmdlets you can run the “Validate a Configuration…” wizard on a clusters or unclustered nodes. This even gives you the ability to run validation directly on Core installations.
3) We have many cmdlets to manage VMs, including live migration. Yes, I am talking about writing PowerShell ccripts to live migrate VMs. How cool is it to have a script which runs every few seconds or minute to monitor the cluster and its health, and based on some conditions re-balance the resources by live migrating VMs to different nodes.
4) If I am talking about VMs, I do need to mention CSV. I have already talked about how to enable CSV in PowerShell, but apart from that we do have a set of cmdlets to manage CSV disks.
5) Creating roles have been simplified through PowerShell cmdlets. For this release we have one line cmdlet to create roles (look at the Add-Cluster*role cmdlets).
6) We also have exposed a cmdlet to generate dependency report that can be saved. This allows you to render dependency reports directly on Core installations.
2) How do I get started using PowerShell?
I guess this might not be new to some of you, but I want to make sure that I have it in this article, so that you do not have to search for it. There are two ways to enable PowerShell.
1) In the Windows Server 2008 R2 Release Candidate (RC) build and later, there will be a ‘Windows PowerShell Modules’ link under your Administrative Tools which will automatically import all the PowerShell modules for features or roles which you have installed. It even runs it as an Administrator for you by default, so you don’t need to elevate the permissions every time.
You can then immediately start using Failover Clustering (or Network Load Balancing NLB) PowerShell cmdlets in the command prompt.
The RC build is available here: http://technet.microsoft.com/en-us/dd362341.aspx
2) To be able to use PowerShell cmdlet's you need to run PowerShell in Administrative Mode and run below cmdlet
Import-Module FailoverClusters
My suggestion would also be to create a default profile for yourself and have this line added, so that the module gets loaded every time you open a PowerShell Windows. In Windows Server 2008 R2, you do have the option to open a PowerShell Window and import all the modules on the machine.
Please note that modules are loaded in a session and will only remain while the session exists.
I have always found the output of the below command helpful. This makes a table of cmdlets with cluster cmdlet name and a synopsis/description. The description is pulled from the Help content of the cmdlet.
Feel free to modify this simple cmdlet to extract the information that you would need:
Get-Command -Module FailoverClusters | %{Get-Help $_.Name} | ft Name,Synopsis –Wrap
For Network Load Balancing, use NetworkLoadBalancingClusters
3) Where are the properties?
The cluster objects are: cluster node, cluster group, cluster resource, cluster network, cluster network interface, resource types and the cluster, itself. As I mentioned earlier our cmdlets are action oriented and you would be performing these actions on any of the above listed cluster objects. Most of the cmdlets expect to return a cluster object back.
These objects are the container of their own properties.
So for example, let say you want to see the property of a resource. Using cluster.exe you would type:
Cluster.exe res <Resource Name> /prop
To get the same data from Cluster PowerShell cmdlets you would
Get-ClusterResource <Resource Name> | Format-List *
Get-ClusterResource returns a ClusterResource object. This object contains all the pre-defined properties of the resource. But if you just type
Get-ClusterResource <Resource Name>
You would only see some selected information about the resource on the output screen like resource name, resource group, resource state and resource type. Also keep in mind the object that the cmdlet returns contains additional information which is hidden by default.
When you pipe the out of Get-ClusterResource to Format-List , the Format-List cmdlet takes the object and displays it as a list. The second parameter to Format-List cmdlet '*' will show all values, thus you get to see all the properties of the ClusterResource object as a table of Property Name and Value. You may also type ‘fl’ instead of ‘Format-List’.
So how do you modify the Value of these properties?
There are various ways to do this. You can either cache the object, access the property name and set new value for the property, or you can do the same thing on the fly, without caching it.
For example Let say you want to change the RestartDelay property of a resource. You would use:
$res = Get-ClusterResource <resource Name>
$res.RestartDelay=<new value>
And you are done.
You can present a counter argument that I can do the same with Cluster.exe and it is as simple as:
Cluster.exe res <resource name> /prop <propertyname>=<value>
I agree with you. But how easy is it to do this for all the resource on your cluster? The power of PowerShell helps us here. The below example would update a property of all the resource
Get-ClusterResource | For-Each { $_.<PropertyName>=<NewValue>}
What if you only wanted to change the value of property for specific resource type and not on all resource?
Yes, PowerShell does provide you with filtering options and you would be writing something like:
Get-ClusterResource | where-object { $_.ResourceType -ilike "<resourcetype" } | for-each { $_.<Property Name>=<value>}
Isn't that neat and simple? This is where you get the power of PowerShell with its rich language (both cmdlet’ing and scripting).
4) Where are the private properties?
Private properties? Well for now we would use cluster parameters to refer private properties. Let’s not get into the discussion of why they’re called cluster parameters and why not private properties. We’ll leave that for another blog :).
One of the unusual things about cluster parameters is that they are dynamic. The properties can be added or removed. Another challenge is with the data type of these properties and the way cluster keeps this information.
For now, let’s focus on Get-ClusterParameter and Set-ClusterParameter. Get-ClusterParameter is equivalent to /priv parameter in Cluster.exe
If you are interested in looking at the parameters of a resource, you use
Get-ClusterResource <resource name>| Get-ClusterParameter
The above cmdlet would list all the parameters of the given resource.
To Change the value of a parameter, enter
Get-ClusterResource <resource name> | Set-ClusterParameter -Name <parameter name> -Value <new value>
5) How do I enable CSV?
We do not have any cmdlets which enable Cluster Shared Volumes (CSV). Please do not misunderstand me, I am not saying that we cannot enable CSV feature from PowerShell.
Cluster objects have a property that controls enabling and disabling of CSV. In Failover Cluster Manager there is actually no way to disable CSV.
To enable CSV on a cluster using PowerShell cmdlets, use
$clus = Get-Cluster <cluster name>
$clus.EnableSharedVolume="Enabled"
The above cmdlet would not enable the CSV feature, but rather it should show you the terms and restrictions associated with using CSV. You will want to read these terms to better understand how and when CSV should be used.
For other CSV-related cmdlets, try
Get-Command -CommandType cmdlet *ClusterSharedVolume
Thanks,
Vikas Kumar
Software Development Engineer in Test
Clustering & High Availability
Microsoft

THQ has announced Chaos Rising, the next standalone expansion pack for Dawn of War 2. It will be released for PC as a Games For Windows title in Spring of 2010.
Warhammer 40,000: Dawn of War II - Chaos Rising features a new playable army, the traitorous Chaos Space Marines, and continues the epic journey of the Blood Ravens as they battle this new, more personal enemy.
Developed by award-winning internal studio Relic Entertainment, Chaos Rising offers new single-player and co-op campaigns, a level cap increase from 20 to 30, more powerful war-gear and a suite of innovative multiplayer options. The exclusive first look preview of Warhammer 40,000: Dawn of War II - Chaos Rising will be featured in PC Gamer’s December issue, available on newsstands by October 12.
“Chaos Rising delivers a tremendous amount of new content, including the powerful Chaos Space Marines, new multiplayer maps and units, a new level cap and a continuation of the Blood Ravens single player campaign,” said Kevin Kraff, vice president of global brand management, THQ. “Relic’s passion for the Warhammer 40,000 universe and talent in crafting innovative RTS games will ensure Chaos Rising is an engaging experience that will advance the franchise and genre.”
“Dawn of War II took intimate brutality to another level and introduced RPG-RTS hybrid gameplay,” said Jonathan Dowdeswell, general manager, Relic Entertainment. “The epic struggle between Space Marines and the forces of Chaos lets us take those two game-play elements and create an even more intense experience - this time, the battle is personal.”
Adobe AIR is designed to be consistent across operating systems. The result is that AIR applications can also run consistently across operating systems. The reality however is that there are certainly places that operating systems differ significantly, yet present metaphors that users expect. Among those more pervasive differences is the Windows system tray. The same metaphor exists, but differently for Mac, and may not exist at all depending on your Linux distribution. Let??s take a look at what is involved to use JavaScript to interact with the system tray in a cross operating system fashion.
Note that just because you can write an AIR application to behave consistently, doesn??t mean that one cannot be written to focus on a specific operating system. If you chose to leave out support for other operating systems, then be aware that decision may come back to haunt you later.
When I set out to build this I did a little searching first and found a Flex example that originated from Sasa Radovanovic, and that was updated by Jeff Houser circa the Flex 3 Beta 3 timeline. What follows is a migration of that work from Flex to JavaScript, with a lot more verbiage around the why and how of the details. All things considered however, when you develop in AIR, you have many of the same classes available to you in both the Flash world and the JavaScript world. I encourage you to explore what??s available from both APIs.
When it comes to the system tray, it is generally common to have an icon that represents your application. This is important as your application itself won??t show up in the ??start bar? when it has been minimized. On Mac, the equivalent is the ??dock? and the icon that shows up there is generally the one associated with the application itself. In both cases, you can actually control at runtime how you want that icon to appear. With that in mind, let??s first start by loading our own custom icon.
var imgDock = null; $( document ).ready( function() { // Loader to load the icon image // Use Loader not HTML image to get at bitmap data (pixels) var loader = new air.Loader(); // Handle when the icon image is loaded // Load the icon image (in this case local) loader.contentLoaderInfo.addEventListener( air.Event.COMPLETE, doLoaderComplete ); loader.load( new air.URLRequest( SPLASH_IMAGE ) ); // Custom event handler for window closing // Want to prompt the user to see if they want to close or minimize nativeWindow.addEventListener( air.Event.CLOSING, doClosing ); } );You might initially be inclined to use an IMG tag. The problem with this approach is that it doesn??t give you access to the raw pixel data that the operating system will expect. To get at this data we will use an instance of the Loader class. Like most things web, the loader works asynchronously, so we will want to register for notification when the icon is loaded. Since this is local (in this case) it should be nearly instantaneous, but still we need to wait at least that instant.
// Called when the icon image is loaded // Setup systray/dock actions depending on operating system function doLoaderComplete( evt ) { var isMac = null; // Get the bitmap data (pixels) of the icon for the system // The system will size and convert to the appropriate format imgDock = evt.target.content.bitmapData; if( air.NativeApplication.supportsSystemTrayIcon ) { // Setup Windows specific system tray functionality air.NativeApplication.nativeApplication.icon.tooltip = SYSTRAY_TOOLTIP; air.NativeApplication.nativeApplication.icon.addEventListener( air.MouseEvent.CLICK, doTrayClick ); isMac = false; } else { isMac = true; } // Override the default minimize behavior and use our own nativeWindow.addEventListener( air.NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGING, doStateChange ); // Setup a menu on the docked icon to restore or close air.NativeApplication.nativeApplication.icon.menu = createMenu( isMac ); }Once our icon has been loaded, we will go ahead and get the pixels, referred to as bitmap data, of the image. We??ll store that in a reference for later use - specifically, we will show the icon in the system tray when the application is minimized and remove it when the window is restored. We??ll also want to put the icon back should the application window be minimized again.
What comes next is the main branch between Windows and Mac, and AIR gives you hooks to find out on which operating system your application is running. The NativeApplication class has a static property for ??supportsSystemTrayIcon? and ??supportsDockIcon? which represents Windows and Mac respectively. There are also many other useful properties on the NativeApplication class to include a check for menu support, and the flag to start the application when the user logs into the system.
If the application is running on a Windows operating system, then there are some additional options that we can leverage. Notably in this case are putting a tooltip on the system tray icon, and also listening for a click on the icon to restore the application window. Regardless of operating system, we want to catch a minimize gesture from the user and replace the default behavior with our own; namely minimize to the system tray and not the ??start bar?.
// Called when the docked icon is clicked (Windows only) // Calls a shared function to restore the window function doTrayClick( evt ) { undock(); } // Called when the window is minimized // Minimizes to systray/dock in place of traditional minimize function doStateChange( evt ) { if( evt.afterDisplayState == air.NativeWindowDisplayState.MINIMIZED ) { // Stop the default behavior // Call shared function to systray/dock evt.preventDefault(); dock(); } }While we are at it, we will go ahead and create the menu on the system tray/dock icon for the application on the whole. I??ve made the effort here to track the operating system when I create the menu. This is subtle but important. In the case of Windows the common term to close an application is ??Exit? while on a Mac the term is ??Quit?. The menu items create here can call the same functionality, that part doesn??t differ per OS, but I wanted to present the user with terminology they??d expect to encounter.
// Called to create a menu on the systray/dock icon // Takes operating system into consideration function createMenu( isMac ) { var menu = new air.NativeMenu(); var openItem = new air.NativeMenuItem( OPEN_ITEM ); var exitItem = null; // Both operating systems have an option to open the window openItem.addEventListener( air.Event.SELECT, doOpenSelect ); menu.addItem( openItem ); if( !isMac ) { // Mac provides built-in "Quit" item // Create an "Exit" item for Windows exitItem = new air.NativeMenuItem( EXIT_ITEM ); menu.addItem( exitItem ); } return menu; }Before we talk about the actions in those specific menu items, let??s pause and talk about what the application has done so far, and is now displaying.
When the application started, it loaded a custom icon to use in the system tray/dock. Once that icon was loaded, we grabbed the bitmap data for reference, and then proceeded to create platform-specific hooks for the application when hidden; namely the menu. Now the application is running, displaying it??s main window, and expecting some fashion of user interaction. Let??s say the user is next ready to minimize the application.
Keeping in mind that we want this application to sit in the system tray/dock, not on the ??start bar? we want to catch the default behavior and insert our own. We??ve already setup the application even handlers for minimize, so let??s take a closer look at the actual functionality. The first step is to prevent the actual minimize behavior, which can be done with the preventDefault() function call. Then to formally ??dock? the application, we hide the main window, and associate the icon we loaded earlier with the application.
// Called to put the window on the systray/dock // Hides window and puts icon in place function dock() { nativeWindow.visible = false; air.NativeApplication.nativeApplication.icon.bitmaps = [imgDock]; }Note that AIR can take a variety of sizes for the icon, and that they may differ depending on operating system. On Windows as an example, this icon tends to be displayed at 16?16. On a Mac it is very user-definable and may be anywhere between 16?16 and 128?128. You may want to account for this to get the best display for your icon, but when in doubt, the operating system will actually scale the icon image appropriately.
Now with the application safely tucked away, the user can continue on along with their business. At some point in the future we??ll assume that they want to bring your application back front and center however, and we??ve already laid the groundwork to make this happen. On Windows, clicking the system tray icon will ??undock? the application, while selecting the ??Open? context menu item on both Windows and Mac will perform the same function.
// Called to restore the window to normal mode // Shared function called by multiple event handlers function undock() { // Show the window and bring it to the front nativeWindow.visible = true; nativeWindow.orderToFront(); // Clear out the systray/dock icon (optional) air.NativeApplication.nativeApplication.icon.bitmaps = []; }In the case of restoring the application window to it??s former glory, we??ll first want to make it visible. To make sure the user isn??t blocking our newly visible window with one of their own, we??ll also want to bring our application to the front. Finally we??ll pull any custom icon indicator from the application. On Windows this will remove the icon from the system tray while the window is visible.
You may want to keep the icon in the system tray at all times regardless of state, in which case you??ll not clear the icon. You??d also likely not wait to put the icon in place for when the user minimized the application, and make the assignment as soon as the image is loaded. The real detail here is that AIR doesn??t presume to know how your application should behave. You need to design the behavior you want, while also taking into consideration operating system differences.
Now your user can start the application, ??dock? the main window to the system tray, and restore the window through some user gesture (which again is going to differ depending on operating system). How about closing your application once and for all?
// Called when the native window is starting to close // Prompts the user to see if they want to close or minimize function doClosing( evt ) { var answer = null; // Stop the default of actually closing the window evt.preventDefault(); // Ask the user what action to take answer = confirm( "Select \"OK\" to exit or \"Cancel\" to minimize." ); if( answer ) { // If they actually want to close the application closeApplication(); } else { // If they really just want to minimize the window dock(); } }One of the lines of code we didn??t talk about up front was that we added a listener to the native window to catch the closing event. This happens before the window is actually closed, and gives us a chance to more formally handle the event. In this case, we will ask the user if they are sure they want to close. This is a good practice since the user may not know what gesture to provide to actually put the application into the system tray/dock.
Very much like the minimize event, we can prevent the default behavior by calling preventDefault(). Next we can use the good old JavaScript confirm() method to ask the user about their real intentions. If they really want to close the application, then we??ll go ahead and make that call at the application level. If they actually want to put the application into the system tray/dock, then we??ll call the ??dock? method we discussed earlier during the minimize operation.
// Called to close the window // Shared by multiple event handlers function closeApplication() { nativeWindow.close(); }As a summary, we first need to manage a custom icon, potentially at different sizes based on operating system, create the appropriate context menus for the application, and stop some of the default behavior and inject our own.
While that??s it in a nutshell, the variables get involved in how you want your application to behave when running on different operating systems. When does the icon get generated or put into the system tray? What should the context menu say to the user? How should the prompt to stop closing be worded depending on OS? These are all decision you will need to consider as you implement your own approach to docking. I??ve included a sample application with the above behaviors for your use as a template.
Martin Maurer is building an open source management tool for virtualization platforms: Proxmon Virtual Environment.
The product, still in beta (0.9), has some interesting capabilities:
Additionally, the developer is implementing also a live migration capability.
Since both KVM and OpenVZ don't have a GUI it's worth a try even if it's still in early development.
Download it here.

The easiest way to get started with VIX is by using the vmrun command which is packaged inside of VIX. It's a command-line executable that doesn't require a development environment, and is pretty easy to use once you get the hang of it.
Since I mostly use ESX, I want to take an ESX-centric view of using vmrun in this post, and I'm also going to focus on what you can do to the guest operating system within VMs. Specifically I'm going to address two use cases that I think are pretty important and useful:
First, you'll need to install VIX 1.6.2. On Windows you'll find vmrun in %PROGRAMFILES%\VMware\VMware VIX. On Linux it should be available in your path, so you can just run it from anywhere. Next, make sure you've got an ESX 3.5 update 2 or higher server to run commands against. In addition, you'll need a VM whose operating system is running an up-to-date copy of VMware tools.
If you type vmrun with no arguments you'll get a listing of all the things vmrun can do, but I want to focus on guest operations, which are listed below.
Table 1: Guest operations supported by vmrun.
| Operation | Description | Supported on ESX? |
| runProgramInGuest | Run a program in Guest OS | Yes |
| fileExistsInGuest | Check if a file exists in Guest OS | Yes |
| setSharedFolderState | Modify a Host-Guest shared folder | No |
| addSharedFolder | Add a Host-Guest shared folder | No |
| removeSharedFolder | Remove a Host-Guest shared folder | No |
| listProcessesInGuest | List running processes in Guest OS | Yes |
| killProcessInGuest | Kill a process in Guest OS | Yes |
| runScriptInGuest | Run a script in Guest OS | Yes |
| deleteFileInGuest | Delete a file in Guest OS | Yes |
| createDirectoryInGuest | Create a directory in Guest OS | Yes |
| deleteDirectoryInGuest | Delete a directory in Guest OS | Yes |
| listDirectoryInGuest | List a directory in Guest OS | Yes |
| copyFileFromHostToGuest | Copy a file from host OS to guest OS | Yes |
| copyFileFromGuestToHost | Copy a file from guest OS to host OS | Yes |
| renameFileInGuest | Rename a file in Guest OS | Yes |
| captureScreen | Capture the screen of the VM to a local file | No |
| writeVariable | Write a variable in the VM state | No |
| readVariable | Read a variable in the VM state | No |
Use case: Installing an agent in your VM.
Installing agents is an integral part of managing large numbers of systems, whether physical or virtual. Usually you want to bake your agents into your OS image, but occasionally a new agent will come along that needs to be deployed to existing systems. This example shows how you can copy an agent from your desktop to your VM and install it. The only thing you need is an agent that can be installed without user intervention (which is the norm for agents anyway).
Please note: Commands should be entered all on one line, it's split up here just for the sake if fitting it into the blog.
Example 1: Copying an MSI file from your desktop to your VM.
| vmrun -T esx -h https://esx.example.com/sdk |
| -u root -p secretpw -gu user -gp userpw |
| copyFileFromHostToGuest "[storage1] Windows/Windows.vmx" |
| "c:\program files\my agent software\agent.msi" c:\agent.msi |
One thing to point out here is that, despite the command saying "From Host to Guest" the file is actually being copied from the same system where vmrun is invoked (for example your laptop or workstation).
Next we use runProgramInGuest to install the MSI.
Example 2: Invoke the MSI file we copied above.
| vmrun -T esx -h https://esx.example.com/sdk |
| -u root -p secretpw -gu user -gp userpw |
| runProgramInGuest "[storage1] Windows/Windows.vmx" |
| c:\agent.msi |
Use case: Restarting a service on Windows.
This one's really easy so I'll just show it without explanation.
Example 3: Restart a service on Windows.
| vmrun -T esx -h https://esx.example.com/sdk |
| -u root -p secretpw -gu user -gp userpw |
| runProgramInGuest "[storage1] Windows/Windows.vmx" |
| c:\windows\system32\net.exe restart dhcp |
If Linux is more your style, tweak the last part to say something like /etc/init.d/sshd restart and you'll be restarting Linux services just as easily.
How do I get the path to my VMX file?
The hardest part about dealing with vmrun when you're managing ESX is knowing where your VMX file is. To get this you have to either log in to your ESX system and locate the VMX file, or you can use the VI API. Within the VI API, the VirtualMachine object contains a data structure called VirtualMachineFileInfo. The vmPathName property of this structure tells you the path to your VMX file. Not very pretty, but over time you'll see us rolling out some more convenient ways to access the functionality VIX provides. In the meantime there's a lot of really useful stuff you can do with tools like vmrun.
