Here is another one a little quicker than last time which is good
With this piece of coding, I have fix the problem of the man flying off the stage when the key is held down, (You can see this problem in the last section I did called Keyboard events), the key press looped the upward motion and did not return it to its original position.
So to achieve this we need to turn off the eventListener with in the “jump” function, as you can see in the code the removeEventListener is placed within the function that was created. Then after this we need to turn the listener back on in the “land” function to stop the Man dropping off the bottom of the stage.
Plus allso with in this code I have made the man rotate to add a little fun, see if u can get the poor bloke back on his feet
To do this I had to add a event Listener called “roll” within the function, so when the key is pressed the man rotates and when the key is released he stops, also returning him to the floor.
stage.addEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.addEventListener(KeyboardEvent.KEY_UP, land);//stage listener so we don’t have to select Object
function jump(event:KeyboardEvent):void
{Man_mc.y -= 100;
stage.removeEventListener(KeyboardEvent.KEY_DOWN, jump);//remove the function jump
stage.addEventListener(Event.ENTER_FRAME, roll);
}//jump up 100 pixels
function land(event:KeyboardEvent):void
{
Man_mc.y += 100;
stage.addEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.removeEventListener(Event.ENTER_FRAME, roll);//add Function jump plus remove the roll function
}
/*man drop back to the original
place which is down 100 pixels plus all so land on whatever angle the key was released on*/
function roll (event:Event):void
{
Man_mc.rotation += 55;
//rotates the man 55 degrees per frame![]()
}
Well there we go and I hope you all have fun getting the man to land the right way up.
In the next section I will be looking at timers








Script Comments
That have commented on my site and hope that others will in the
future.
Also to the people that have been waiting to see my progress.
Sorry that I have not posted for a few weeks, I have been busy playing
With my ubuntu install and playing rainbow 6 Vegas 2, left 4 dead and
Warcraft
So anyway here I am again. This time in the following exercise I am
looking at keyboard function, but first I thought I would point out
how you would write a Comment within the code.
In the last blog I broken the code down in to paragraph which I think
took a lot of reading and a lot time. So this way I can input
comments on the way and point out what’s happening at that time.
The way you put comment in the code is by using.
// this is used for a single line comment.
Also if you are writing this in the action panel within flash you
will see that there is a color change to grey (by default) to let
you no its a comment.
For a multiple lined comment you have to use a start and stop command.
If you do forget to put in the ” /* “command at the end of your
comment, all the code below the first command ” /* ” will be thought
of as the comment it’s self, plus once again if you are typing this
out in the actions panel you will see a color change of the text to
indicate what’s comment and what’s not.
I hope I explained that well enough…
Hopefully the keyboard function blog will be in the next week.
Tags: Flash, script comments
No Comments »