Coder Profile - Show off your skills, get a coder profile.
 
 
 
Actionscript Events
Programming
Events are the heart of Actionscript. Without them, you are pretty much completly rendered helpless when creating, pretty much anything, in Flash. Events are basically different actions that if performed, follow through with a block of code.

For example:
Code Copy / Restore
  1. function onMouseDown() {
  2.          trace("Mouse Pressed");
  3. }
What this code does is it places the mouseDown() event into a function and traces (outputs) the text "Mouse Pressed" when the user clicks the mouse.

There are three different ways to use events... On movieclips, on buttons (now depreciated since Actionscript 3.0 and Adobe Flash CS3) and on frames.

When placing events on buttons, the syntax is quite simple:
Code Copy / Restore
  1. on (event) {
  2.          //code
  3. }
Example:
Code Copy / Restore
  1. on (press) {
  2.          trace("Mouse Pressed");
  3. }
The same method goes for the same with movieclips.


Placing events on frames is a little bit different... You can access them in a few ways:
Code Copy / Restore
  1. function onMouseDown() {
  2.          //code
  3. }
Code Copy / Restore
  1. onMouseDown = function() {
  2.          //code
  3. }
Code Copy / Restore
  1. myMC.onMouseDown = function() {
  2.          //code
Code Copy / Restore
  1. onMouseDown = myFunction;
  2.  
  3. function myFunction() {
  4.          //code
  5. }
The first code block inserts the event into a function and follows through with the code when it has happened. Remember, all events (not placed on buttons or mc's) must be placed on in a function syntax, or else it won't work.

The next code block is the same as the first, but with different syntax.

The third places the event directly on a movieclip, so it has direct access the that movieclip (the syntax also applies to that when on a movieclip, so you still need to call _root when reffering to other objects).

The final one places a the event on a seperatly declared function, so you can switch the functions around when you want to.


Finally, here's a list of every the most used events and what they do:

onMouseDown- When the mouse button is clicked

onMouseUp- When the mouse button is released

onMouseMove- When the user moves the mouse

onMouseWheel- When the mouse wheel is used

onLoad- When the frame/movieclip/button first loads

onEnterFrame- Runs the function the number of your fps per second

onPress- When a button or movieclip is pressed

onRelease- When a button or movieclip is released

onReleaseOutside- When a button or movieclip is released outside of its bounding box

onRollOver- When a button or movieclip has the mouse moved over it

onRollOut- When a button or movieclip has the mouse moved off of it

onKeyDown- When the user presses any key on their keyboard

onKeyUp- When the user releases any key on their keyboard

onSetFocus- When an object recieves focus

onKillFocus- When an object loses focus


Posted By mikeMarek
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
Page 1 of 1
More Articles By This Author
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
if/else, switch/case and ?/: Statements In Actionscript 2.0
Recently Posted "Programming" Articles
N-Queens-Series Part I (Only the fittest survive)
Currying in JavaScript: Fun for the Whole Family!
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
Quick Threading Tutorial - C++
C++ And Me (A Love Story)
First look at C
Introduction to Pseudo Code
Integrating your website with PHP
Recently Rated "Programming" Articles
[C++] Templates
Quick Threading Tutorial - C++
Intorduction to memoization.
N-Queens-Series Part I (Only the fittest survive)
[PHP] Create A Unique Page Hits Counter
Currying in JavaScript: Fun for the Whole Family!
Actionscript Events
First look at C
if/else, switch/case and ?/: Statements In Actionscript 2.0
Actionscript API
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Internet & Web Sites (1)
Life In General (2)
Operating Systems (3)
Other (2)
Programming (48)
Security (10)
Software Development (5)
Web Development (15)
search Search Inside
Programming
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved