ActionScript :: Can Track Keys Pressed
Apr 29, 2011Can I track the keys pressed, using ActionScript?
View 1 RepliesCan I track the keys pressed, using ActionScript?
View 1 RepliesI am struggling a bit with keys on the keyboards controlling a movieclip to happen.Ive got a person moving when pressing right and left, and a movieclip with three frames: First frame is a movieclip with the person standing still, looking bored. The second frame is the person moving right, and the third frame is the person moving left.This is the code that Ive inserted into the persons actions on scene1:
if (Key.isDown(Key.RIGHT)) {_x += speed;this.gotoAndStop(2);_xscale = +scale;}
if (Key.isDown(Key.LEFT)) {_x -= speed;this.gotoAndStop(3);_xscale = -scale;}
this code works alright accept that when the keys are not pressed it doesnt stand still, the legs are still moving, so I tried to include this code aswell:
if (!Key.isDown(KEY.RIGHT)) [code]....this makes the person standing still when not pressed but not moving the legs when turning right and left.
How do you detect when to keys are pressed together. For example, if I press W and E together, I want something to happen. How do I do that?
View 5 Repliesif (Key.isDown(Key.RIGHT)and (Key.isDown(Key.LEFT){
trace("both pressed");
i am trying to write the syntax to detect left and right cursor keys .pressed down at same time.
Im unclear why this code is not working? What am i doing wrong?
ActionScript Code:
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
[code].....
I am doing a Flash game for school with parallax scrolling. Though I am going a much simpler way of the art, I am having one major error. My error is that when I stop pressing the Up Arrow Key, my ship does not move. All that my ship does, is sit there doing nothing, except for the following; exhausting fuel and showing the flame animation. Detecting if the Up Arrow Key (evt.keyCode == 38), I have tried both code below:
ActionScript Code:
!evt.keyCode == 38
and
ActionScript Code:
evt.keyCode != 38
Cannot Detect All Key pressed onKeyDown
Here is the code I used:
Code:
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: " + Key.getCode() + " ACSII: " + Key.getAscii() + "
[Code]....
It is an usual code to listen the key presed on the keyboard. For some reason, I cannot detect any letter-key exept letters "w", "x", "d" and "J". I tested it on a different computer and results are the same. It is driving me crazy. I am not sure what is the problem.
I'm developing a little game. I use the following code to detect the keys pressed by the player:
[Code]...
Basically the shootKey will be hold down by the player almost all the time. And the changeColorKey will be pressed very often but not hold down. While testing I noted that holding the shootKey and the right arrow down, the onKeyUp events for the changeColorKey don't get fired. Holding the up or down arrow key instead of the right arrow has the same effect. If I hold the left arrow key the events get fired. Why does it occour? Is there something wrong with my code?
I want this code to move my map i.e map_mc when the keyboard keys are pressed. When I add it to the map_mc, I see no effect what do u think I am messing with.
Code:
on (keyPress "<Left>") {
currentX = this._x;
this._x = currentX - 2;
} on (keyPress "<Right>") {
currentX = this._x;
this._x = currentX + 2;
} on (keyPress "<Up>") {
currentY = this._y;
this._y = currentY - 2;
} on (keyPress "<Down>") {
currentY = this._y;
this._y = currentY + 2; }
I've followed the thread there: [URL]
I understand that this class allow the script to detect when keys are pressed in combination.
But what is exactly the implementation when a key is used both in single and combination states. Let's say that you've the "q" key used alone and "shift-q"...how would one proceed to achieve this detection?
I want to detect which keys are pressed while user input text into TextField.I tried something like
import flash.text.TextFormat;
import flash.text.TextField;
import flash.events.Event;[code].......
but this doesn't work.
ive tested my game on several different computers. it works well on my desktop, but 2 laptops suffer an issue when left, space and up are all simultaneously pressed... thus the character is unable to move, jump and shoot at the same time
View 2 RepliesCreate a listener that will wait for a combo of keys pressed to launch a command? Something like if they type "admin" it will trigger a function.
View 2 RepliesI have it like this so far:
ActionScript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, KeyReleased);
public function KeyPressed(event:KeyboardEvent):void
[Code]....
and so far it works good, except when I press shift. If I'm holding the left or right arrow key and then I press shift, the object stops moving and doesn't do anything. However, if I release the arrow key and THEN press and hold shift, it works perfectly. How can I make it so that I can press shift while I'm holding the arrow key and still have it work?
in actionscript, Is there a way i can make a coddition happen if 2 keys at once are pressed?
example:
if (Key.isDown(Key.SHIFT) && (Key.isDown(Key.LEFT) && _currentframe == 1)) {
gotoAndPlay("running_left");
} else if (Key.isDown(Key.RIGHT) && (Key.isDown(Key.RIGHT) && _currentframe == 1)) {
gotoAndPlay("running_right");
}
or can't i do shift and left/right?
Im having a problem getting responsive keyboard movement. I have a key_up listener which fails to trigger when 3 keys are down. E.g. Imagine up and right keys are being pressed to move up + right. The user wants to change to moving up + left. The user presses the left key before lifting thg right key. I have a key_up listener to detect when a key is no longer being pressed. However in this scenario it fails to trigger when 3 keys are pressed. Even in this online example, there is the same problem, look how unresponsive it is when chaging from up right to up left really quickly. [URL]
[Code]...
whether using a String as the key in a Dictionary results in slower lookups than using an Object, Class or Custom Object (an instance of developer defined Type)?
When using a String as a key, does the literal String have to be parsed, or does the Dictionary key point to the String Object?
How do I get the AWSD keys to work as smoothly as the arrow keys. I can put the arrow keys inside an enterFrame
[AS]onClipEvent (enterFrame) {
//move the tank
if (Key.isDown(Key.RIGHT)) {
[Code]....
If I put the AWD keys inside an enterFrame they run until I push another button
I have a function on root:
_root.fadeBox_mc.onEnterFrame = function (){
if (fade){
this.nextFrame();[code]....
This causes a mc to fade in and out on rollover/rollout. But what I wanna make is a box that fades in when pressed on the button and fade out when pressed for the second time. But if I say
on (press){
_root.fade = true;
}
the mc fades in, but I cant do another on (press) to fade out. Is this too confusing?
The buttons on the page cause a jump to the individual movies (the web pages) which are on one layer concurrently. What I have right now works and now I want to add audio. The intent is to have a song start when the viewer connects to the website and will have controls to stop it if they wish. I added a layer that contains the audio which works OK but clicking the Home button causes the audio to play again resulting more than one audio track. I was able to fix that by starting the Home movie one frame later than the audio but I don't really think this is the right approach. Is the method I'm using for the audio correct (see screenshot) or is there a better way to do it? I need to control the audio independently with affecting the other layers. The music track will be in the Sound layer. I had to remove it because the song hasn't been released yet.The attached FLA is saved in CS3 but I am working in CS4.
View 2 RepliesDoes anyone know of a way to track the load time of an XML document? I have an xml document that has over 150,000 lines and it takes a little time to load. I am ok with the load time in general however I would like to create a preloader to tack its process.
I have tried putting the xml load/onLoad code in a movie clip and use getBytesTotal and getBytesLoaded to track the mc progress but it seems as though when that mc is loaded the application freezes until the xml is fully loaded.
How can I created an advertisement in flash where the server can track the number of clicks from the web user ?
View 5 RepliesI"m using Flex 4 and an AdvancedDataGrid. I need to keep track of the previously selected item. I can't think of where to capture this though. In an itemClickHandler method, the grid's selectedItem value is already the current selected item.
View 2 RepliesI know that manipulate sound with as2 is limited. I wondered is it possible to manipulate a sound/track is possible with AS3?
View 3 RepliesI'm trying to make a "next track" button. "T" is meant to be track number, and every time they click this button, I wanted "T" to increase by one until T>4 where I need it to go back to T=1 (I've only got 4 tracks). Then, I want, depending on what "T" equals, for it to start playing Track"T" and stop playing previous track. I also want the track playing to be looping continuously. At the moment, everything is muted, until I press the button; where it then plays all four tracks at once. I also have a problem with the mute button, but I've got a strong feeling both are of the same reason. I think my problem is that it does not know what "T" equals to begin with so it accepts all if statements; playing all tracks. But I'm new to Flash (my second project) so I'm not sure.
on (release){
stopAllSounds();
T =T+1
if (T>4){
T=1
} if (T = 1){
_root.snd1.start(0, 100);
[Code] .....
has anyone seen a handy component or code to monitor playback of your flv to see if flash is dropping frames.It would be nice to see total frames dropped, and maybe average frames dropped per second.In a perfect world it would be a graph over time.
View 3 RepliesI am trying track to see if mouse is between 0 and 200 pix in the Y coordinate, then do an if statement.
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);
// I use this to track readings.
function mousePosition(event:MouseEvent) {
[code].....
I'm trying to dynamically create buttons that will change accordingly to the matching array vars. So far, the only part that isn't working is the mouse down event. The trace just goes nuts and I'm kinda confuse here.[code]...
View 1 Replieswhat am I doing wrong here? The getchildByName value stays null, therefore it is not removing the movieclip.
var myMC:MovieClip;
mybtn.addEventListener(MouseEvent.CLICK,track);
function track(e:MouseEvent):void {
[code].....
I am using an array with a pIndex value of 0:
this.pArray = ["1.swf", "2.swf", "3.swf", "4.swf"];
this.pIndex = 0;is pressed, the array number increases by 1:
MovieClip.prototype.changeImage = function(d) {
[code].....