ActionScript 3.0 :: Detecting / Using Keyboard Events - GotoAndStop?
Apr 1, 2009
I'm confused about AS3's key handling. I just want a script that goes "If "R" is pressed, gotoAndStop(#). While in AS2 this was extremely easy, many examples I see now have variables in them. So all I know so far:
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN/UP/Whatever I want, nameFunction)
function nameFunction (evt:KeyboardEvent):void {
}
I've seen people with code like if (evt == 82) or something like that, but it doesn't work. C
View 9 Replies
Similar Posts:
Nov 7, 2009
I have 2 scenes. In both scenes, I have a movie clip that moves via keyboard control. If the goto next scene is triggered by the movie clip in the first scene the keyboard control works in the second. However, if I use a button to move to the next scene then there isn't any control over the movieclip in that scene. I've traced the keyCode in the second scene and it is picked up but the switch statement doesn't run. I'm migrating to Actionscript 3.0 and updating something I created in 2.0. I would like to do it without writing a class.
[Code]...
View 5 Replies
Aug 29, 2009
Well basically I've got this one frame in my animation. It's got three buttons and an input text box. One of the buttons goes with the text box, but I want the enter key to do the same thing (gotoAndStop) as the button. Unfortunately I've not a clue how.
View 2 Replies
Mar 2, 2009
I was working on some simple keyboard movement for an AS3 game, but running into trouble. Some keys would work, some won't!.I started a new flash just to test the keyboard, and confirmed what I was seeing. Some keys like "D" will work, while others like "A" don't seem to. Here is the code from the keyTest program.
Code:
package
{
import flash.display.*;[code]..
So when I press D or W, this flash outputs "68 down" or "87 up" or whatever as intended. But if I press keys like A or S, it outputs nothing. Wut?
View 2 Replies
May 6, 2010
An error appears :Incorrect Number of arguments Expected 1 Source :detectKey();
stop();
loaderInfo.addEventListener(ProgressEvent.PROGRESS ,updateloader);
stage.addEventListener(KeyboardEvent.KEY_DOWN, detectKey);
function detectKey(event:KeyboardEvent):void {
[Code].....
View 4 Replies
Nov 9, 2009
I am trying to detect the key down event for the alt key in flex. I have a standard event listener for KeyboardEvent.KEY_DOWN and KeyboardEvent.KEY_UP but don't get any response for the alt key (or ctrl key).
I know I can detect if the alt key was pressed via a mouse event, but I want to update the cursor when the alt key is pressed to show it will perform a different action from when it's not pressed.
I am using Safari on a Mac for developing so let me know if perhaps it's an isolated issue.
View 4 Replies
Jul 22, 2011
I am making the board game Shogi in actionscript 2 and I have a question on how to detect a particular imput.I have a movie clip on the stage, I want it so that if I hold down the keyboard button "p" and then click on the movie clip, it will go to the movie clip's frame 2 (not the entire flash project's frame 2, just the particular icon's frame 2. I need this because I am using movie clips as game pieces and in Shogi, certain game pieces can be promoted. I also was wondering how to detect what frame it is on.
View 3 Replies
May 29, 2009
I am working on a small section of my game and am attempting to detect key presses from an external class but I cannot get it to work. This code worked just fine when within the document class but now it's unresponsive. I'm not getting any errors, simply no activity whatsoever.Here's the applicable code:
My document class:
Code:
package
{
import flash.display.MovieClip;
public class Engine extends MovieClip
[code]....
View 4 Replies
May 29, 2011
I've just hit a really strange bug with a program I'm creating. The program allows the user to add shapes (currently all squares: SmallThing, MediumThing and LargeThing) to an area of the screen, then drag them about by clicking and draging using the mouse. Pretty simple. Unfortunately, the code seems to be failing for the smaller shapes (they're not THAT small, currently the smallest shape is 32 x 32) which are not generating mouse events at all. I have used trace statements to verify this. I am having a few issues with the larger shapes ocassionally not registering mouse up events, but I can live with this - the main issue is with the small shapes not being moveable.
All the shapes are descended from the same super class, and have the same event listeners added to them when they are created.
Here are the relevant functions in my Screen class. It's all pretty basic code so I really can't see what the problem is.
[Code]....
View 12 Replies
Jan 8, 2009
In AS2 I did this:
ActionScript Code:
ContactVerDoor.onRelease = function() {
if (Key.isDown(Key.SPACE)) if (Key.isDown(Key.SHIFT)) {
//Do something
}
}
I now need to code it in AS3.Can I still check if a key is down without listening for the keypress events? I understand how to code the Mouseclick in AS3.
View 2 Replies
Jan 23, 2010
I have an application that at runtime creates a class called map. The constructor for this loads a XML file that specifies a number of images to load and loads them as children. What I want to do is to somehow sense when all images specified in the XML file are loaded and dispatch an event.
What I do is to create a load event for each image to load, that places the image as a child in the map object. This map is then put as a child on the stage.
I need to add a event listener to map that listens when it is fully loaded and triggers a event.
map.addEventListener(...) gives me a compile error of course.
View 3 Replies
Mar 31, 2010
I have some nested movieClips. I've got an event listener on the parent listening for a mouse click. Problem is, the listener never picks up the click.[code]On movieClipStack, I can see that mouseEnabled = true. In addition, buttonMode = true works exactly like it's supposed to. But onStackClicked never happens - movieClipStack just isn't detecting any sort of mouse event.
View 2 Replies
Sep 30, 2009
I'm trying to write a simple counter. UP or Space increments a number and DOWN decrements. It's just one big number in the middle of the screen. A bell rings on an increment and I have added code to go full screen on mouse click.[code]...
View 1 Replies
Sep 2, 2009
I have a Card class. From this class, I have three possible children: Photo, Video and Info. In my main class, I want to create a few instances of these different classes without knowing what kind it is. But, no matter that, I want them all to listen to the mouse, so I may have something like this:
ActionScript Code:
var item:Card = new Photo();
item.addEventListener(MouseEvent.CLICK, mouseHandler);
The thing is: the Card class is kinda like a canvas... it has certain properties common to every type of item, but there's a space where it leaves it as a canvas... a Photo instance will load a photo there, a Video instance will load a video and a Info instance will load text to a TextField. The problem is that the event listener doesn't work the way I want it to... on an Info instance, the target of the click is the TextField; on a Photo instance is the picture... I want them all to be the class itself... in other words, I want to be able to parse the target as a child of the Card class. My code for the mouseHandler method is
ActionScript Code:
private function mouseHandler(e:MouseEvent):void
{
if(e.target is Photo)
[Code].....
That's the main idea... to be able to know what kind of object I'm clicking and access its properties... but on an Info instance, e.target is of type TextField... to be able to access the Info object, I have to do e.target.parent, and that is NOT the idea.
View 1 Replies
Oct 1, 2009
I'm trying to write a simple counter. UP or Space increments a number and DOWN decrements. It's just one big number in the middle of the screen. A bell rings on an increment and I have added code to go full screen on mouse click.
Test mode works fine ( except for full screen of course).
Seems to work fine on the local machine using Safari 3.2.3
However if I try to run it locally using firefox it does not work.I need it to run on a laptop but it does not always acknowledge the keyboard events and while in full screen it never responds to the keyboard events.Laptop is running Safari 3.2.1
import flash.display.StageDisplayState;
import flash.events.KeyboardEvent;
var chickCount = 0;[code]..........
View 2 Replies
Apr 7, 2011
I was looking at this game called "Tsunami Fighter" (if you google it, it'll be the first thing that pops up�I can't post links sadly) which is a keyboard mashing game. Basically you have to mash a certain keyboard button as fast as possible to stop the rage bar from reaching the top. I tried some things that I thought would work,
How would I script the keyboard mashing part of this game (The part where you have to keep a greater keyboardclicks/second than the rising bar You'll know what im talking about if you play the game. I'm not really concerned at the score or the graphics just the keyboard event thing.
View 3 Replies
Apr 1, 2010
I created an E-learning project for a customer that has pages that require the user to make keyboard entries. When the user enters a specific letter, the page progresses. The pages work as expected until the customer places the project in a 'wrapper' that controls the navigation. When this is done, the user can make the keyboard entries, but now the page will not progress to the next section. It seems that the wrapper is stopping the system from detecting that the specific letter is pressed.
View 7 Replies
Mar 12, 2012
why the swf does not catch any keyboard events? When i Ctrl+Enter my .fla there is a message appearing that says: "Your content will not stream. Runtime Shared Library (RSL) preloading will require all of your content to download before the first frame will play. To prevent this you can change the Runtime Shared Library Library Settings in the Advanced ActionScript 3.0 Settings dialog which can be raised from the Public Settings dialog. The Runtime Shared Libraries being preloaded are: textLayout_1.0..........."
View 17 Replies
Mar 12, 2010
I am adding a key listener to my AIR application like so:
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
keyDown="onKeyDown(event)">
Yet only sometimes when I press keys does it actually invoke. I have no clue why, I thought maybe something else has focus. Well I cannot add key listeners to NativeWindow or NativeApplication, and I would assume if it is on the WindowedApplication which is the root element, that as long as my application has focus the key presses should invoke the listener.
View 1 Replies
Jun 23, 2011
is it true that keyboard events can not be accessed outside of the stage on non display objects?
example:
package
{
//Imports
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
[Code].....
here i would like to initialize a new TestClass() then press a on the keyboard to receive the output Test Class: a.
View 1 Replies
Jul 16, 2009
I have a key.addlistener setup to listen to key events.What I want to be able to do is to dispatch key events by for example a mouse click or just on load. I've tried a lot of possible solutions such as dispatchEvent with type as "onKeyDown" and "keyDown" etc.... but key listener simply do not treat it as a keyboard event.
Code: Select allvar eventObj = new Object();
eventObj.type = "keyDown";
eventObj.code = 13;
eventObj.ascii = 'e';
dispatchEvent(eventObj);
View 1 Replies
Jun 6, 2009
seem to have trouble getting a keyboard event within a class to work, I have an ENTER_FRAME event which works fine, but the keyboard event never gets called.[code]
View 2 Replies
Aug 9, 2010
Is there way to navigate to various buttons on a stage using only the keyboard? I have several movies (complete with cover art) on my Flash stage. I want to convert them into buttons so that anytime a user navigates to that button and presses enter, it will take them to a new frame (where I will have information about that particular movie). I know how to do this with Mouse clicks. But, this application requires users to use arrow keys in order to navigate and not the mouse.
View 3 Replies
Aug 12, 2010
I finally found a way to exactly position my External SWF on the main stage. Here is the Actionscript I placed on an empty layer:
Code:
this.createEmptyMovieClip("externalSWF",1);
externalSWF._x=550;
[code].....
View 2 Replies
Jan 15, 2011
currently learning AS3 and having a bit of trouble with keyboard events. I feel like I understand how they work, but something about my implementation is faulty. This is basically the code I currently have, and I can't find an error in it based on tutorials and such that I've looked up:
Code:
package {
import flash.events.KeyboardEvent
[code]....
View 2 Replies
Oct 5, 2009
I have two mx:TileList controls that I'm using to allow editing of objects in batch. The first contains a collection of all available data, and the 2nd contains the current batch. Both are bound to ArrayCollections, and using the native drag-n-drop functionality of the TileList control the data is moved from one ArrayCollection to the other when an object is dragged between them.
I need to change the currentState to show & reset the batch manipulation controls when the batch count goes from 0 to n or n to 0 items. Based on the documentation, I would have thought that I should listen to the dragComplete event, but my testing shows that instead of firing after the data has been removed from the source ArrayCollection and added to the destination ArrayCollection, it fires (consistently) between these two actions.
[Code]...
View 2 Replies
Feb 2, 2010
I want my animation to STOP when I press SPACE, and then PLAY when I press SHIFT. This needs to be in AS3. The only catch is that my whole animation is composed of 5 Scenes. Would this be a problem? Also, I'm confused as to where I should add the code. I have it in a class and it still doesnt work. I tried putting it on the 1st frame on Scene 1.
View 1 Replies
Aug 7, 2010
Here is my code:
[Code]...
The code for KEY_UP and KEY_DOWN seems to work fine. But, the rest of it returns the error "1119: Access of possibly undefined property Key through a reference with static type Class." How do you call a function for Right, Left, Enter, and Escape Keys?
View 8 Replies
Aug 9, 2010
Is there way to navigate to various buttons on a stage using only the keyboard? I have several movies (complete with cover art) on my Flash stage. I want to convert them into buttons so that anytime a user navigates to that button and presses enter, it will take them to a new frame (where I will have information about that particular movie). I know how to do this with Mouse clicks. But, this application requires users to use arrow keys in order to navigate and not the mouse.
View 4 Replies
Mar 19, 2010
I am trying to create an on-screen keyboard for a touch-screen kiosk. Does anyone know how to send a keyboard event to a text input component from a button click event? For example, the user will push the on-screen buttons to enter their name, press tab to go to the next field, and so on.
I believe that I somehow need to use dispatchEvent but have not been able to get it to work. For example, pressing the on-screen A keyboard button will fire a CLICK event and call a handler to place an A in the currently focused text input component. The handler needs to be able to dispatch a keyboard event (with the correct keycode) to that text input field and that is where I am stuck.
View 6 Replies