hey guys!
I’m doing some silverlight work and I ran into a problem adding event listeners to the silverlight objects using javascript.
I am writing a menu system, and as I attach the listener for a button, I would like to attach all the listeners for the menu it is associated with.
this is the code I have issue with:
[code]
function loadMenuEvents(src, idx)
{
var menu_name = src.name.replace(“button”, “menu”);
var menu_block = menuBar.FindName(menu_name);
menu_block.addEventListener(“MouseLeave”, function(){ hideMenu(menu_name, src, idx) });
for(var i = 0; i < menu_block.children.count; i ++)
{
var menu_item_name = menu_block.children.getItem(i).name;
if(menu_item_name.indexOf(“text”) != -1)
{
var menu_item = menu_block.FindName(menu_item_name);
menu_item.addEventListener(“MouseEnter”, menuItemHighlight);
menu_item.addEventListener(“MouseLeave”, menuItemUnHighlight);
}
}
}
if I alert menu_item_name, I correctly get each menu items name, but if I put the alert inside the event handler, and get the name of the object who’s handler it is, it seems like all the events are attached to the last object, because I only ever get it’s name.
I really can’t see what can be causing this so any help is greatly appreciated.
Thanks,
//erlin!