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








OnKeyDown Question


Here is what I'm trying to do:
Use the spacebar on a keyboard to toggle a mic on or off, not just mute the mic object but stop it from being published.

The problem with the following code is that as long as you keep the spacebar pressed down it constantly republishes the stream !!!!

################################################## ########## ########

nc = new NetConnection();
spaceBar = new Object();
Key.addListener(spaceBar);

nc.connect("rtmp://192.168.244.101/test");
nc.onStatus = function (info) {
trace("nc: info.code = " + info.code);
if (this.initLight == null) {
light_mc.connect(this);
this.initLight = true;
status_txt.text = "connected";
createNetStream(this);
} else {
status_txt.text = "NOT connected";
}
};
createNetStream = function(nc){
ns = new NetStream(nc);
ns.onStatus = function(info) {
trace("NS.onStatus> info.code: " + info.code);
}
mymic = Microphone.get();
mymic.setRate(11);
ns.attachAudio(mymic);
}
spaceBar.onKeyDown = function () {
status_txt.text = "Pressing talk button" + newline;
trace("Pressing talk button");
ns.publish("myStream", "live");
}

spaceBar.onKeyUp = function () {
status_txt.text = "Stream Stop" + newline;
trace("Stream Stop");
ns.close();
}

################################################## ########## ########

My question, is there anyway I can make it only publish the stream once ?

Thanks Hitman




FlashKit > Flash Help > Flash ActionScript
Posted on: 12-29-2007, 04:36 PM


View Complete Forum Thread with Replies

Sponsored Links:

OnKeyDown...
Hello!

How can I do this:
As long as I press a key, I want to do something with Actionscript, like this
_root.player._x += 10;
But if I copy this expression in the OnClipEvent(KeyDown),
the MovieClip "player" moves only 10px,
if I press the key 10sec or 1sec, there's no difference.

How can I solve this problem ?

Thanx 4 help

Mfg

View Replies !    View Related
OnKeyDown?
Code:
#initclip
//Allow AppSimClass to inherit MovieClip properties
AppSimClass.prototype = new MovieClip();
function AppSimClass (){
// Global variables
this.CMD_BEGIN = new String();
this.CMD_END = new String();
this.CURSOR_POS = 0;
this.FORM_MODE = false;
this.INS_MODE = false;
this.FONT_SIZE = 10;
this.FONT_WIDTH = 7.1;
this.FONT_HEIGHT = 12.5;
this.NUM_CHARS = 65;
this.NUM_LINES = 16;
// Arrays
this.standardKeyArr = new Array();
this.actionKeyArr = new Array();
this.tabArr = new Array();
this.formArr = new Array();
this.conditionArr = new Array();
// Key capturing
this.onkeyDown = function(){
if(Key.getCode() >= 65 and Key.getCode() <=90)
for(i=0;i<this.standardKeyArr.length;i++)
if(Key.getCode() == this.standardKeyArr[ i].code)
this.terminal.text += this.standardKeyArr[ i].symbol;
}
}
This isn't the complete class, but I can't seem to get the onKeyDown function to fire. I had posted earlier, but here it is again. I have never been able to get the onKeyDown event to fire. I've even used the Selection.setFocus("whaterver"); and had no results. Has anyone been able to get this to work?

View Replies !    View Related
OnKeyDown >>> F11
Hi all,

I am trying to use this code as key assingnable play button.
In this case I need it to be assigned to the F11 key only.
But for my surprise, it only works if the combination
Shift+F11 is pressed !!

I exclusively need F11, rather than Shift+F11

Where did I go wrong?




meuObj.onKeyDown = function() {
// ascii c = 122
if (Key.isDown(122)) {
trace("F11 foi pressionado");
}
};
Key.addListener(meuObj);



Tks a lot!

View Replies !    View Related
OnKeyDown (Bug)
I just want to verify that this is happening for others...

If you put this code in a new .fla in MX, and run it using "test Movie" it doesn't trap "<enter>" and a few other keys... But when you try it as an swf, or imbedded in an HTML page, it traps <enter> without a problem...

What up wit dat?


PHP Code:



mainUpdate = new Object();
_root.createTextField("field", 1, 100, 100, 100, 20);
field.border = true;
field.text = "Press a Key:";
//
//doesn't work with <enter> key in "Test Movie"
//but works fine in separate swf or in HTML...
mainUpdate.onKeyDown = function() {
    var theKey = Key.getCode();
    // see, "<enter>" doesn't work
    trace("tracing keyCode:"+theKey);
    field.text = "Key.getCode:"+theKey;
};
Key.addListener(mainUpdate);

View Replies !    View Related
OnKeyDown....
Ok i have this function that also had a listener.
how can i like active this function ONLY for ENTER and not ALL keys...

rename.onKeyDown = function() {

trace("ENTER WAS PRESSED");
Rename();
}

Key.addListener(rename);

