Quantcast
Viewing latest article 2
Browse Latest Browse All 4

AIR Tip: ContextMenuItem can crash AIR app on Windows

This is just quick tip for all AIR developers. If you are developing AIR application and you want to use ContextMenu please be aware of possible problem on Windows platform. This is not problem on Mac, and it’s not problem in Flash Player (even on Windows). It is problem just in AIR on Windows (at least what I have find out till now).

Problem is as follow:

You want to have ContextMenu for some of your item (right click menu). You have created ContextMenu and want to add ContextMenuItem in this way

var myItem:ContextMenuItem = new ContextMenuItem(myItemName);

if variable myItemName is initialized or at least is empty string, all is ok. But there can situations when it is null. For example when you want to support multilanguage with ResourceManager, so it’s not correctly fill up and it’s null. In that case you AIR will crash and you will not know why, because it’s works on Mac, it works in FlashPlayer (without AIR), it just doesn work in AIR on Windows platform

So my quick fix was create fix function, like this

private function fixEmptyString(val:String):String
{
	if (val == null)
		return '';
 
	return val;
}
 
var myItem:ContextMenuItem = new ContextMenuItem(fixEmptyString(myItemName));

This will for sure.

Hope this helps you.

P.S. I will post this and another useful AIR tips in my Franto.com Tips & Tricks, so do not wait and subscribe to my list, if you find AIR tip this useful…


Viewing latest article 2
Browse Latest Browse All 4

Trending Articles