Popup Overview

The Popup commands enable you to build, edit, and display context menus. A menu can appear anywhere on your application or in the system tray if you've included your application in the system tray. For more information on adding your application to the system tray see the SWF Studio Application tab and/or Tray.addIcon.

You can specify the text of a menu item, whether an item is checked or not, and whether an item is disabled or not when you first build your menu or at any point afterwards. You can also create multiple level menus by specifying sub menu items for any menu item.

Menus can be built manually through code or by loading a formatted file. Once a menu is built you can get a formatted string representation of the menu to load at another time.

When you create a menu using the Popup commands SWF Studio will not display the menu automatically for you. You control when a menu is displayed. You can receive notifications for right-clicks on both your application and on the system tray. This information can then be used to display any menu you choose. Also see Tray.setNotify for information about receiving other events like left, middle, and right mouse clicks on the system tray.

Menus can be shown where the mouse is located or, by specifying coordinates, on any point of your application/screensaver.

Here is an example where we create a menu called "context" and then make it appear when the user right-clicks on our application. When the user selects an item from the menu we will display a message in the SWF Studio Trace window.

First we create a new menu and give it a name.

ssCore.Popup.newMenu({name:'context'});

Next we add an item to the menu.

ssCore.Popup.addItem({name:'context', id:1, parent:0, type:'item', text:'Item 1'});

We'll add another item to the menu, and it will have a sub menu.

ssCore.Popup.addItem({name:'context', id:2, parent:0, type:'menu', text:'Item 2'});

The following item is an item of the sub menu for the above item. Notice the id of the previous item and the parent value of this item.

ssCore.Popup.addItem({name:'context', id:101, parent:2, type:'item', text:'Sub item 1'});

We'll add one more item that will be a checked item.

ssCore.Popup.addItem({name:'context', id:3, parent:0, type:'item', text:'Item 3', flags:'checked'});

This code will setup a function that will show our menu when the user right-clicks on our application.

function onContextMenu(return_obj, callback_obj, error_obj)
{
    ssCore.Popup.show({name:'context'}, {callback:contextMenuSelection});
}
ssCore.Popup.setNotify({event:'onContextMenu'}, {callback:onContextMenu});

Notice that in the previous code sample there is a callback function specified for the show command. When the user selects an item from our menu that callback function will be called, returning the id of the item pressed. If no item was pressed, then 0 is returned.

function contextMenuSelection(return_obj, callback_obj, error_obj)
{
    if (return_obj.result == 0)
    {
        ssDebug.trace('No menu item was pressed.');
    }
    else
    {
        ssDebug.trace('Item with id of '+return_obj.result+' was pressed.');
    }
}