Keyboard Events

Adobe, Flash, Learning | Posted by antirealism
Feb 23 2009

Here we go finally,

Only a small exercise due to most of the code is the same as the last few exercises, so in this One there was not much for me to try to remember :)

so first off in this we have to make the ” EventListener ” listen to the stage for an event, the reason for this is if we call up the instance name, like I did on the other codes, we would have to select the item before it would move, so if we make the whole stage active the listen will find the Object without us having to click on it.
Here we will be using Key_Down (press) and the Key_Up (release)
I have chosen to make the item jump as we press the button and on release the item will return to position.

Here is the code…

stage.addEventListener(KeyboardEvent.KEY_DOWN, jump);
stage.addEventListener(KeyboardEvent.KEY_UP, land);

//stage listener so we dont have to select Object

function jump(event:KeyboardEvent):void
{
Man_mc.y -= 100;
}
//jump up 100 pixels

function land(event:KeyboardEvent):void
{
Man_mc.y += 100;
}
/*man drop back to the original
place which is down 100 pixels*/

To test this flash movie please click in box first or click this link.
TESTMAN


I would like to add that if u hold down space bar the object (the man) will fly off screen. This is because the drop down is a listener, soon I will be learning how to make it return to its position and not run away.

Thank you for reading

Next it will be timer event…

Share and Enjoy:
  • Twitter
  • Facebook
  • Google Bookmarks
  • Print
  • del.icio.us
  • RSS
  • email
  • Digg
  • StumbleUpon
  • Live
  • Ping.fm
  • Slashdot
  • MySpace

Script Comments

Adobe, Flash, Learning | Posted by antirealism
Feb 23 2009

Well hello again, just thought I would say thank you to the people
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.

// :void will return nothing in code.

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.

/* event.target.x += 10
event.target.y += -25
this is where the items
will move up 10 across 25 */

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.

Share and Enjoy:
  • Twitter
  • Facebook
  • Google Bookmarks
  • Print
  • del.icio.us
  • RSS
  • email
  • Digg
  • StumbleUpon
  • Live
  • Ping.fm
  • Slashdot
  • MySpace

Update and Explanation.

Adobe, Flash, Learning, Photoshop | Posted by antirealism
Feb 01 2009

well I have been looking at my own blog exercise 1 and I have come to the conclusion that I did not explain the code in any shape or form and for me to show u what I have learned and hopefully help others understand a little more of what goes in flash coding, I have broken the code down a bit..

“Square_mc” This is the name I gave to the object on the stage. This is called the instance name. Also I used _mc to let me no it’s a movieclip. all objects on the stage need to have a instance to be called up in the code, there is Three symbol types Movieclip _mc, Button _bt and Graphic _gc , this also can make it easier to read the code at a later date.

The “addEventListener” is the way we tell flash to listen for an event. After this we have to let flash know what this event will be, in this it was a “MouseEvent”.

“MouseEvent.CLICK” is really as it says; the event will be a click event so as You press down on the mouse button the event will start.

we then give the event a name, in this I call it “onclick”, this could have been anything but it good to put something in relation to what you want to happen, also to make it easier for you to come back to it at a later date.

With “onclick” now the name of the function that will run, we have to let flash know what will be carried out once the item as been clicked on.

The “:void” part of the code is there to let the program know that we do not need a return a value from the event.

When the “square_mc” is clicked the object will then move up by 10 pixels ” x += 10″ and across 25 pixels y “+= -25″ with a rotation of 11 degrees “rotation += -11″ I put these value in by random they could have been anything.

Then at the end of this program there is “Square_mc.buttonMode = true;” which tells flash to treat “Square_mc” like a button, so when the cursor goes over the object it will show that the item is clickable.

Well that’s it, if you now go to the second exercise and read throw the code, I hope this would have given a better understanding of what’s going on in each part.

Thank you for reading …

Share and Enjoy:
  • Twitter
  • Facebook
  • Google Bookmarks
  • Print
  • del.icio.us
  • RSS
  • email
  • Digg
  • StumbleUpon
  • Live
  • Ping.fm
  • Slashdot
  • MySpace