Archive

Archive for March, 2011

Flex : KeyBoard, keyCode convert to String

March 31, 2011 Leave a comment

I searched in vain for a while for a function to convert a keyCode from a KeyboardEvent to an understandable string, so here a piece of code (doesn’t contain all the codes, at least the ones I needed):


private function convertKeyCode(keyCode:uint):String
{

switch (keyCode )

{

case Keyboard.F1: return "F1";

case Keyboard.F2: return "F2";

case Keyboard.F3: return "F3";

case Keyboard.F4: return "F4";

case Keyboard.F5: return "F5";

case Keyboard.F6: return "F6";

case Keyboard.F7: return "F7";

case Keyboard.F8: return "F8";

case Keyboard.F9: return "F9";

case Keyboard.F10: return "F10";

case Keyboard.F11: return "F11";

case Keyboard.F12: return "F12";

case Keyboard.ESCAPE: return "ESCAPE";

case Keyboard.UP: return "UP";

case Keyboard.DOWN: return "DOWN";

case Keyboard.RIGHT: return "RIGHT";

case Keyboard.LEFT: return "LEFT";

case Keyboard.PAGE_DOWN: return "PAGE_DOWN";

case Keyboard.PAGE_UP: return "PAGE_UP";

case Keyboard.ENTER: return "ENTER";

case Keyboard.HOME: return "HOME";

case Keyboard.TAB: return "TAB";

}

return "";

}

Categories: Uncategorized

Flex : Find the topmost popup

March 30, 2011 Leave a comment

With the PopupManager it’s possible to add/create/remove a new popup. But i can’t find a way to get the top most popup without overriding this class (which something you want to do for a big Flex application).

So far I found this solution, which is more kinna of work around. So if any body has a better solution, i will be pretty much happy to read it.

Assuming the you call the addPopup/createPopup with the parameter PopUpManagerChildList.POPUP, example :

PopUpManager.createPopUp(parent,MyPopupClass,true,PopUpManagerChildList.POPUP);

The this function will return the top most popup:

private function getTopMostPopup():void {

 var childList:IChildList = Application.application.systemManager.popUpChildren;
 for (var i:int = childList.numChildren - 1; i > 0; i--)
 {
      var child:DisplayObject = childList.getChildAt( i );
      if (child is Container)
           return child;
 }
 return null;

}

Application.application.systemManager.popUpChildren contains all the DisplayObject displayed with PopupManager. But many of the itemRenderers of your components could be in this list eventhough there are not visible in the screen. This is why my function get the last child inheriting from Container (your popup must inherit from Container).

Custom Menu – Right Click on Flex – Opaque mode

March 29, 2011 Leave a comment

Flex provides a context menu you can customize with the class ContextMenu.

However, the default context menu is quite ugly. And it’s not even possible to hide the adobe flash native items (Parameters, Global Parameters, About Adobe Flash Player).

So, to have a nice customized menu with a right click you won’t be able to get it from the ContextMenu provided in Flex. You will have to find another way.

Trying to set up a custom menu on a right click for one of my application, I tried few solutions. Actually only one but throught different ways.

The solution consists in disabling the right click on your flash application. Then catch the right click with JavaScript, and pass the event to your flex application through ExternalInterface, and then display your own Menu. There is plenty of websites explaining about this workaround and even a project on google code : http://code.google.com/p/custom-context-menu/

I tried this workaround, and it worked on most of the browsers (not on opera, but i didn’t take time to try to make it work).

But one thing you have to keep in mind if you do try such solution : you have to set the wmode of your flash to opaque. I already wrote about that mode a year ago, and for myself i never use it. By setting your flash with this mode, you will hit quite a few problems (like you scroll mouse not working for example).

 

Categories: Uncategorized