Flash CS3, CS4 Tutorial, Keyboard Contols
70Flash CS4 Tutorials
Flash Tutorials
- CSS, How To
Great Blog Dedicated to sharing great CSS Tutorials and How To Guides. - Flash CS4 Tutorials
List of Flash CS3 and CS4 Tutorials in ActionScript 3.0 - IT Admin
IT Admin is you home for all computer related issues. Stop by and check out what is going on in the it world from a real it professional. - Flash CS4 Tutorials
Adobe Flash CS4 And CS3, The Information you really need is a website and ebook deidcated to provideing quality Flash CS4 Tutorials. - Flash CS3 Tutorials
Gordon French is a Flash Developer. You have found His Free Flash CS3 Tutorials - Flash CS3 Tutorial, Arrow Keys
ActionScript 3.0 Tutorial on how to make an object move with the arrow keys.
Flash CS4 Tutorials, ArrowKeys
Balloon
When working in Flash CS4 the key board is just as important as the mouse. However, many web sites over look keyboard intractability. If you want your site to stand out, use keyboard controls. If you test the code below you will see that whenever you press a key Flash tells you a key has been press. Thats great, but what if you want to know when a specific key is pressed. Well then you Continue Smileyneed to know the key codes. I have included a list of these codes at keyCodes
This sample of code will detect when a key is pressed then if that key was the space bar, it will output that you pressed the space bar.
function hearKey(yourEvent:KeyboardEvent):void{ if (yourEvent.keyCode==32){ trace("you pressed the space bar"); }; }; stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKey);
Make an Object Move (Arrow Keys) Ok, so are you ready to do something useful with keyboards events. Let us start with a basic element that any flash game needs, the ability to move an object around the stage.
In this Flash CS4 Tutorial I will teach you how to move a Movie Clip around the stage. In future Flash Tutorials, I will teach you how to detect if an object has hit another object but for now lets just work on getting control of an object. You will need the source files for this tutorial. Source Files
In this file you will find three layer. The actions layer which will as always contain the code or ActionScript you are going to use. The balloon layer which in this case has an instance of a hot air balloon name balloon_mc. and he last layer, background which contains a nice sky scene for the balloon to travel in. Some of he work has once again been done for you. The instance of the balloon is properly named balloon_mc. If you try this project on your own remember that all objects must be named in the properties panel for ActionScript to be able to use them. Please add the example code to the first key frame in the actions panel.
function hearKey(yourEvent:KeyboardEvent):void{ if (yourEvent.keyCode==Keyboard.RIGHT){ trace("ballon is moving"); }; }; stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKey);
First we need to create a function to listen for the key strokes. Listeners need to be applied to an object, but this time the object is the stage. So, we will use stage.addEventListener. We have already covered this code so lets continue to the fun stuff. Please add the new code inside the function you just created, see example. If you test your movie at this point you will see the out panel say the balloon is moving when you press the right arrow key. We use the trace feature to test that the function and if statement is working properly.
Now, we need to actually make the balloon move. We are going to do this by telling balloon_mc to move 5 pixels to the right. In ActionScript 3.0 that looks like balloon_mx.x += 5. That means add 5 pixels to the current x position. Please remove the trace tag and add the code in the example. Press control-enter to test the movie. If your code is correct the balloon will move to the right when the right arrow key is pressed.
function hearKey(yourEvent:KeyboardEvent):void{ if (yourEvent.keyCode==Keyboard.RIGHT){ balloon_mc.x+=5 }; }; stage.addEventListener(KeyboardEvent.KEY_DOWN, hearKey);
We are almost done, all that needs to be done is to add an if statement for the other three arrow keys. Remember that in Flash the stage is made up of x and y coordinates. To move an object you will either add or subtract from it current position. That means to go left you will subtract 5 not add. Look closely at the finished code and you will see how the math works. Look closely at the up and down keys, the math it opposite of what you would first think. That is because in Flash 0 is not the center it is the top left corner to Flash 10 is farther towards the bottom of the stage then 5. Therefore, adding makes the object go down.
Congratulations, You now have a a Flash CS4 Movie with Interactive Arrow Keys.
IT Admin
- CSS, How to understand inline and block level elements.
Block level elements are normally displayed as blocks with line breaks before and after. Examples of block level elements include paragraphs, headings, divs and block quotes. Inline elements are... - 3 months ago
- CSS, How To tweak css for only Safari?
If you have spent anytime dealing with CSS you have run into issues with a browser rendering code incorrectly. You may even have gone as far as to make several style sheets and use a browser check... - 3 months ago
- CSS, How to Hide Styles from Older Browsers?
Some older browsers, such as Netscape Navigator 4 and IE 4, have poor support for CSS. It is possible to hide styles from these browsers using specific media types and @import rules. All styles will... - 3 months ago
- CSS, How to use @import styles
@import Styles? Header and external style sheets also can import other style sheets using the @import rule. The @import rule must be placed before all other rules in the header or external style... - 3 months ago
- CSS, How to use External Style Sheets!
The third method of applying styles to document involves linking to external style sheets. External style sheets are the most appropriate method for styling documents. If styles need to be... - 3 months ago
- CSS, How to Use Header Styles
Header styles also can be used to style the <p> element. The CSS rules can be placed in the head of the document using the style element. Like inline styles, header styles, header styles... - 3 months ago
- CSS, How to Apply Inline Styles.
CSS, Inline styles can be applied directly to elements in the HTML code using the style attribute. However, inline styles should be avoided wherever possible because the styles are added to the HTML... - 3 months ago
- Twitter Weekly Updates for 2009-08-09
New blog post: CSS, What is a <div> http://bit.ly/Sbfu # Flash, ActionScript tutorials on loops http://bit.ly/QMq8t # Great PHP Tutorial on using include and require. Include is a great way... - 3 months ago
CSS, How To
- Twitter Weekly Updates for 2009-11-22
The maker of iFart is sending a message to Steve Jobs and Apple: http://digg.com/d31ARUx?t # An Open Appeal to Steve Jobs: http://digg.com/d31ARUx?t # Powered by Twitter Tools - 5 days ago
- CSS, How to work with content areas.
The content are of a box can be given width, height, and color. Width and height can be specified in points (equal to 1/72 of an inch), picas (equal to 12 points), pixels, ems, exes, millimeters, centimeters, inches, or percents. - 2 months ago
- Twitter Weekly Updates for 2009-09-20
My Farmville is broken, cant access, gifts, market, or ribbons # Farmville and zynga are a rip off. Watch out. There are still some glitches in the game and zynga told me to bad Im unimportant. # wouldnt it make more since for a developer to fix broken issues rather then add new features. Well not farmville, [...] - 2 months ago
- Twitter Weekly Updates for 2009-09-06
I need 5 more neighbors on FarmVille help me out. http://bit.ly/tLsni # looking for flash tutorials and how to guides check out – http://frenchsquared.com/ # Powered by Twitter Tools - 3 months ago
- Twitter Weekly Updates for 2009-08-30
New version of Wordpress theme adStyle is live at: http://wordpress.org/extend/themes/adstyle # Just finished installing OS X 10.6 on my new Solid State drive. Very impressed, seems noticeably faster. # I need more neighbors on Farmville for Facebook. Hit me up as a friend. http://bit.ly/tLsni # playin farmville on my macbook 10.6 and new solid sate sata II [...] - 3 months ago
- CSS, How to properly use Border Styles.
The border properties specify the width, color and style of the border of an element. Shorthand border properties include border-top, border-bottom, border-right, border-left and border. - 3 months ago
- CSS, How to Padding Padding and more Padding
Padding can be applied to the outside edges of the content area of any block level or inline element. Padding creates the space between the edge of the element and its content. - 3 months ago
- Twitter Weekly Updates for 2009-08-23
Wordpress liked my theme. They have asked that a make a few revisions and resubmit. Sounds like my theme may get accepted! # how long does it normally take for wordpress to get back to you after submitting a theme? # Just finished update my first wordpress theme http://wordpress.org/extend/themes/adstyle # New wordpress theme made for adsense check it out [...] - 3 months ago
PrintShare it! — Rate it: up down flag this hub