View Replies !    View Related
OnKeyDown
Hi, I'm having a problem with onKeyDown.
Code:
Key.removeListener(listener7);
if (Key.getCode() == 80) {
if (upperrightdone == 0) {
delete this.onEnterFrame;
highlightupperleft.gotoAndStop(3);
highlightupperright.gotoAndStop(4);
gotoAndStop(8);
} else {
if (lowerleftdone == 0) {
delete this.onEnterFrame;
highlightupperleft.gotoAndStop(3);
highlightlowerleft.gotoAndStop(4);
gotoAndStop(9);
} else {
delete this.onEnterFrame;
highlightlowerright.gotoAndStop(4);
highlightupperleft.gotoAndStop(3);
gotoAndStop(10);
}
}
}
There is a chunk of code like this for each of the four keys that are used. New keylisteners are deleted and added everytime the game moves back and forth between frames. However this seems to have caused a problem in that if you mash the keys (not just random ones but the ones assigned to various functions, we have built our own controller that only has four keys) down a lot or press multiple ones very quickly the game becomes non-responsive or fails to delete listeners. This leads to highlighted buttons and segments that shouldn't be highlighted, and that will undoubtedly confuse the user. I was wondering if there was a way to 'pad' or protect the code against this somehow? This will be open to a large non-computer savvy public so....

View Replies !    View Related
OnKeyDown
Ok, So I add a listener to listen for an onkeydown. I also have a XML connection going. Here's the deal, whenever the ENTER key is pressed the XML stops functioning. This is only after the onkeydown listener is in the code. Without it everything works fine. Any other key can be pressed and it works fine, but once I hit the enter key it locks up the xml connection or something.

View Replies !    View Related
MovieClip.onKeyDown Help
I have a small of code like this on the first keyFrame:

this.createEmptyMovieClip("control",10);
control.onKeyDown = function(){trace("Keydown");}

But when I press a key, nothing happen. What wrong with my code? Please help me !

Thanks !

View Replies !    View Related
OnKeyUp/onKeyDown
In flash help there is a simple example about this method, but I can't get it to work.

Code:
myMovieClip.onKeyUp = function () {
trace ("onKeyUp called");
};
why don't I get anything? Shouldn't the trace action be triggered when I press any key?

View Replies !    View Related
Disable OnKeyDown?
Ohhh Man. I'm so close here...

This code is in the first frame of my timeline. It works like a charm. But as you can see I've set up a frame label "done". The deal is that I do not want the onKeydown code to work when it is at that point of the time line. Can I disable it? I attached the .fla and if you want to see what I'm doing go here. Then to the "locations" section. I would really appreciate any help. Thank you.

onKeyDown = function () { if (Key.isDown(Key.ENTER)) {funcSubmit(),gotoAndPlay("done");}};
Key.addListener(this);

View Replies !    View Related
Onmousedown, Onkeydown
keylistener.onkeydown

it doesn't actually detect when a key goes down, it just causes an event whenever the key is down.

so when i have a trace() statement for example, instead of tracing every time i press a key (such as in onmousedown()), it traces as long as the key IS down.

any suggestions?

View Replies !    View Related
Does OnKeyDown Only Look Out For The Last Key Pressed?
if for example:


Code:
var mykeyListener:Object = new Object();
mykeyListener.onKeyDown = function() {
trace("Key Pressed");
}
mykeyListener.onKeyUp = function() {
trace("Key Released");
}
Key.addListener(mykeyListener);
If I hold down UP, then at the same time hold down LEFT the program repeatedly writes "Key Pressed". If I then let go of LEFT with UP still pressed the program writes "Key Released" but stops tracing "Key Pressed". Even when I then let go of UP I would expect it to recognise the onKeyUP and trace "Key Released" but it seems to no longer register that up was being pressed at all.


Is there any, preferably simple, way around this?

View Replies !    View Related
OnKeyDown ENTER ?
Hi,

We are trying to get a function to run when the enter key is pressed. However we are not sure what code to be using.


Code:
Key.addListener(_root);

_root.onKeyDown = function(){
trace(Key.getAscii());
trace(Key.getCode());
checkAnswer();
}
However the Enter key does not trigger the event, nor a trace.

Thanks,
Two confused souls

View Replies !    View Related
OnKeyDown Question
Hello, this is my first time on a forum, I hope I do this right ...

I am developing a game in Flash MX 2004 and I am using the onKeyDown() function with a Listener to know what key the user has pressed. I then compare that key with a letter on a block and if it is the same, the block goes up and the ball bounces on it. The problem is the last key pressed is stored somewhere and I can't reinitialize it. For example, if the first block is an "a" block and the user pressed "a" and the second block is also an "a" block, he doesn't have to press the key again for the second block to go up.

