A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Don't understand what this function is :(

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    5

    Don't understand what this function is :(

    I'm new so i don't know much and i was examining a simple script and there was a function that looked like this "function movePaddle(event:Event):void{" its only the function declaration because i understand what the code is inside it i just dont get the (event:Event) thing plz help

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That means that the movePaddle function takes one argument, of type Event. This is almost certainly because it's being used as an event listener.

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Im sorry i didn't get that completley here is the whole code(i didn't make it myself)
    function beginCode():void{
    //Adds a listener to the paddle which
    //runs a function every time a frame passes
    mcPaddle.addEventListener(Event.ENTER_FRAME, movePaddle)
    }

    function movePaddle(event:Event):void{
    //The paddle follows the mouse
    mcPaddle.x = mouseX;
    }

    beginCode();

    please make some more sense

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    When you declare a function, the stuff between ( and ) is the list of arguments that that function takes. In this case, it takes a single argument of type Event, and calls that argument event.

    The reason that the function needs to take an Event argument is because it is used as an event listener. Event listeners are functions which are called in response to some event (In this case Event.ENTER_FRAME, which occurs once per frame). These listener functions are passed an Event object which describes the Event they are reacting to.

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