Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




KeyPress Function



Right now I have this code:

Code:


for (var i = 0; i<8; i++) {
...
_root[answerBox].onPress = this.doPress;
...
}


But I want to be able to access it with the keyboard such as this (w/ pseudo code)


Code:


for (var i = 0; i<8; i++) {
...
_root[answerBox].on(keyPress i) = this.doPress;
...
}



Is there anyway to make that possible?
Thanks for your help!



DevShed > Flash Help
Posted on: July 11th, 2007, 01:37 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Keypress Function?
so i have a button so when you click it, it sends out a soldier. I want it so you can be able to click the button AND press something on the keyboard.

I have tried

Code:
soldiersSelect.sendBtn.Key.isDown(49) = function() {
but that doesnt work.

Is there anyway to do this without a onEnterFrame loop?

XML Function On Keypress
Hi, I have the following actions in my root.


Code:
function loadXML(loaded) {
if (loaded) {
//main window
_root.news = this.firstChild.childNodes[x].childNodes[2].firstChild.nodeValue;
_root.ntitle = this.firstChild.childNodes[x].childNodes[0].firstChild.nodeValue;
_root.date = this.firstChild.childNodes[x].childNodes[1].firstChild.nodeValue;
_root.stuff.newsMainWindow.text = _root.news;
_root.stuff.newsMainTitle.text = _root.ntitle;
_root.stuff.newsMainDate.text = _root.date;
//left bar
_root.subText1 = this.firstChild.childNodes[y].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews1.text = _root.subText1;

_root.subText2 = this.firstChild.childNodes[y+1].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews2.text = _root.subText2;

_root.subText3 = this.firstChild.childNodes[y+2].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews3.text = _root.subText3;

_root.subText4 = this.firstChild.childNodes[y+3].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews4.text = _root.subText4;

_root.subText5 = this.firstChild.childNodes[y+4].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews5.text = _root.subText5;

_root.subText6 = this.firstChild.childNodes[y+5].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews6.text = _root.subText6;

_root.subText7 = this.firstChild.childNodes[y+6].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews7.text = _root.subText7;

_root.subText8 = this.firstChild.childNodes[y+7].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews8.text = _root.subText8;
} else {
trace("file not loaded!");
}
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("new.xml");
And then in the Stuff movie clip (I really need to work on naming my MC's ) I have a button, when I press that button, it increments _root.x by one I need to reload the XML information to the second firstchild.


Code:
on(press)
{
_root.x = _root.y+1;
trace(_root.x);
}
And Finally, The XML.


Code:
<newsfeed>
-
<new>
<title>Site Updated</title>
<date>30/12/04</date>
-
<news>
I have finally updated this site to use a flash interface
</news>
</new>
-
<new>
<title>Site Not Updated</title>
<date>30/11/04</date>
<news>lalalalala</news>
</new>
</newsfeed>
Any help is greatly appreciated.

Just to make sure everyone knows what I want to do, is reload the XML data when X=1, if X=0 then it works fine (with the "Site Updated" news) but I am not sure how to get the data again for "Site Not Updated".

Cheers, Gazler.

UPDATE, I got this working eventually

XML Function On Keypress
Hi, I have the following actions in my root.


Code:
function loadXML(loaded) {
if (loaded) {
//main window
_root.news = this.firstChild.childNodes[x].childNodes[2].firstChild.nodeValue;
_root.ntitle = this.firstChild.childNodes[x].childNodes[0].firstChild.nodeValue;
_root.date = this.firstChild.childNodes[x].childNodes[1].firstChild.nodeValue;
_root.stuff.newsMainWindow.text = _root.news;
_root.stuff.newsMainTitle.text = _root.ntitle;
_root.stuff.newsMainDate.text = _root.date;
//left bar
_root.subText1 = this.firstChild.childNodes[y].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews1.text = _root.subText1;

_root.subText2 = this.firstChild.childNodes[y+1].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews2.text = _root.subText2;

_root.subText3 = this.firstChild.childNodes[y+2].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews3.text = _root.subText3;

_root.subText4 = this.firstChild.childNodes[y+3].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews4.text = _root.subText4;

_root.subText5 = this.firstChild.childNodes[y+4].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews5.text = _root.subText5;

_root.subText6 = this.firstChild.childNodes[y+5].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews6.text = _root.subText6;

_root.subText7 = this.firstChild.childNodes[y+6].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews7.text = _root.subText7;

_root.subText8 = this.firstChild.childNodes[y+7].childNodes[0].firstChild.nodeValue;
_root.stuff.subNews8.text = _root.subText8;
} else {
trace("file not loaded!");
}
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("new.xml");
And then in the Stuff movie clip (I really need to work on naming my MC's ) I have a button, when I press that button, it increments _root.x by one I need to reload the XML information to the second firstchild.


Code:
on(press)
{
_root.x = _root.y+1;
trace(_root.x);
}
And Finally, The XML.


Code:
<newsfeed>
-
<new>
<title>Site Updated</title>
<date>30/12/04</date>
-
<news>
I have finally updated this site to use a flash interface
</news>
</new>
-
<new>
<title>Site Not Updated</title>
<date>30/11/04</date>
<news>lalalalala</news>
</new>
</newsfeed>
Any help is greatly appreciated.

Just to make sure everyone knows what I want to do, is reload the XML data when X=1, if X=0 then it works fine (with the "Site Updated" news) but I am not sure how to get the data again for "Site Not Updated".

Cheers, Gazler.

UPDATE, I got this working eventually

On (keyPress 'q') = Function
hi everyone

im looking for a way to achieve the classic on keypress x gotoandplay routine, yet without tagging the attributes to a button on stage.

in other words:

any way to do this via actionscript in some manner of

on Keypress('x') = function() { movieclipname.loadmovie(''x.swf") };

the last few lines must seem like the babblings of an illiterate in actionscript (which i am), but i wouldnt know how else to put this...

help please.

cheers!

KeyPress Function
I am trying to create some hot keys in my app and I am having problems with the keyPress function. I have used it in the past for single key presses like the enter key or left and right arrows but never in conjunction with other buttons. Any know how to code a keypress event for two buttons like Alt+L or Alt and some other button?

On Keypress Function Key Control?
Can anyone tell me if it's possible to use On Keypress with a button to detect Function Keys or specify the value of the key like in the onClipEvent keydown way? The examples that are always shown show only <left>, <right> etc. keys but never whether you can detect function keys or if there are keys that are unavailable to On Keypress with a button.

I'm sure using onClipEvent would be preferable but I'd like to know what limitations if any other ways have.

Thanks,

Paul

Function KeyPress Error
I am having a problem with a seemingly simple piece of code. I would like to play my movie once I have pressed F12.

Here is my code...Where is the error at? What is the correct scripting?

on (keyPress "<123>") {
play();
}

I understand that 123 is the key code for F12. Do I need to complicate it with listeners?

Thanks for any help.
Syndessol

KeyPress To Call A Function?
I'm using the FlippingBook component to create an online catalog. I have a "go to page" functionality set up whereby the user can enter a page number and click the "go_btn" movie clip to go to that page.

How do I also add this functionality to the "enter" key? I want the "enter" key to do the same thing as clicking the "go_btn". The code shown below is on the first frame along with an instance of the "go_btn" and the book instance "myBook". Thanks for your assistance!


go_btn.onPress = gotoPage;

myBook.onPutPage = function() {
myBook.flipOnClickProp = false;
var res = "";
if (this.leftPageNumber && this.rightPageNumber) {
res = this.leftPageNumber+" / "+this.rightPageNumber;
} else if (this.rightPageNumber == 0) {
res = this.rightPageNumber;
} else if (this.leftPageNumber && !this.rightPageNumber) {
res = this.leftPageNumber;
}
current_page_txt.text = res;
};

function gotoPage() {
var destPageNumber = Number(page_number_txt.text);
if (!isNaN(destPageNumber)) {
myBook.flipGotoPage(destPageNumber);
}
}

KeyPress Function Not Responding
Hey there,

I'm trying to implement a keyPress function in my navigational controls as a result of some user feedback, but I'm having trouble identifiying why my ActionScript isn't working. The navigational buttons are stored within a movie clip in the main timeline, and use exactly the same code as I have been using before, albeit with a keyPress function in the top, e.g.:


Code:
on (release, keyPress "<Right>") {
_root.nextFrame();
this.gotoAndStop("allEnabledR");
}
This doesn't work.

However, I made a new movie consisting of two simple keyframes and used exactly the same button and it DID work!

What would cause the button to work in one movie, but not the other?

The button still responds to the 'release' part of the code (that is it behaves as normal when clicked on), but not the 'keyPress' part.


Any ideas?

Function KeyPress Error
I am having a problem with a seemingly simple piece of code. I would like to play my movie once I have pressed F12.

Here is my code...Where is the error at? What is the correct scripting?

on (keyPress "<123>") {
play();
}

I understand that 123 is the key code for F12. Do I need to complicate it with listeners?

Thanks for any help.
Syndessol

Zoom (right-click) Function With A KeyPress?
I'd like to have a user be able to press + or - and have the file zoom in and out ... similar to the right-click > Zoom in/out function.

I searched around here but can't seem to answer my question.

Thanks in advance.

Such Thing As A Global Function For Keypress?
After doing searches here and elsewhere, and since I'm fairly new to this, I'm looking to controll a projecter using Global functions.
I need to do this by only using keys on the keyboard. space would be for next scene, right arrow for next scene, left arrow previous scene, less than is previous frame, greater than is next frame, end is stop and Home goes to movie beginning.

Am I able to control this way without having to put code in each frame or scene to stop? Appreciate input, help, an example or place to refere to.

Thanks

Pausing Animation By On KeyPress Function
Hi, i try to make pausing in animation using on (keyPress "<Space>") function, a have read tutorial Pausing Animation http://www.kirupa.com/developer/mx2004/pause.htm ,in this tutorial is used butons but i need with on (keyPress "<Space>")

I try
Code:
on (keyPress "<Space>") {
play();
}
not work, please help

[CS3] Stopping The KeyPress Function From Repeating When Key Held Down
Hi,

It is important that I use the keyPress function for this to work rather than a listener.

When keyPress is used I want a score to be increased by 10 but that it wont keep increasing by 10 when held down. I want it to only increase by another 10 when the key has been released and then pressed again.

Can anyone help with this?

[F8] Quick "tranlastion" From Button Function To Keypress
Right, as my program is set,
you have type something into the input box and then click a button for something to happen onscreen.
So, im trying to find a way to cut the middle man and convert
sendBtn.onRelease = function(){place switch case here} into
a keypress.
That way, you could just hit enter after you're doing typing rather than
having to go click the button.

Does anyone know how i can do this?

Keypress F5, F6, Etc
How can I get the keypress event of F5, F6, etc... I know I can't do it directly with flash, but maybe Javascript... kinda lost here...

On KeyPress Help
Anyone know how I can have Flash recognize the user pressing the F4 key for the on keyPress event?

Keypress
I'm making a personal "babybanger" game for my son, to teach him the meaning of letters, numbers and shapes...here goes:

I have movies (A-B) with each 4 frames containing different pictures which start with the current letter i.e B = Ball or Baby....., each frame has a stop action.

In my main scene I have a button with this script:


on (keyPress "b") {
_root.b.swapDepths(1);
tellTarget ("b") {
play();
}
}

So when he hits the "b" key it will play the next frame of the B movie.

The problem being that the B movie keeps playing through all the frames as long as he holds down the key, I just want it to play one frame every time he hits the "b" key.....I could really use an action with :
on (keyRelease "b") instead but can't seem to find out how.

KeyPress Help Please
I am creating a piano swf and upion the press of a key I want the button the the piano look like it is in its down state. I have placed the movieclip and given it the instance name "KeyPress1" on the stage the gave it an alpha value of "0" and then placed the following script on it.

on(keyPress "q") {
KeyPress1._alpha = 100
}

And that works except that when I release he key "q" I want the movieclip instance to change back to a "0" value and therefore not be visible and furthermore I want to make sure that while the key "q" is being pressed that the alpha value stays at "100"

How can I accomplish this? Somebody please help

Thanks in advance,
Josu

Keypress
how do i detect keypress of numbers like 3. I want to put on a frame with a stop action , a movie clip turns invisible, and a action where when you press 3, that movie clip turns visible again.
thanks.

On Keypress....
Hi all, I'm new at the flashkit-forums.

I've surfed around flashkit a lot to have a look at some sources and I learned a lot of them.

I'm certainly not a flash-expert, I'm just in a learning fase. I think it is a great programming language for web applications.

I made my first game (well actually my second, but the first one isn't really worth mentionning), and I have a little problem with it. I added it to the movies--> games -section of flashkit (although it didn't get approved yet (how long does that take normally?)).

It's a typing test game I made just to get a bit the hang of actionscripting. It tracks wich key is pressed and if it is the same key as the letter apearing on the screen then the score goes up.

No some people told me that a good adition would be that the score goes down when someone presses a wrong key. I just don't see how to implement that.

Here is how I made it: I have 26 frames and in each frame there's a letter I converted to a button. That button tracks if the key is pressed of the letter wich appears on the screen. If randomly goes to another frame (with another letter)... There's a timer included wich ends the game after 30 seconds.

Here is the code I used for tracking the key:


Code:
on (keyPress "a"){
_root.score++;
gotoAndPlay(random(26)+2);
}
I tried adding the following to let the score goes down when a wrong button is pressed but it doesn't work off course:


Code:
on (keyPress !"a"){
_root.score++;
}
Anybody has any idea on how I can implement such thing?

Thanks in advance,

greets Rob

(I attached the source-code of my game)

Keypress Help
Ok im doing a project that it set up like a video game, and want to make it two players... I have all the coding for the question generator done, but how can i go about using key strokes for contestants to "buzz in" on my game? And to also keep a tally of thier score.

Thanks any help would be appreciated!

KeyPress
I would like that this function would also be executed when i press a Key, how can i do this?

Thanks for any help.

JGraca

a1.onPress = function() {
mov1(a1, 1);
gotoAndPlay(17);
};

Keypress
can someone help me with this, just tell me what to put inside the condition

if ('Alt + Shift is pressed'){
...
}

thanks

MaX_BoY

On KeyPress In An Exe?
I'm trying to have an invisible button in a flash projecter take you back to a scene on keyPress.....its not working....does it not work in an exe?

also, is it possible to use the F1 key?

any help appreciated...

Keypress Help
Here is what I want,

I want my movie to play till the end, then stop. After it stops, I want to be able to press enter, which, in turn, would send it to the next scene. I tried the following, but to no avail. Any help would be GREATLY appreciated.

--------------
stop();
on (keyPress "<Enter>") {
gotoAndPlay(Slide2, frame 1);
}

--------------

Slide2 = Scene 2

Also, I did name my frame instance on Scene 2 "frame 1". So that is not the problem. Thanks in advance

On Keypress Help
what is the code word for if they keypress one of the numbers at the top of the keyboard.

Thanks

On (keypress)
Hello,

I have tried to implement on (keypress) and it just has not worked I have a button on the main timeline with the following code...

code:
on (release, keyPress "<Enter>") {
resultSet = "Loading...";
loadVariablesNum(varPath + "/asp/stu_login.asp", 0, "POST");

}
on (release, keyPress "<Enter>") {
gotoAndPlay(148);
}


When I go to test it pressing the enter key does not advance the movie.

Keypress Help
Ok, does anyone know why this doesn't work?:


Code:
_root.currentwep = "Handgun";

//make weapons changeable
if (Key.isDown(Key.SPACE)){
_root.currentwep = "Shotgun";
}


I don't understand why it wont work when in previous games ive made it has worked. Anyway, thx.

On(keypress...
Is it possible to use other then the predefined keys for this command? For instance Command I. If not is there a work around?

Thanks in advance for any help

Keypress Help
hey, i know that you can use the keypress with up,down,left,right and some other buttons,
but what is the script for normal letters, e.g. a, s, d, w

any help would be good, thanks

jason

Keypress
could anyone help me, basicaly im using this script to make a car go forward when you press the UP button.

onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
speed += 1;
}

the problem is that i would like to change it so that you press the W button instead.

can anyone help

jaosn

KeyPress
I have this code on a button in a project:

on (rollOver) {
containerA.unloadMovie();
}
on (release, keyPress "<Right>") {
trace("The Right Arrow key was pressed");
clearInterval(timer);
goToAndPlay("81start");
containerA.attachMovie("PlayStatSymbol", "PlayStatSymbolA",1);
script50.stop("50.mp3");
}

The "keyPress" part does not work. So I took this code and put it into small file (attached) and it works fine. Any idea why it won't work in my other file?

KeyPress
What is wrong with this keyPress command?

Code:
def.onEnterFrame = function(){
x4 = this._x
y4 = this._y
y5 = y4
x5 = x4
x5 += 46
y5 += 40
y4 -= 40
if ((((guy._x > x4) && (((guy._y > y4)) && ((guy._x < x5))) && (guy._y < y5)))) {
if (keyPress "1") {
def.play();
}
}
};

dont mind the part in bold its a substitute for a hitTest command.

On Keypress...
Hi,
I tried to make a page with a very little flash movie, height=1 width=1
I wanted to make it possible to press a key on a page and there will be an other page loaded. So people will be be quicker on browser through the website.

But it doesn't work, because you have to select the movie first (almost impossible when the movie is 1 by 1 px) before you can press a key. Is there a way to avoid this? I really don't want to make a movie wich you first have to select before you can use the shortkeys



the page is located here:
http://bcounter2.techroll.nl/

The flash movie will only appear when you are logged on:
username: Kaffa
password: qwerty
its located under the image with the text "jouw profiel" above it.

on the button in the movie I have:

Code:
on (keyPress "b"){
getURL("index.php?p=bewerk_profiel", "_parent")
}
on (keyPress "p"){
getURL("index.php?user=" + user, "_parent")
}
on (keyPress "u"){
getURL("index.php?p=upgrade_profiel", "_parent")
}
on (keyPress "c"){
getURL("index.php?p=casino", "_parent")
}
on (keyPress "s"){
getURL("__________allpages/shoutbox/_shoutbox_add.php?user=" + user, "shoutbox")
}
on (keyPress "r"){
getURL("JavaScript:radio_stream(220,305)")
}
on (keyPress "l"){
getURL("index.php?action=log-out&redirect=1", "_parent")
}

On(keyPress) Bug?
I had a scroller that was working perfectly using the on (keyPress "<Down">) script. Then it just stopped working. I dismantled the script and the button and re-did the whole thing, but still no success.

Is there some kind of bug at work here? Has anyone else ever experienced an event handler just dying like that?

[F8] Keypress
I have build a lot of simulations in captivate and this time it’s just not cutting it, so I have to bring it into flash for the interactivity. JOY

Here is what I’m trying to do. I want the user to have to hold down ctrl while pressing the down key to have the move play; they will probably have to do this five times. So is it possible to handle multi key presses in flash?

Thanks in advance
Drizzle

Keypress
If I want to use the arrpw keys to move an object, there seems 3 ways top do it.

1 uses on(kepress..), 1 uses getascii key amd the other uses an event handler.

What is the difference between the 3

Keypress
If I want to use the arrpw keys to move an object, there seems 3 ways top do it.

1 uses on(kepress..), 1 uses getascii key amd the other uses an event handler.

What is the difference between the 3

Keypress
Hi experts,

Is there an alternative to using 'Keypress' when detecting keyboard actions? The problem is with 'keypress' only detecting one key at a time - if one is making a game for example, with keys to detect movement and shooting, ideally you would want it to detect more than one keypress at a time so you can move and fire at the same time without one interrupting the other.

Thanks in advance,

ADE

Keypress
Hi,

I am very very new to flash but coming along alright. I was wondering if there is a simple way to know when a key has been pressed. I dont care which key it is, I just want to know a key have been pressed on the keyboard

Thanks

[CS3] Keypress
I am pretty new to flash and now I having a hard time getting any further. This a class project I am working on.

Right now the program responds to key press but I want a pause between key press to avoid just flying through the whole thing.
The FLA can be found at

http://www.geocities.com/islamicgames/kalpha1.fla

Thanks

Keypress
If I want to use the arrpw keys to move an object, there seems 3 ways top do it.

1 uses on(kepress..), 1 uses getascii key amd the other uses an event handler.

What is the difference between the 3 ?

Any Way To Allow One Keypress OR Another?
If I have four buttons that can be clicked in my scene, is there any way to allow either "1" OR "a" to control the first one, "2" OR "b" for the second, etc?

I know I can combine different mouse events:


Code:
on (release, keyPress "1") {
gotoAndPlay(2);
}
... where the comma essentially says on release OR when pressing "1".

But when I do different keyPresses:


Code:
on (release, keyPress "1", keyPress "a") {
gotoAndPlay(2);
}
to say on mouse release OR when pressing "1" OR when pressing "a"... I get a duplicate event error. I've tried using || and various other things, and none of my efforts or searches have resulted in anything.... What would the syntax be for this? Thanks!

Keypress Fun..
Hi, i`ve made a simple character and used the key listener to get him responding to the keyboard (move left, right, up down, punch and kick). But, when i press and hold a key to move him there is a delay (he moves then waits then continues to move) - can i get rid of that? Also, there is a two-frame walk-cycle and when he moves left or right i want it to play continuously - but it doesn`t, it plays only once unless i keep rehitting the move key. Is there a known issue with this or a workaround for it?

Any help is greatly appreciated always, thanks!

More Keypress Fun
I have a car symbol which is moved around the stage using the UP, DOWN, LEFT and RIGHT arrow keys. The movement is working fine, but I want the car to be correctly orientated to the direction it is moving. I have acheived this when moving up/down by changing the yscale value, but cannot achieve the same when moving left or right. My code is as follows:


Code:
onClipEvent(enterFrame) {

_global.speed = 5;

if (Key.isDown(Key.UP)) {
this._y -= _global.speed;
this._yscale = 100;
}

if (Key.isDown(Key.DOWN)) {
this._y += _global.speed;
this._yscale = -100;
}

if (Key.isDown(Key.LEFT)) {
this._x -= _global.speed;

}

if (Key.isDown(Key.RIGHT)) {
this._x += _global.speed;
}
}
Any help would be most appreciated.

KeyPress
I'm creating a presentation (like PowerPoint). I would like to have my points come in with a differnt effect one at a time when I press the down arrow and then go to the next slide when I press the right arrow. Do I need to make each point in a separate .swf file and load each file on press? But I would like to have all my points stay on screen untill I go to the next slide. Is this possible? I'm using the McTween pluging to control my effects, I don't know if you need to know that or not, but I am.

-Thanks

On KeyPress How To?
Hi,
I would like to attach a movieclip from the library when I press the keyboard key "A". (or any other key for example)

I can't get ot to work, Please help me!!

I am using it this way:

on (keyPress "<space>"){
_root.attachMovie("myMovie_mc", "newmyMovie", _root.getNextHighestDepth());}

Keypress Help
hello,

I am completely stuck, as a newby to actionscript, yet trying to undertake in my eyes an impossible task, maybe you can help!

what i want to do is this. I have designed an animated alphabet- now i want to attatch then to keys of the keyboard so when you press the letter then on the screen it pops up. Then if left idle for 15 seconds fades out to the blank screen again. So i have all these individual animated letters as movie clips, i just need to know how to script the whole thing together!

if anyone has any info or can reffer me to a good tutorial i would be forever grateful!

thanks.

Copyright © 2005-08 www.BigResource.com, All rights reserved