# Keyboard and buttons

**URL:** <https://forum.kirupa.com/t/keyboard-and-buttons/186225>\
**Category:** Uncategorized\
**Created:** [April 19, 2006, 9:24pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225 "2006-04-19T21:24:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anya](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anya](https://forum.kirupa.com/u/anya)\
**Post date:** [April 19, 2006, 9:24pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/1 "2006-04-19T21:24:24Z")

</div>

I am creating a TV remote. I have buttons 0-9. I would like to be able to use the arrow keys to move between the numbered buttons and then hit enter to select them. I would like all the normal funcions of the different button states (up, over, down) to still work. When the button is pressed, I would like to have an external swf file load. I know how to do this part, just not the arrow keys. I have read a couple tutorials on moving objects with arrows, but I would like mine to be stationary.

Also, when you select a button, I would like a display to show the number you selected, and be able to do double digits. Like a real TV remote. So, pressing 1, gives you a 1. Then arrow to 9, select it, and the display reads 19. Then it loads the “channel” or swf file.

Thanks

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 20, 2006, 2:19am UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/2 "2006-04-20T02:19:47Z")

</div>

Ok…this is going to require something similiar to a tile-based RPG. I do not master in tile-based RPGs, but rather in art-based. So I cannot help you unless I figure out something. But right now, I have shat-loads of homework and I am tired from baseball and crap today. I will be back on tomarrow and hopefully I will have a code. So hold on, you’ll get your code soon!

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 20, 2006, 3:24am UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/3 "2006-04-20T03:24:12Z")

</div>

Alright, I came up with it earlier than I would think I can. This is to select and put in all of the information. The catch is, that I couldn’t find a way to make the buttons change different colors or anything. Really, all this script does, it just uses the array I made, and has nothing to do with the movie clips. Here is the code I have so far:

```auto
//Put this all in the current frame that will hold your buttons
var row:Number = 0;
var col:Number = 0;
var btnpad:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
function enterInfo(num:Number):Void {
    if (Key.isDown(13)) {
        if (txt+num<100) {
            txt += num;
        } else {
            txt = "";
            txt += num;
        }
    }
}
function switchBtns():Void {
    if (Key.isDown(37)) {
        col--;
    } else if (Key.isDown(38)) {
        row--;
    } else if (Key.isDown(39)) {
        col++;
    } else if (Key.isDown(40)) {
        row++;
    }
    if (row<0) {
        row = 0;
    }
    if (row>2) {
        row = 2;
    }
    if (col<0) {
        col = 0;
    }
    if (col>2) {
        col = 2;
    }
    enterInfo(btnpad[row][col]);
}
onEnterFrame = function () {
    switchBtns();
};

```

I will try to make the part that makes the selected button and I will post it on here. Hope I helped…even more!

------------------------_UPDATE_-------------------------------  
I have fixed it. Put in the code below in the current frame, as you did in the above script I proposed. Now have every MovieClip in your pad labeled with the instance names from “1-9” depending on the button it is(for example, for button 1, it would have the instance “1”, and so on…). Then, put in the second script I will supply you(below the one below this text), in each of the MovieClips that you have on stage. Here is the \_root frame script:

```auto
var row:Number = 0;
var col:Number = 0;
var btnpad:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
function checkSelection(mc:MovieClip):Void {
    if (mc._name == btnpad[row][col]) {
        mc.gotoAndStop(2);
    } else {
        mc.gotoAndStop(1);
    }
}
function enterInfo(num:Number):Void {
    if (Key.isDown(13)) {
        if (txt+num<100) {
            txt += num;
        } else {
            txt = "";
            txt += num;
        }
    }
}
function switchBtns():Void {
    if (Key.isDown(37)) {
        col--;
    } else if (Key.isDown(38)) {
        row--;
    } else if (Key.isDown(39)) {
        col++;
    } else if (Key.isDown(40)) {
        row++;
    }
    if (row<0) {
        row = 0;
    }
    if (row>2) {
        row = 2;
    }
    if (col<0) {
        col = 0;
    }
    if (col>2) {
        col = 2;
    }
    enterInfo(btnpad[row][col]);
}
onEnterFrame = function () {
    switchBtns();
};

```

