A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: object listener

  1. #1
    prgrmr 4 hours user 4 years
    Join Date
    Dec 2009
    Location
    behind you
    Posts
    54

    resolved object listener

    hello I am about to work on making a game (which will be glitchy ost likely but this game is just experimental to help me learn)

    and I got some code from an earlier post and would like to know what an object listener is.
    Thanks

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Without an opportunity to see the code, you may be mixing up a couple of terms. You have objects, which makes up the bulk of object-oriented programming and you have listeners. There are different type of listeners depending on what you are listening for.

    Can you be more specific or supply the lines of code that contains your question?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    prgrmr 4 hours user 4 years
    Join Date
    Dec 2009
    Location
    behind you
    Posts
    54
    stage.addEventListener(KeyboardEvent.KEY_DOWN, kDown);



    function kDown(e:KeyboardEvent):void {

    switch(e.keyCode) {

    case Keyboard.DOWN:

    jj.y += 5;

    break;

    case Keyboard.UP:

    jj.y -= 5;

    break;

    case Keyboard.RIGHT:

    jj.x += 5;

    break;

    case Keyboard.LEFT:

    jj.x -= 5;

    break;

    trace("keyCode: ", e.keyCode);

    }

    if(e.keyCode == 87) { //w-87, a-65, s-83, d-68

    jj.y -= 5;

    }

    if(e.keyCode == 83) {

    jj.y += 5;

    }

    if(e.keyCode == 65) {

    jj.x -= 5;

    }

    if(e.keyCode == 68) {

    jj.x += 5;

    }

    }

  4. #4
    prgrmr 4 hours user 4 years
    Join Date
    Dec 2009
    Location
    behind you
    Posts
    54
    hello?

  5. #5
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    What you are using are keyboard listeners. As I mentioned above, there are different types of listeners, some will listener for events from the keyboard, others from the mouse, you even have listeners to look for a file to complete loading.

    In any case, a listener is just a piece of code that is directed to wait for a specific event. For example, a mouse listener

    obj.addEventListener(MouseEvent.CLICK, something)

    This will keep an eye out for the mouse to be click on the specific object (obj), and when it does it fairs off an event to the specific function (something). They are extremely handy when you want your application to perform a task based on a mouse or keyboard action.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

Tags for this Thread

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