Jump to content
Sign in to follow this  
astralaaron

Actionscript 3

Recommended Posts

hi I am new with ActionScript 3, trying to apply a few things I have done in C++.Does anyone know where I can find examples of event handling inside of a class method?Specifically how to call that method and send the event parameter to the method..heres my package / class (BTW I am just trying to make a circle move around when you press the arrow keys)

package {import flash.display.*;import flash.events.*; public class Hero extends MovieClip {var xV = 0;  // x Velocityvar yV = 0;  // y Velocity	public function Hero(){}	public function MoveIt()	{	 this.x += xV;	 this.y += yV;		}	public function handleKeyDown(event:KeyboardEvent)	{        switch(event.keyCode)        {            case 38: --yV; break;            case 40: ++yV; break;            case 37: --xV; break;            case 39: ++xV; break;            default: break;        }	}	public function handleKeyUp(event:KeyboardEvent)	{        switch(event.keyCode)        {            case 38: ++yV; break;            case 40: --yV; break;            case 37: ++xV; break;            case 39: --xV; break;            default: break;        }    }}}

and here is where I am stuck / getting errors.. not knowing how to use this stuff inside of the timeline:

var newHero:Hero = new Hero();this.addChild(newHero);newHero.x = 300;newHero.y = 200;	stage.addEventListener(KeyboardEvent.KEY_DOWN, newHero.handleKeyDown());

I can't figure out how to get the event passed into HandleKeyDown()

Edited by astralaaron

Share this post


Link to post
Share on other sites

Don't out parethesis () on the function name.By doing that you're running the function right there and assigning the function's return value as the event handler, which isn't what you want.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...