-
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
-
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.
-
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|