/    Sign up×
Community /Pin to ProfileBookmark

multiple add events issue

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);
}
}
}
[/code]

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!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManSep 10.2007 — sounds like a "bubble" issue. the only problem is i know very little about event listeners, and only once remember seeing something about how the bubbling plays out. i know that Dok knows a lot about it. a couple others two whos names fail me.

edit.. heres the link. maybe theres something in there that can help you?

http://www.quirksmode.org/js/events_order.html
Copy linkTweet thisAlerts:
@CrazyMerlinauthorSep 10.2007 — thx aaron, I'll look into it
×

Success!

Help @CrazyMerlin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...