Flash / AS

Silverlight

WPF

ASP.net / PHP

Photoshop

Forums

Blog

About

 


FlashComponents
  Galleries
  Slideshows
  Menus
  Design & Effects
  Audio & Video
  User Interface
  Templates

 

 

Multiple Key Detection - Page 7
       code by Michael Avila, written by Kirupa  |  3 April 2006

In the previous page, we dived through more of our checkCombinations method. Let's pick up from where we left off and go back to our second for loop and try again. The value of j is still 1, but the value of i is now 1:

if (keys_pressed[1] == key_combinations[1][2])

Just like before, when we map the values referenced by our array indices, we get:

if (90 == 90)

This equates to true! So far so good. Let's proceed on to the next if statement:

if (1 == key_combinations[1].length - 2)

This time, this too holds true. The length of our key_combinations[1] array minus 2 does equal 1. We now execute the following line of code:

     invokeOnKeyCombination (key_combinations [j][0]);

The value of j, of course, is 1. Substituting in the values from the key_combinations array, we get the following:

key_combinations -> [[redo, 17, 89], [undo, 17, 90], [paste, 17, 86]];

The item referenced by index position 1 (j = 1), is:

[undo, 17, 90]

The 0th object is the string value undo. In short, the invokeOnKeyCombination function takes in the argument undo. If you recall from earlier, the invokeOnKeyCombination simply maps your input to the case/switch statement you designated in your FLA file:

myObj.onKeyCombination = function(name:String) {
switch (name) {
case "undo" :
message_txt.text = "Undo Combination Pressed";
break;
case "redo" :
message_txt.text = "Redo Combination Pressed";
break;
case "new" :
message_txt.text = "New Combination Pressed";
break;
}
};

A text field called message_txt will display the sentence "Undo Combination Pressed." Excellent. You are good to go!


Conclusion
I hope this tutorial helped you to incorporate key detection in your animations. More importantly, this tutorial should have provided your more practice with using, accessing, and manipulating data stored in nested arrays.

If you are interested in seeing my implementation of the animation on the first page of this tutorial, I have provided the source file for it:

If you have any questions, please post them on the forums.

Michael Avila (MichaelxxOA)
CreateAge.com
   

Huge Grin

Kirupa Chinnathambi (kirupa)
kirupa | MIT

 

 

1 | 2 | 3 | 4 | 5 | 6 | 7


kirupa.com's fast and reliable hosting provided by Media Temple. flash components
The Text Animation Component for Flash CS3
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.
Check out our high quality vector-based design packs! Flash Effect Components

Flash Templates
CSS Templates
Dreamweaver Templates

flash menus, buttons and components
Digicrafts Components The best flash components ever!
Entheos Flash Website Templates Free Flash Page Flip
flash components Buy and sell FLAs at Ultrashock!
Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com Purchase & Download Flash Components
Learn how to advertise on kirupa.com