I would like to be able to reinitialize the key (if there were a Key.SetKey() that would be great, but that doesn't seem to exist) or to simulate an onKeyDown() or anything else that would work...

Thanks!

View Replies !    View Related
[mx2004]onKeyDown Going To Much
I have a onKeyDown listener and it does trace("you poked a key!!") well, when i run this, and poke a key, i get about 17 'you poked a key's in the output box, does this having somehting to do with the movie going at 32 fps? and if it does, what can i to make it not go like 17 times everytime it hit a key

View Replies !    View Related
OnKeyDown Issue
it's about a gallery -

previous and next buttons r working correctly, just like

tArray = [];
pArray = [];
iArray = [];

so I tried to implement

listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
Key.addListener(listen);


and when pressing the arrow keys it doesn't load the apropriate image!!

The function is the same for the previous and next buttons - so
where's the catch........

What happens with the images is - on the first KeyDown.RIGHT it goes to
the correct image, on the second it goes back to the first image - and ond the third it skips two images ahead, and likewise for the KeyDown.LEFT.

Is it a matter of removing the listener - and where?

thanx for your time - tonni

View Replies !    View Related
OnKeyDown Mix Up... So Confused
So I have this linear photo "slideshow" with forward and back buttons in which the photo frame resizes to fit the image, and I want to add the ability to move through the photos via the arrow keys. However, when I applied the code it advances the photo, but the border is consistently sized to the current photo -1 in the xml (if that makes sense), even thought the same function is applied to both the buttons, and the arrow keys.

The live example can be seen here http://www.bus15.com/clients/shalowitz/Flash/

I've also attached the FLA. Thanks in advance!

http://www.bus15.com/clients/shalowi.../shalowitz.fla

And here's the xml:


Code:
<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<image title="" source="photos/1.jpg"/>
<image title="" source="photos/2.jpg"/>
<image title="" source="photos/3.jpg"/>
<image title="" source="photos/4.jpg"/>
<image title="" source="photos/5.jpg"/>
<image title="" source="photos/6.jpg"/>
<image title="" source="photos/7.jpg"/>
<image title="" source="photos/8.jpg"/>
<image title="" source="photos/9.jpg"/>
<image title="" source="photos/10.jpg"/>
<image title="" source="photos/11.jpg"/>
<image title="" source="photos/12.jpg"/>
<image title="" source="photos/13.jpg"/>
<image title="" source="photos/14.jpg"/>
</portfolio>

View Replies !    View Related
OnKeyDown Question
Hello, this is my first time on a forum, I hope I do this right ...

I am developing a game in Flash MX 2004 and I am using the onKeyDown() function with a Listener to know what key the user has pressed. I then compare that key with a letter on a block and if it is the same, the block goes up and the ball bounces on it. The problem is the last key pressed is stored somewhere and I can't reinitialize it. For example, if the first block is an "a" block and the user pressed "a" and the second block is also an "a" block, he doesn't have to press the key again for the second block to go up.

I would like to be able to reinitialize the key (if there were a Key.SetKey() that would be great, but that doesn't seem to exist) or to simulate an onKeyDown() or anything else that would work...

Thanks!

View Replies !    View Related
OnKeyDown Event
Hi,

I'm new to Flash and AS, but since AS2 became more OO, my interests have grown and I find myself experimenting in flash with AS2 for the past 2 days, non stop...

I'm trying to make a game that responds to keyboard input. Suppose there are 3 keys involved, each with there own MC that should respond in its own way... How to organize the game loop?

Problems I encountered:

1. the onKeyDown event fires multiple times
Doesn't matter how hard or long you push the key, the according event should only be triggered only once per hit...
This is the code I used for handling the key events:


ActionScript Code:
KeyListener = new Object();
KeyListener.onKeyDown = function(){
        if (Key.getAscii() == 49) { // 1
            do_some_thing
        }
}
Key.addListener(KeyListener);


How to force a 1 time execution, for each hit?

2. All entered keys should be handled sequentially
If you hit a key while the action of a previous key-hit is still running, this event should be 'buffered' and fire AS SOON AS previous action finishes. I tried to implement this using the queue methods of an Array type in AS: push, unshift. FIFO handling of events will be respected this way. Problem is though, i keep on getting 'undefined' entries

code is used:

do_some_thing of previous code becomes:

ActionScript Code:
queue.push(1);


the queue object was declared at the beginning of the frame actionscript, and instantiated with the onLoad event of _root:


ActionScript Code:
var queue:Array;
_root.onLoad = function(){
    queue = new Array();
}


Everytime the mainframe is entered the application should check for key-hits in the queue and process them accordingly:


ActionScript Code:
_root.onEnterFrame = function(){
    processQueue();
}
 
function processQueue) {
    if(queue.length > 0) {
        //trace(queue.shift());
        _root.defenseSystem.activatePad(queue.shift());
    }
}


Is this a good gameloop? or should I call processQueue only when a key was hit and call it again when it's busy? (to be more efficient)
How to ensure several actions don't run sync? Just keep a boolean to check wether 'system' is busy or not?


greetz and thx,
Sewdn
AS newbie

View Replies !    View Related
Key.isDown Vs. OnKeyDown
Does anyone know the heirachy of command between Key.isDown and .onKeyDown?

I am programming a game and have a bug where I think this may be an issue.

If I have BOTH at the same time, which one takes precedence? ...if either.

View Replies !    View Related
OnKeyDown On A Movieclip
hi all,

this one works very fine:

//---------------
//code
MovieClip.prototype.Movement = function() {
this.onRelease = function() {
trace("hello");
};
};

//end code


//this one dont work
//---------------
//code

MovieClip.prototype.keyMovement = function() {
this.onKeyDown = function() {
trace("hello");
};
};



whats the problem? and how can I do it?

View Replies !    View Related
Onkeydown Event ,key=a Letter ?
ok i saw someone post this a day or 2 ago ..
wanting to have a keydown event ,with the letter "a" pressed
to trigger an action on a MC ..goto and play or whatever ..
anyone know how to do this .i played around with it for a bit but didnt get it to work .the best i came up with was any key event triggered an action ..lol
even with the key code 65 i believe was the keycode for the letter 'a' still didnt work ..


i would like to see the working code for on a key down event letter a ,b,c or whatever trigger an action ..

;;;;key "a" down, play whatever mc ;;;;;;;

cheers

View Replies !    View Related
Simple OnKeyDown To Hard For Me
Hey gurus.

all i want to do is make a button or MC on my scene change color or alpha when i press a letter on the keybord let's say the letter (A)

eventually i want to make all the keys work the same way

completely lost here.
sorry newbie here.

View Replies !    View Related
Dealing With The Slowdown Of: OnKeyDown?
Hey,

I'm making a RPG but I was having some problems with speed. So I decided to get rid of the onEnterFrame functionc checking for keyPresses and went on using KeyListeners.

Here's my current code:
code: var myListener = new Object();
Key.addListener(myListener);
myListener.onKeyDown = function() {
if (!moveing && !bussy) {
if (Key.isDown(Key.RIGHT)) {
moveRight();
}
//--Rest of keydetection---
}
};
The thing is that it sometimes takes a full second for the computer to react on a keypress (mostly happens when another key was pressed right before). Is there a way to solve this?

Thnx,
SaphuA

View Replies !    View Related
OnKeyDown...break Keyboard :|
Hello once again

I've searched through the forums, and found some snippets on how to capture the Enter keystroke, but even applying some of these techniques seems to not invoke the onKeyDown event!

This is basically what i have:

code:
someListener = new Object();

someListener.onKeyDown = function():Void{
var kcode = Key.getCode();
var bSearch:Boolean = false;

for (var n=0; n<9; n++){
if ((available[n] == 0) && (kcode == letters[n].charCodeAt(0)) && (bSearch == false)){
bSearch = true;
checkPress(n);
}
}
}

Key.addListener(someListener);


Basically it checks to see if the letter is a valid keypress by the user, and if so go and do some work.

Originally i simply had a trace indicating what letter code was pressed. The Enter, Backspace and Delete keys never triggered the trace event.

So, now that it works as expected, i tried to modify it to capture the Enter keystroke. Prior to the for loop i put in something to check if the keystroke was == 13, but it didn't seem to matter. The fact is...the listener.onKeyDown even doesn't capture the keystroke.

I'm using Flash MX2004...and Firefox as my browser...hmmm....Firefox...think i'll go start up IE just to check it out.

View Replies !    View Related
OnKeyDown, GoToFrame [MX2004]
Hello. I want to make it that when you press down the enter/return key, the flash movie will advance to another frame. However, I'm not sure how to script this correctly. What script code do I use, and where do I put it?

Thank you for your help!

View Replies !    View Related
How To Pass Parameter To OnKeyDown ?
my goal is to pass a parameter to an onKeyDown function.
when the user types inside an input text field, i want it to
update a dynamic text field, so that it shows the user what they
are typing.
the following code is what i am trying to do, though it does not work.
any ideas ???


Code:
function watchMeType(myInputTextField,myDynamicTextField){

Key.addListener(_root.myInputTextField);

_root.myInputTextField.onKeyDown = function(){
_root.myDynamicTextField.text = _root.myInputTextField.text;
}

}

View Replies !    View Related
Listening For [Enter] With OnKeyDown
Hi all -- quick question. Can anyone tell me why the [Enter] key doesn't trip the following code ::


Code:
keyListener = new Object();

keyListener.onKeyDown=function(){
trace(Key.getCode());
}

Key.addListener(keyListener);

As far as that code is concerned, the [Enter] key is not a key. Doesn't do a thing. Can anyone help ease my confusion?

View Replies !    View Related
OnKeyDown And Better Way Of Testing Button Up/down
Alright so I pose another question to you ladies and gents of AS.org.

Here's my current dilema. I'm using a Listener to check if I've hit a key or not and it works just fine BUT the problem is that one of the keys is not working. Here's my code so far, the enter key isn't working.


ActionScript Code:
keyListener = new Object();
Key.addListener(keyListener);
keyListener.onKeyDown = function() {
    if (Key.isDown(Key.SPACE)) {
        if (spaceHit == false) {
            //Space wasn't already down
            trace("I've hit The Space Key");
            //Duplicate the vial
            addVial();
            //Move all of the vials somehow
            //Determine whether last vial was good or not
            spaceHit = true;
        } else {
            //Space WAS already down
        }
    }
    //PROBLEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //Next Key
    if (Key.isDown(Key.ENTER)) {
        if (enterHit == false) {
            //Space wasn't already down
            trace("I've hit The Enter Key");
            //Duplicate the vial
            addVial();
            //Move all of the vials somehow
            //Determine whether last vial was good or not
            enterHit = true;
        } else {
            //Space WAS already down
        }
    }
};

That's the first question. Also is there any more effective way of checking if a key is down? I know I still have to write an onKeyUp bit for it so that it'll change the toggles back to true.

Edit: And I DO have enterHit as false. This is why it's perplexing me!

Edit 2: I'm also wondering about some Actionscripted Movement for multiple MC's. I duplicate an MC and before that I move some previously duplicated movie clips. How in the world can I get a uniformic movement for all of the Duplicated MC's? Using a for or while loop just does it too fast! Here's what I've been doing

ActionScript Code:
function moveVial(xDif) {
    while (xDif>0) {
        trace("I'm working!");
        for (c=_root.vialMax; c>=_root.vialMin; c--) {
            _root["vial"+c]._x -= 21.8;
            break;
        }
        xDif -= 21.8;
    }
    //Maybe?
    //The Distance is 109 between vials
}
And xDif is actually defined and is 109 when it firsts starts. Thanks for any help!

View Replies !    View Related
Really Strange Problem With Onkeydown...
Consider for example the simple code:


Code:
var clavier:Object=new Object()
clavier.onKeyDown=function(){

if (Key.getCode()==17) {
trace("press")
Key.removeListener(clavier)
}

}


Key.addListener(clavier)
When pressing the key corresponding to 17, it sometimes gives once "press", but sometimes gives TWICE "press"!!
I realy don't understand how it can give twice "press", even with Key.removeListener(clavier)!

This code is very simplified compared to the code I actually use, but I don't think that there is something which can give this problem in my more complicated code. Since I tried this more simple code, I did not succed in repeating this strange occurence neither in the simple code nor in the complicated one. It seems to appear as random, and once it even gave three times "press".

View Replies !    View Related
OnKeyDown(1) Running On Start
ok, I have all my code in the first frame...

Some reason when I have

Code:
onKeyDown(1)
{
trace("OMG");
}
it doesn't happen when I actually press the left key, but it RUNS as soon as I test!

same with any other functions like

btn.onRelease = //function name

runs straight away, how can I fix this?

View Replies !    View Related
OnKeyDown Doesn't Work.
Hello all.
I really tried, before writing. I'm really confused.
So, program sometimes creates some windows dynamically. (just right in MS Windows)
By pressing ESCAPE button on the keyboard i want to "close" that windows.


ActionScript Code:
var keyListener = {};
keyListener.onKeyDown = function() {
    var theKey = Key.getCode();
    trace("keyCode: "+theKey);
    switch (theKey) {
    case Key.ESCAPE :
        _root.letter.removeMovieClip(); //closes the window
        break;
    }
};
Key.addListener(keyListener);
moreover, even trace doesn't work
the code is written in the first frame.
What am i doing wrong?

View Replies !    View Related
Question About Key.onKeyDown Timing
hi there,

i have a question about the timing of Key.onKeyDown:

usually there are two ways to check for keys in a game:
in the Main loop use:

Code:
if (key.isDown(37)){
do_me()
}
or use the listener:

Code:
this.onKeyDown=function(){
if(key.getCode()==37){
do_me()
}
Key.addListener(this)
now, when i use the first method, the key is checked every time the loop executes, but what about the second ?

does it get updated on every frame of the movie, or does it have it's own interval ?

View Replies !    View Related
This.onKeyDown Isn't Triggered By Enter
I've this in my code:


ActionScript Code:
Key.addListener(this);this.onKeyDown = function() {      trace(Key.getCode());}


which works okay but it dosn't seem to be triggered when I press the enter key (either the main one or the one on the num pad)

anyone know an event I can use where I can capture an Enter key press? I know you can use on(keyPress "<Enter>") in a button but I'd like somethin I can use in the MX style of coding

cheers all

View Replies !    View Related
OnKeyDown Event Not Working
for some reason nothing happens when i press the space bar.

does anyone have any clue as to why.



#initclip
function Climber() {
}Climber.prototype.onKeyDown = function() {
if (Key.isDown(Key.SPACE)) {
trace("boom");
}
};
Object.registerClass("man", Climber);
#endinitclip
Sincerely

Bill

View Replies !    View Related
OnKeyDown Not Working In IE/Netscape
Hi,

I apologize if this is a dupe post... I am very new to this.

I am working from the Flash Photogallery sample here on kirupa.com (very helpful!!).

It seems to me that the keystroke listening stuff only works in preview and in the flash player, not in IE6 nor Netscape 7. Am I missing something? Is this a security limitation perhaps (I am using xpp sp2)?

Thanks,
Chris

View Replies !    View Related
Waiting 1/8th Second To Detect OnKeyDown
Rock Paper Scissors game - again (but soooo close).

How would one go about telling Flash "Hey, if the User does NOT hit the left down or right key within 1/8th of a second then...do something"?

Here's my AS which works and displays a Rock, Paper or Scissors depending on the arrow key pressed, I just need some way to "time out" if they don't press a key quick enough.


Code:

var keyListener_obj:Object = new Object();
keyListener_obj.onKeyDown = function() {
switch (Key.getCode()) {
case Key.LEFT :
RPSUser_mc.getNextHighestDepth();
RPSUser_mc.gotoAndStop(2);
break;
case Key.DOWN :
RPSUser_mc.getNextHighestDepth();
RPSUser_mc.gotoAndStop(3);
break;
case Key.RIGHT :
RPSUser_mc.getNextHighestDepth();
RPSUser_mc.gotoAndStop(4);
break;
}
};
Key.addListener(keyListener_obj);
I have no clue what I would need to search for to do this.

View Replies !    View Related
AtatchSound OnPress Instead Of OnKeyDown?
How could I alter this code so that it works onPress?


Code:
var ranSound = new Sound(this);
ranSound.onPress = function() {
if (Key.isDown(Key.SPACE)) {
this.stop();
this.attachSound("s"+Math.round(Math.random()*11));
this.start();
}
};
Key.addListener(ranSound);

View Replies !    View Related
Getting Slideshow To Advance With OnKeyDown
Hi all,
I've made a thing that loads pictures from an external folder. I have some buttons to where when you press on one it will go to the next picture and when you press on the other one it will go to the previous picture. However, I cannot make it go to the next or previous images by using the arrow keys. I've tried some code but it just doesn't work! If someone could please help me it would be greatly appreciated! Here's the code below (for the whole thing... there's also one button that I have that when it is clicked on it makes the slideshow go automatically. Towards the bottom is where the other two buttons are, and my attempt at the arrow key method.)


Code:

square._alpha=0; // set movie clip called square to transparent i.e. alpha=0
mypic=1; // mypic is a variable we will use to count the images in the show
_root.ssOn=0; // button instance name ssOn is set to 0 or off when the program starts
statTimeSet=0; // staticTime variable set to 0 when the movie starts
_root.onEnterFrame = function() // _root main movie timeline, when movie starts call function
{
if (square._alpha <10) // if square movie contains image with less than 10% transparency
{
loadMovie("images/image"+mypic+".jpg", "square"); // load image1.jpg into movie square
fadeOut=false; // image is not fading out
fadeIn=true; // image fade In is set to true
}
if (square._alpha > 10 && fadeOut)
{
square._alpha -= 10; // if fading fade movie = movie – 10% alpha until faded out
}
if (square._alpha < 100 && fadeIn && !fadeOut) // if image is fading and not Out
{
square._alpha += 10; // increment fade in 10% until completely faded in i.e. 100% alpha
}
else // if image is not fading in or out i.e. has loaded then do not fade in the image
{
fadeIn=false;
curTime = getTimer(); //create a variable curTime and set it to the current time object
if(!statTimeSet) // if stat Time variable is not set then set
{
statTime=curTime; // set static time = Current time built in
statTimeSet=1; // set statTimer to 1 or ON
}
if ((curTime >=statTime + 5000) && mypic <= 79 && !fadeIn && !fadeOut && _root.ssOn)
{
trace("curTime" + curTime)
trace ("statTime" + statTime)
fadeOut=true;
mypic++;
if (mypic > 79) // do not use >= or it will skip the last slide
{
mypic=1;
}
statTimeSet=0; // make sure this line is outsidet the if statement above it
}
}
// Below is code for the buttons
next.onRelease = function(){
if(mypic < 79 && !fadeIn && !fadeOut)
{
fadeOut=true;
mypic++;
}
if(mypic >= 79)
{
mypic=1;
}
}
back.onPress = function()
{
if(mypic > 1 && !fadeIn && !fadeOut)
{
fadeOut = true;
mypic--;
}
if(mypic == 1 && !fadeIn && !fadeOut)
{
fadeOut = true;
mypic = 79;
}
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
if(mypic > 1 && !fadeIn && !fadeOut)
{
fadeOut = true;
mypic--;
}
if(mypic == 1 && !fadeIn && !fadeOut)
{
fadeOut = true;
mypic = 79;
}
} else if (Key.getCode() == Key.RIGHT) {
if(mypic < 79 && !fadeIn && !fadeOut)
{
fadeOut=true;
mypic++;
}
if(mypic >= 79)
{
mypic=1;
}
}
}
Key.addListener(listen);
}
}

View Replies !    View Related
This.onKeyDown Isn't Triggered By Enter
I've this in my code:


ActionScript Code:
Key.addListener(this);this.onKeyDown = function() {      trace(Key.getCode());}


which works okay but it dosn't seem to be triggered when I press the enter key (either the main one or the one on the num pad)

anyone know an event I can use where I can capture an Enter key press? I know you can use on(keyPress "<Enter>") in a button but I'd like somethin I can use in the MX style of coding

cheers all

View Replies !    View Related
OnKeyDown Event Not Working
for some reason nothing happens when i press the space bar.

does anyone have any clue as to why.



#initclip
function Climber() {
}Climber.prototype.onKeyDown = function() {
if (Key.isDown(Key.SPACE)) {
trace("boom");
}
};
Object.registerClass("man", Climber);
#endinitclip
Sincerely

Bill

View Replies !    View Related
OnKeyDown/timeline Problem
i'm having a problem with a game character, where the animation is freezing where it should be looping.

[swf= width=256 height=240]http://www.ambethia.com/flash/LOLO.swf[/swf]
http://www.ambethia.com/flash/LOLO.swf

as you can see, it plays through once, then gets stuck on the second frame of the part it should be looping. this is only happening while a key is held down on the keyboard, once you let the key off the animation continues looping again (if you take out the onKeyUp bit that stops the animation on the first frame).


ActionScript Code:
Key.addListener(lolo_mc);
 
lolo_mc.onKeyDown = function() {
    // set lolo's direction and tell him to move
    if (Key.isDown(Key.DOWN)) {
        loloDir = "down"
    }
    if (Key.isDown(Key.UP)) {
        loloDir = "up"
    }
    if (Key.isDown(Key.LEFT)) {
        loloDir = "left"
    }
    if (Key.isDown(Key.RIGHT)) {
        loloDir = "right"
    }
    this.gotoAndPlay(loloDir);
    loloMove = true;
}
 
lolo_mc.onKeyUp = function() {
    // unlike the other directions, lolo has a special frame for when he's facing forward
    if (loloDir == "down") this.gotoAndStop("home")
    else this.gotoAndStop(loloDir);
    loloMove = false;
}


i've got the character set up as a movie clip with every frame from his animation in a single timeline, using labels as a reference to the starting point of each direction, with a gotoAndPlay at the last frame pointing back to the labeled frame again.

this seems like a simple/logical way to set up the characters animation, am i missing something?

thanks!

i'm new at flash, this is my first attempt at a game.

the FLA file

View Replies !    View Related
OnPress And OnKeyDown Question?
Is it possible to include onPress and onKeyDown in the same function? For example, this doesn't work but something like this:

button.onPress.onKeyDown("A") = function(){
//something
}

View Replies !    View Related
OnKeyDown Function Is Doubled
This has been bugging me for days:

I'm making a movie where the menu needs to be controlled by keys as well as mouse. When you enter the menu screen a function literal is attached to a Key listener to keep track of which is the currently active button. I do this by increasing decreasing a counter with -1/+1

The problem is that when a user returns to this screen after viewing another section, the value is increased / decreased by 2! As if the function is doubled. This results in every other button being skipped. It even happens when I explicitely reset the key Listener and its onKeyDown event.

Please check this code if you have some spare time:

ActionScript Code:
// this handles the product navigation with left and right keys
var count:Number = 1;
this["prod"+count].gotoAndStop("_over");
_root.keyCatcher.onKeyDown = function(){
    clipPath = _root.products_mc
    if (Key.isDown(Key.RIGHT)) {
        clipPath["prod"+clipPath.count].gotoAndStop("_up");
        if (count<11) {
            clipPath.count+=1;
            clipPath["prod"+clipPath.count].gotoAndPlay("_over");
        } else { // reset
            clipPath.count = 1;
            clipPath.prod1.gotoAndPlay("_over");
        }
    } else if (Key.isDown(Key.LEFT)){
        clipPath["prod"+clipPath.count].gotoAndStop("_up");
        if (count>1) {
            clipPath.count-=1;
            clipPath["prod"+clipPath.count].gotoAndPlay("_over");
        } else {
            clipPath.count = 11;
            clipPath.prod11.gotoAndPlay("_over");      
        }
       
    } else if (Key.isDown(Key.ENTER)){
        _root.gotoAndStop("product"+clipPath.count);
    }
}



Many many TIA,


.soma

View Replies !    View Related
YourMC.onKeyDown=function(){...}
yourMC.onKeyDown=function(){...}


OK. has anyone ever got this event working? I also used

yourMC.focusEnabled=true;
yourMC._focusrect=true;

so I would be able to see when a particular movieclip receives focus. When I test this (unfortunately i cannot use debugger due to the TAB needing to step through focus toggles the debugger) apparently Flash doesn't recognize focus EVEN THOUGH graphically it is showing focus via _focusrect.

can anyone shed more light on the onKeyDown function as it relates to movieclips?

View Replies !    View Related
OnKeyDown/Numpad Handling?
I wonder how to tell Flash to make a difference between pressing the regular CURSOR DOWN key and the NUMPAD CURSOR DOWN key.

I use a catch key function:


Code:

function CatchKey() {

//Catches various keys

var keyListener:Object = new Object();
Key.addListener(keyListener);

keyListener.onKeyDown = function(){
trace(Key.getCode());
PressEnter = 0;
if (Key.getCode() == 40 and cboKeyword._visible==false) {
txtKeyword.text = "GO TO THE SOUTH";
PressEnter = 1;
}

}



In my reference book I see that the Ascii-Code for the Numpad Key "2" (=CURSOR DOWN) should be 98. Yet when I trace the keypress, I get 40, which is the regular cursor down key. So it seems I cannot really determine which key is pressed. - Or have I overlooked something?

Artimidor

View Replies !    View Related
Random Sound OnPress Instead Of OnKeyDown?
How could I alter this code so that it works onPress?


Code:
var ranSound = new Sound(this);
ranSound.onPress = function() {
if (Key.isDown(Key.SPACE)) {
this.stop();
this.attachSound("s"+Math.round(Math.random()*11));
this.start();
}
};
Key.addListener(ranSound);

View Replies !    View Related
OnKeyDown Inside A Custom Class?
I can't seem to get onKeyDown to work inside a custom class?

Anyone get it to work?

View Replies !    View Related
OnKeyDown Sound Latency Problem
Hello guys,

Im in quite a pickle here. I've been developing an online application that involves the use of the keyboard to generate sound events. since its a musical application, the precision of this action is integral to its proper functioning.

i have been doing all my development, and tests, on a PowerBook G4 1.5Ghz (not the fastest machine in the world, but a decent and solid one) with Flash 8 installed (publishing flash 8 SWFs), and have been aware for a while that Flash is supposed to be smoother / quicker on a PC than on a Mac.

The app runs perfect on a mac, almost no latency; however on PC's there is an audible latency from the moment u press the key to the moment the sound is heard. i've stripped down the app to make sure that its not some other calculation affecting its responsiveness. ive stripped it down to the point where the only thing going on is:

key.listener > sound.start

and still the PCs show a pretty audible latency. ive searched everywhere for anything realted to this. is it a flash player problem? is it a PC keyboard speed problem? no idea.

this is the code i have on my movie:

var sound1:Sound = new Sound();
sound1.attachSound("m01.wav");

var now:Number;

version.text = "version: " + _root.getSWFVersion();

var myListener:Object = new Object();
myListener.onKeyDown = function () {

sound1.start();

pressed.text = "Pressed: " + Key.getCode();

}



myListener.onKeyUp = function () {
pressed.text = "";

}

Key.addListener(myListener);


And the movie can be found here (for testing purposes):

http://heavy-mental.com/test.swf


Any help will be insanely appreciated.

Thank you
federico

View Replies !    View Related
OnKeyDown, OnKeyUp Scripting Question
Hi all-

Maybe I'm missing something obvious, but I can't quite figure this one out. Is there any way to check and see if a specific key has been relased? I'm working on a game that currently works great with a mouse, but I'm trying to convert it so that it works with keyboard as well. Right now I have a function that is called by an onMouseDown event, and then a separate function called on the onMouseUp event.

I'd like to do the same thing with the keyboard, and I've come very close through a few different ways, but nothing quite gets me there.

Make sense? Let me know if you need more info...

The "ideal" code would go something like this:










Attach Code

onKeyDown(Key.SPACE) {
do something ONCE;
}
onKeyUP(Key.SPACE) {
do something else ONCE;
}

View Replies !    View Related
Key_Listener.onKeyDown Dependa On LoadMovieNum() ?
My SWF has Key_Listener.onKeyDown

On "M" it callas function which toggles between mouse.show and mouse.hide
On "R" it reloads itself using
loadMovieNum("filename",0)

It works fine except after reloading, every press of M causes the toggling
function to be called two times.
Another reload causes the function to be called three times every time M is
pressed.
Naturally, the mouse toggles only when the function is called un-even number
of times, and therefore the whole thing works only when the file is reloaded
even number of times.

What might be the reason for that and how shall I sort it out?

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved