methodArguments popupMenu

Hello,
i try to pass an argument to my function with popupmenu but nothig…

this is my menu:

var menu = plugins.window.createPopupMenu()
_sub = menu.addMenuItem()
_sub.text = 'text'
_sub.setMethod(new1)
_sub.methodArguments = [1, "data"]

my function:

function new1(args) {
	application.output(args[0])
}

i want to pass also the event is it possible?

thanks

There are a couple of default arguments that will always be passed to a method triggered by the popupmenu, your argument will start at index 5.
See the comment in the sample code:

// set the arguments to be sent to the callback method
// (an array of elements which will be passed as arguments 5, 6 and so on to the callback method)
// the first 5 arguments are fixed: 
//	[0] item index
//	[1] parent item index
//	[2] isSelected boolean
//	[3] parent menu text
//	[4] menu text
entry.methodArguments = [17, "data"];

Thanks for your answer.
I tried but nothig…it prints

_sub.methodArguments = ['asd', "data", 'pippo']
/**
 * @param {Array} args
 * @properties={typeid:24,uuid:"30649593-2E51-4B39-AA5B-F67CB2EDE3BD"}
 */
function call(args) {
	for (var index = 0; index < args.length; index++) {
		application.output(args[index])
	}
	
}

You expect the first argument to be an array, but that is not correct. All those values will be separate arguments.

Try this:

function call(index, parentIndex, isSelected, parentText, text, yourFirstArgument, ....) {
	...
}

Thanks…it works!!

After eight years of not being able to pass parameters with the popupMenu I today stumbled upon this post (THANK YOU).

The following now works for me:

/**
 * @properties={typeid:24,uuid:"A43C20A4-35FE-4F93-8F4E-16B5A28D5689"}
 */
function showpopup(event) {
	var popupmenu = plugins.window.createPopupMenu()

	var menuitem1 = popupmenu.addMenuItem('Menu Text', globals.myGlobalMethod)
	//add arguments to the method call
	menuitem1.methodArguments = ['myInfo']

	var source = event.getSource()
	if (source != null) {
		popupmenu.show(source);
	}
}
/**
 * @param {String} itemIndex0
 * @param {String} parentItemIndex1
 * @param {String} isSelectedBoolean2
 * @param {String} parentMenuText3
 * @param {String} menuText4
 * @param {String} arg5
 * 
 * @properties={typeid:24,uuid:"77930261-9675-4270-A5AC-F4EC3E1BDB96"}
 */
function myGlobalMethod(itemIndex0, parentItemIndex1, isSelectedBoolean2, parentMenuText3, menuText4, arg5) {
	application.output(arg5);
}

Dean Westover, President
Choices Software, Inc.

Haha, glad to have helped! :)