1. Home
  2. Computing & Technology
  3. Animation

[D-i-Y] Christmas Tree Ornaments that Move with Drag & Drop or Arrow Keypresses

By Adrien-Luc Sanders, About.com

8 of 9

Key.isDown(***) checks to see if the key specified inside the parentheses is, as the script might indicate, pressed/down. It returns a value of true or false, but doesn’t do anything else; that’s what we need the if statement for. It evaluates whether or not the specified key is pressed, and if the value returned is true, then it performs the function inside the brackets.

Each key is defined by Key.KEYNAME, and each key has its own unique name (you can check Flash’s in-program ActionScript reference for a full list of the strings and numbers assigned to each key). For each if statement, we check to see if one of the four arrow keys is pressed, and then adjust the position of the symbol referenced by _root.active accordingly.

For instance, if the statement testing to see if the up arrow was pressed returned a true, then the script would subtract three pixels from _root.active’s current y position, moving it up horizontally by three pixels with every press of the key. If the statement testing the right arrow’s status returned a true, then the script would add three pixels to the current x position, moving it three pixels to the right with every press.

So what’s _root.active? It’s the ornament that’s currently selected as the one that’s going to move when those keys are pressed. The last step covers defining the most recently clicked ornament as the active one.

Explore Animation
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Animation
  4. Flash Animation Tutorials
  5. Do-It-Yourself
  6. [D-i-Y] Custom Christmas Tree Ornaments that Move with Drag & Drop or Arrow Keypresses

©2009 About.com, a part of The New York Times Company.

All rights reserved.