MINI SUPPORTERS:

 

 

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

SUPPORTERS:

cloud storage
cloud storage
kirupa.com's fast and reliable hosting provided by Media Temple. Creative web apps. Make your own free flash banners and photo slideshows.
HTML5 CSS3 Mobile Gallery for iPhone, iPad Flash effects. Art without coding.
Flipping Book - page flip flash component. Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery
X-Platform Application Development for Flash Free Flash Components Download - XML Templates, Players and Galleries.

two computer monitors

US Direct

Learn how to advertise on kirupa.com  
 
SHARE:



MINI SUPPORTERS: