28.11.10

Switching to Classes

I have no idea how to do this right, so I'm just going to go at it. I will start by taking the code for each of the buttons in the original Jump program and placing them into the individual AS3.0 files.

This is the code from the original Jump program:



Red.addEventListener(MouseEvent.CLICK, RedJump);


function RedJump(event:MouseEvent):void
{
Green.x -= 60;
}


Blue.addEventListener(MouseEvent.CLICK, BlueJump);


function BlueJump(event:MouseEvent):void
{
Green.x +=60;
}


Yellow.addEventListener(MouseEvent.CLICK, YellowJump);


function YellowJump(event:MouseEvent):void
{
Green.y +=60;
}


Orange.addEventListener(MouseEvent.CLICK, OrangeJump);


function OrangeJump(event:MouseEvent):void
{
Green.y -= 60;
}

In my new folder for the project, I have created five .as files which will house the code: MoveLeft, MoveRight, MoveUp and MoveDown for each of the buttons, and Jump for the main body of the program.

No comments:

Post a Comment