Same Action to multiple HUD elements
Code your action by hand, not with the HUD editor. If you give your components generic names with a number at the end, you can write a simple for-loop that will assign the action to every component with the correct component name.
For this sample to work, i assume your main menu buttons are named MainMenuButton_0 to MainMenuButton_30.
--initialze HUD
hud.newTemplateInstance ( application.getCurrentUser ( ), "YourHudName", "MMenu" )
local hUser = application.getCurrentUser ( )
for i=0, 30, 1 do
--create scaleup action
local hActionScaleUp = hud.newAction ( hUser, "ScaleUpMMButton_"..i )
hud.beginActionCommand ( hActionScaleUp, hud.kCommandTypeInterpolateSize )
hud.pushActionCommandArgument ( hActionScaleUp, hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i ) )
--set your own scaling values here
hud.pushActionCommandArgument ( hActionScaleUp, 10 )
hud.pushActionCommandArgument ( hActionScaleUp, 10 )
hud.pushActionCommandArgument ( hActionScaleUp, hud.kInterpolatorTypeLinear )
hud.pushActionCommandArgument ( hActionScaleUp, 50 )
hud.endActionCommand ( hActionScaleUp )
--create scaledown action
local hActionScaleDown = hud.newAction ( hUser, "ScaleDownMMButton_"..i )
hud.beginActionCommand ( hActionScaleDown, hud.kCommandTypeInterpolateSize )
hud.pushActionCommandArgument ( hActionScaleDown, hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i ) )
--set your own scaling values here
hud.pushActionCommandArgument ( hActionScaleDown, 6 )
hud.pushActionCommandArgument ( hActionScaleDown, 6 )
hud.pushActionCommandArgument ( hActionScaleDown, hud.kInterpolatorTypeLinear )
hud.pushActionCommandArgument ( hActionScaleDown, 50 )
hud.endActionCommand ( hActionScaleDown )
--get button
local hComponent = hud.getComponent ( hUser, "MMenu.MainMenuButton_"..i )
if hComponent then
hud.addComponentEventHandler ( hComponent, hud.kEventTypeMouseEnter, hud.getAction ( hUser, "ScaleUpMMButton_"..i ) )
hud.addComponentEventHandler ( hComponent, hud.kEventTypeMouseLeave, hud.getAction ( hUser, "ScaleDownMMButton_"..i ) )
log.message ( "new mouse handlers for button "..i.." added!" )
end
end