
Building desktop widgets with Zinc: Right click
Following the tutorial on
Building Flash desktop widgets with Zinc, in this tutorial we will see some actionscript and a bit of {MDM}Script to add some interactivity to our widget.
We will do something very similar to what I've explained before in my post "
Building flash web widgets: right click" but this time is desktop oriented thanks to
MDM Zinc.
At the moment the only way to close our application is by pressing the "Esc" button and that's not nice and not user friendly at all...
So we will open our flash file, and add the following script:
function closeWidget() {
mdm.Application.exit();
}
var cmMenu:ContextMenu = new ContextMenu();
cmMenu.hideBuiltInItems();
cmMenu.customItems.push(new ContextMenuItem("Close Widget", closeWidget));
this.menu = cmMenu;
There's a function called closeWidget and it has only one line of {MDM}Script that will close our application.
The rest is the usual script necessary to have a right click menu explained before in my post "
Building Flash web widgets: Right click" so if you need more explanation please read that post.
We will do the same we did for the web widget and we will add a link to our site and a link to Widgipedia.
Let's update the code:
function closeWidget() {
mdm.Application.exit();
};
function linkToMe():Void {
getURL("http://overloadstudios.blogspot.com/");
}
function linkToDistributor():Void {
getURL("http://www.widgipedia.com");
}
var cmMenu:ContextMenu = new ContextMenu();
cmMenu.hideBuiltInItems();
cmMenu.customItems.push(new ContextMenuItem("Close Widget", closeWidget));
cmMenu.customItems.push(new ContextMenuItem("Built by Overload Studios", linkToMe, true));
cmMenu.customItems.push(new ContextMenuItem("Powered by Widgipedia", linkToDistributor));
this.menu = cmMenu;
Now we have added a link to my blog and a link to Widgipedia and the code is the same as the one
on this post except for one thing, the script to add the link to my blog has something new, it says "true" as a final parameter ( "Built by Overload Studios", linkToMe,
true ), this "true" means there will be a division line above it to separate the close button to the credits.
If we test the flash movie pressing Ctrl+Enter (command+Enter on Mac) and press down the right button of the mouse, we should see a menu like this one:
of course if we click on "close widget" nothing happens and is because the script to close the widget only works when the application is built with MDM Zinc.
{MDM}Script is perfect to extend flash applications, has hundreds of options and we will add another one just because
Ok, not just because... instead of the single line to close the application, just in case the user doesn't want to close it and pressed the button by mistake, we will add a "confirm" window so the user can really close the widget or leave it open; to do so, we will update the script changing the closeWidget function as follows:
function closeWidget() {
var Result = mdm.Dialogs.promptModal("You sure you want to close?", "okcancel", "confirm");
if (Result == true) {
mdm.Application.exit();
}
}
We are adding a "confirm window" called Result and has three parameters: the message, the two options available and the window style. To see find out more about the possible options, please check
the MDM Zinc documentation.
We don't need to add anything else from the flash side, we can save and close the file if we want to and now we should open Zinc and follow the instructions given in
the previous tutorial with the difference that in this case in the "input devices settings" we will change the "right mouse button" setting to
Send to Flash instead of the default "Ignored".
Build your widget and you will be able to see something like:
And that's it! our widget is ready to be uploaded to Widgipedia!
Please don't forget to check the
Zinc documentation and if in case you get stuck in something, visit the
MDM Forums as for sure you will get a fast answer.
salut!
-----------
:: Games Garden ::