It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

Adding and Removing a listener?

Moderator: Phate

Adding and Removing a listener?

Postby RichGags on Fri Mar 16, 2007 5:46 pm

Hi,
Im trying to create a game for my 1 year old in flash that shows a letter on the screen. He has to press that letter on the keyboard to move on to the next letter.

So far Ive got this...(for letter a)

Code: Select all
stop ();
var myListener:Object = new Object();
myListener.onKeyDown = function() {
    if (Key.getCode() == 65) {
         play();
}
};
Key.addListener(myListener);


the problem is, when I get to letter b and put this...

Code: Select all
stop ();
var myListener:Object = new Object();
myListener.onKeyDown = function() {
    if (Key.getCode() == 66) {
         play();
}
};
Key.addListener(myListener);


"a" still works. How can I make it so the listener, "resets" or "forgets" any previous letter?

Thanks!
Rich
RichGags
 
Posts: 0
Joined: Fri Mar 16, 2007 5:39 pm

Postby flabbyrabbit on Fri Mar 16, 2007 8:39 pm

I made a small game to see how fast you could type the alphabet in the right order. Anyway I didnt use Listeners or anything complicated it was simply had an invisible MovieClip with the code:

Code: Select all
on (keyPress "a") {
    _root.gotoAndStop(2);
}


And then on frame 2 the code on the MovieClip hanged to:

Code: Select all
on (keyPress "b") {
    _root.gotoAndStop(3);
}


And so on. I hope this helps you to make this game for your child, it sounds like quite a nice game to teach them.

Flabby Rabbit
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England


Who is online

Users browsing this forum: No registered users and 0 guests