dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: listeners uh?

  1. #1
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194

    listeners uh?

    Hi,
    can someone tell me what the point of listeners are in MX2004? why are they needed, whats special about them??

  2. #2
    Uses MX 2004 Pro Quixx's Avatar
    Join Date
    Nov 2004
    Location
    U.S.
    Posts
    877
    Well... There are different types of listeners, and I'm not very familiar with them all. But I like using the key listener when I need my movie to detect a key hit. It's beneficial in some cases, because you don't need to put your code under an onEnterFrame even handler for it to take effect. The code is only called when a keyboard key is hit, which saves on system resources since the code isn't being checked every frame.

    So instead of using the following code, where the if() statement is constently being checked...

    Code:
    onEnterFrame = function () {
    	trace("checking");
    	if (Key.isDown(65)) {
    		trace("You hit the \"a\" key!");
    	}
    };
    ...You can use this code, where it is only checked on when a key is hit.

    Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
    	trace("checking");
    	if (Key.isDown(65)) {
    		trace("You hit the \"a\" key!");
    	}
    };
    Key.addListener(keyListener);

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center