Listener+gotoAndPlay 2004-03-10 - By Jim Cheng
Back IsK wrote:
> It's a kids 'secret agent' game. I want it to listen for a sequence of > letter/numbers whilst the rest of the game plays. On the stage I have a > movie clip and on hearing them sequentially it should move from frame to > frame, within its movie clip with the final frame launching the browser.
Hmm, it might be easier to do it all from a single listener in Actionscript. This keeps things organized in one place.
I'd do something like the following, and place it in frame 1. An additional group of frames follow, the number being equal to the total characters in the code word, e.g. eight additional frames in this example for the eight letter "codeword":
<code>
/* Change secretListener.word and secretListener.url to suit your needs and put this code in frame 1 of the movie. */
// Define a new listener object var secretListener = {}; secretListener.word = 'codeword'; secretListener.url = 'http://www.google.com/'; secretListener.ptr = 1;
// Define a handler for onKeyDown secretListener.onKeyDown = function() { // See if they entered the next letter... if (Key.getAscii() == this.word.charCodeAt(this.ptr)) { // Go to the next frame if it's correct gotoAndStop(this.ptr++); // If the entire code is entered, go to the URL if (this.ptr == this.word.length) { getURL(this.url); } } }
// Add the listener Key.addListener(secretListener);
</code>
Regards, Jim
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ Supported by Fig Leaf Software -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ Lower Prices for Certified Training! Check out new lower prices for Certified Macromedia Training from Fig Leaf Software. Expand your skill set with courses in ColdFusion, Flash, Rich Internet Applications and .NET in the new year. Fig Leaf Software provides the highest caliber instruction at our training centers in Washington D.C., Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location.
Get the details at http://training.figleaf.com/ -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- To unsubscribe, e-mail: flashnewbie-unsubscribe@(protected) For additional commands, e-mail: flashnewbie-help@(protected)
|
|