Here is the second script, to be put in each of the movieclips:

```auto
onClipEvent (enterFrame) {
    _root.checkSelection(this);
}

```

There, I hope I helped you solve your problem. If you still have problems, I will upload my .fla for you to see. Good luck on your…remote for your TV, lol!

---

<div class="post-metadata">

**Author:** ![anya](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anya](https://forum.kirupa.com/u/anya)\
**Post date:** [April 20, 2006, 8:19pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/4 "2006-04-20T20:19:15Z")

</div>

Ok. This is what I did. I have a empty movie clip on the stage that I would like to load all the files into. I clicked on clip, with the instance name of “empty,” and put your second code for the movie clip in.

On my action script layer, I entered the first script you gave me. I entered the movie clip name. Now when I test the movie, it is giving me action scripting error. It reads:

**Error** Scene=Scene 1, layer=A, frame=1:Line 5: The class ‘empty’ could not be loaded.  
function checkSelection(mc:empty):Void {  
Total ActionScript Errors: 1 Reported Errors: 1

Here is the action script I put in for the buttons:

var row:Number = 0;  
var col:Number = 0;  
var btnpad:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];  
function checkSelection(mc:empty):Void {  
if (mc.\_empty == btnpad[row][col]) {  
mc.gotoAndStop(2);  
} else {  
mc.gotoAndStop(1);  
}  
}  
function enterInfo(num:Number):Void {  
if (Key.isDown(13)) {  
if (txt+num\<100) {  
txt += num;  
} else {  
txt = “”;  
txt += num;  
}  
}  
}  
function switchBtns():Void {  
if (Key.isDown(37)) {  
col–;  
} else if (Key.isDown(38)) {  
row–;  
} else if (Key.isDown(39)) {  
col++;  
} else if (Key.isDown(40)) {  
row++;  
}  
if (row\<0) {  
row = 0;  
}  
if (row\>2) {  
row = 2;  
}  
if (col\<0) {  
col = 0;  
}  
if (col\>2) {  
col = 2;  
}  
enterInfo(btnpad[row][col]);  
}  
onEnterFrame = function () {  
switchBtns();  
};

I attached my .fla file

---

<div class="post-metadata">

**Author:** ![anya](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anya](https://forum.kirupa.com/u/anya)\
**Post date:** [April 20, 2006, 8:21pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/5 "2006-04-20T20:21:48Z")

</div>

Ok. I fixed the action script error, I shouldn’t have put the movie clip name (mc:MovieClip), so that is fixed. However, the file still doesn’t do anything when I use the keyboard.

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 20, 2006, 11:02pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/6 "2006-04-20T23:02:40Z")

</div>

Here, this is the .fla I used, go ahead and analyze how I did it. Then you can optimize to what you want. I tried, sorry…

---

<div class="post-metadata">

**Author:** ![anya](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anya](https://forum.kirupa.com/u/anya)\
**Post date:** [April 21, 2006, 1:53pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/7 "2006-04-21T13:53:08Z")

</div>

Sorry, I can’t open the file. It says unexpected file format.

---

<div class="post-metadata">

**Author:** ![chrisisjargon](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@chrisisjargon](https://forum.kirupa.com/u/chrisisjargon)\
**Post date:** [April 21, 2006, 9:48pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/8 "2006-04-21T21:48:20Z")

</div>

> [@anya](#):
>
> Sorry, I can’t open the file. It says unexpected file format.

download it again as this sometimes happerns when downloading the files, i have just tryied it and works ok.

---

<div class="post-metadata">

**Author:** ![cobrasniper555](https://avatars.discourse-cdn.com/v4/letter/c/838e76/32.png) [@cobrasniper555](https://forum.kirupa.com/u/cobrasniper555)\
**Post date:** [April 22, 2006, 10:42pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/9 "2006-04-22T22:42:50Z")

</div>

Well…it’s flash 8…Do you have flash MX PRO?

---

<div class="post-metadata">

**Author:** ![anya](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@anya](https://forum.kirupa.com/u/anya)\
**Post date:** [April 24, 2006, 1:31pm UTC](https://forum.kirupa.com/t/keyboard-and-buttons/186225/10 "2006-04-24T13:31:28Z")

</div>

nope. Flash MX 2004
