Page 1 of 4 123 ... LastLast
Results 1 to 10 of 35

Thread: Can anyone tell me how to create custom events??

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anyone tell me how to create custom events??

    Hello all,
    I hope whoever reads this post has already understood my needs. I want information(or help) about creating custom events. If anyone has enough knowledge about it please share with me and others.
    Thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    var prop = 3;
    
    function check() {
      if(prop != check.old)
        prop.onchange();
    }
    
    check.old = prop;
    
    window.setInterval(check, 100);
    
    prop.onchange = function() {
      alert("Property change event has been fired!  Property is now: " + this);
    };
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Looks like the event would fire every 100ms once the prop value had changed.

    Oh, and:

    Error: prop.onchange is not a function
    Source File: file://localhost/ . . . /test/prop_h.htm
    Line: 11
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You are, of course, quite right.
    Code:
    var prop = 3;
    
    var onchange = {
      'prop': function() {
        alert("Property change event has been fired!  Property is now: " + this);
      }
    };
    
    function check() {
      if(prop != check.old) {
        check.old = prop;
        if(onchange['prop'])
          onchange['prop'].apply(prop);
      }
    }
    
    check.old = prop;
    
    window.setInterval(check, 100);
    Last edited by Twey; 09-16-2006 at 08:12 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Twey,jschuer1: Can you tell me what this code does(of course, I know it demonstrates a custom event) but how to use it?? Thanks.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It sets up a polling function that checks for a condition (a change in the variable prop's value, in this case) every 100ms. When it detects a change it executes a function which, in this case pops up the alert. You could adapt it to check for any condition and to execute anything when that condition is met. Polls do not have to be continuous. Nor must they use such advanced object oriented coding. If you have a look at this post:

    http://www.dynamicdrive.com/forums/s...ad.php?t=13003

    It gives a more practical example of a poll using a more mundane coding style. It is a poll that only begins when something else is initiated and that can therefore end when its sought for condition is found and acted upon.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Nor must they use such advanced object oriented coding.
    The idea was that in a real-world setting, one could have a list of properties to monitor, and add/remove them dynamically.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Twey
    The idea was that in a real-world setting, one could have a list of properties to monitor, and add/remove them dynamically.
    I wasn't complaining. I could learn a thing or two from you as regards this type of javascript. I was just saying, for shachi's benefit, that it doesn't have to start out like that when you are first trying to understand the basic concept.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I was just making a note as to why I did it
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    jscheuer1, Twey: I still don't get a thing(may be because if my low experience in javascript) can you give me a little simple example?? I am all

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •