I'm currently trying to built a little Air Application where I want to set the normal Command-C key to call a function? Is this even possible to use a standard Menu Command?
function createMenu():NativeMenu{
var menu:NativeMenu = new NativeMenu();
var menuOneCommand: NativeMenuItem = menu.addItem(new NativeMenuIte开发者_如何学编程m("Menu 1"));
menuOneCommand.keyEquivalent = "C"; //Command Shift C
menuOneCommand.addEventListener(Event.SELECT, myfunction);
return menu;
}
Moreover I would love to know how i can call a function (myfunction) which is actually a MouseEvent Handler?
function myfunction(e:MouseEvent = null) { trace('Throws Errors at the moment')}
Thank you for your help!
I'm not sure what you mean in the first part of your question (what is the normal command C key?) and I've never worked with NativeMenuItems, but concerning the second part of your question:
When adding an event listener for Event.SELECT, the callback function must accept an Event object, not a MouseEvent object. Since MouseEvent inherits from Event, you can safely change MouseEvent to Event in the parameter list of myfunction
, unless you're using some of the properties of e
that belong exclusively to MouseEvent (your example does not).
Well, if I'm running my Air Application it has of course the default menu, almost every application has. Like "File", "Edit" and "Window". First of all, can i get rid of them, because they are not needed for my Application. And that's exactly what I mean with CMD-C. If i look up the "Edit" Menu I find the normal commands like "Copy", "Paste" etc. and they of course have the default Shortcuts like CMD-C or CMD-V. However i would like to use them for my Application in a different way. I want to call a function in my AS if I'm hitting CMD-C or CMD-V.
Of course it's not a problem with any other "not-default" shortcut, like e.g. CMD-F, but CMD-C is already taken by default. Can i change that behaviour?
Thank you for your help!
精彩评论