Monday, June 3, 2024
188
rated 0 times [  193] [ 5]  / answers: 1 / hits: 25048  / 15 Years ago, wed, january 13, 2010, 12:00:00

How do I create a custom event class similar to ActionScript? What I mean by that is a class that I can use to fire off my own events, send the necessary data.


I don't want to use third-party libraries like YUI or jQuery to do it. My goal is to be able to send a event that looks like this:


document.addEventListener("customEvent", eventHandler, false);

function eventHandler(e){
alert(e.para1);
}

document.dispatchEvent(new CustomEvent("customEvent", para1, para2));

Please no third-party library solutions.


More From » actionscript-3

 Answers
9

A method that worked for me was to call document.createEvent(), init it and dispatch it with window.dispatchEvent().



  var event = document.createEvent(Event);
event.initEvent(customEvent, true, true);
event.customData = getYourCustomData();
window.dispatchEvent(event);

[#97841] Monday, January 11, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turnerf

Total Points: 620
Total Questions: 101
Total Answers: 109

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
turnerf questions
;