Keyboard Event Not Registering
I created a simple AS# project in flex2.
Code:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class Snake extends Sprite
{
public function Snake()
{
this.addEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);
}
private function onKeyPress(event:KeyboardEvent):void{
trace("here");
}
}
}
but it does not trace out anything
thanks
cheers
firdosh
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 07-02-2006, 07:57 PM
View Complete Forum Thread with Replies
Sponsored Links:
Keyboard Events Not Registering
Hi all, this is my first post...
I'm using CS3, but previously used CS2. I'm using the following code:
function inputDecoder(e:KeyboardEvent):void
{
trace( e );
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, inputDecoder);
Some keys are detected upon the press, but most are not. For example, when the spacebar is depressed, the following is outputted: [KeyboardEvent type="keyDown" bubbles=true cancelable=false eventPhase=2 charCode=32 keyCode=32 keyLocation=0 ctrlKey=false altKey=false shiftKey=false]
But then when I press the "Q" key, for example, nothing is output.
Is there any reason for this to occur? I'm using a Dell 600m laptop, and have never had any problems with the keyboard before.
Thanks in advance for the help!
View Replies !
View Related
[AS3] Images Not Registering ROLL_OUT Event
Here is the Project
They work fine if you are slow, but if you just brush one of the hotspots the thumbnail will stick on the screen. I assume this is a fairly common problem. I've searched and read docs until my eyes bleed, so if anybody knows an obvious solution or can just point me in the general direction it would be mightily appreciated
Here's the code. It's a bloody mess. This is my first AS3 project. Works though.
PHP Code:
package { public class Walkaround extends Sprite { private var index:uint = 1; private var count:uint = 0; private var done:Boolean = false; private var _displayedThumb:Sprite = new Sprite( ); private var _loadXML:XMLLoader; private var _loader:Loader = new Loader( ); private var _nameList:XMLList; private var _planeURL:DisplayObject; private var _locationList:Array = new Array(); private var _markerXML:XML; private var _xCoord:int; private var _yCoord:int; private var markerHolder:Sprite = new Sprite(); private var _markerContent:DisplayObject; private var _thumbOn:Boolean = false; private const X_SHIFT:int = 100; private const Y_SHIFT:int = 75; private const PATH_TO_IMAGES:String = new String("images/plane/"); private const PATH_TO_THUMBS:String = new String("images/plane/thumbs/"); public function Walkaround() { // lets not scale stage.align = StageAlign.TOP_LEFT; stage.scaleMode = StageScaleMode.NO_SCALE; // change frame rate to 30 fps: stage.frameRate = 30; loadXML("walkaround.xml"); } private function loadXML(theXML:String):void { // load xml _loadXML = new XMLLoader(); _loadXML.addEventListener(Event.OPEN, onOpen); _loadXML.addEventListener(Event.COMPLETE, onComplete); _loadXML.load(new URLRequest(theXML)); } private function drawPlane(event:Event):void { var bitmapData:BitmapData = new BitmapData(_planeURL.width, _planeURL.height, true, 0xFFFFFF); bitmapData.draw(_planeURL); var thePlane:Bitmap = new Bitmap(bitmapData); thePlane.x = 163 - X_SHIFT; thePlane.y = 192 - Y_SHIFT; addChildAt(thePlane, 0); } private function onOpen(evt:Event):void { addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onComplete(evt:Event):void { done = true; } private function onEnterFrame(evt:Event):void { addChild(markerHolder); // list of images in XML elements var imageList:XMLList; // draw the plane var bmLoader:Loader = new Loader; bmLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, drawPlane); var bmRequest:URLRequest = new URLRequest(String("images/737_top.png")); bmLoader.load(bmRequest); _planeURL = bmLoader //grab the XML _markerXML = new XML(_loadXML.grabXML()); _nameList = _markerXML.marker; // create array of all markers for each (var p in _nameList) { //grab the fields from xml var type:String = _markerXML.marker[count].@type; var name:String = _markerXML.marker[count].@name; _xCoord = _markerXML.marker[count].@x - X_SHIFT; _yCoord = _markerXML.marker[count].@y - Y_SHIFT; var rotation:int = _markerXML.marker[count].@rotation; imageList = _loadXML.getImages(count); //add current marker to array of the markers _locationList["button" + count] = [type, name, _xCoord, _yCoord, rotation]; for each (var i in imageList) { _locationList["button" + count].push(i); } // see what kind of marker it is and color it appropriatly var markerColor:uint = new uint(0x00FF00); if (_locationList["button" + count][0] == "outside") { markerColor = 0xFF0000; //red } else if (_locationList["button" + count][0] == "under") { markerColor = 0x00FF00; //green } else { markerColor = 0x0000FF; //blue } // Create the marker. var marker:Sprite = new Sprite(); marker.name = "button"+count; // Disable the mouse events of objects inside the marker. marker.mouseChildren = false; // Make the sprite behave as a marker. marker.buttonMode = true; // Create a up state for the marker. var up:Sprite = new Sprite(); up.graphics.lineStyle(1, 0x000000); up.graphics.beginFill(markerColor); up.graphics.drawRect(0, 0, 15, 15); up.name = "up"; // Create a over state for the marker. var over:Sprite = new Sprite(); over.graphics.lineStyle(1, 0x000000); over.graphics.beginFill(0xFFCC00); over.graphics.drawRect(0, 0, 15, 15); over.name = "over"; // Adder the states and label to the marker. marker.addChild(up); marker.addChild(over); // Add mouse events to the marker. marker.addEventListener(MouseEvent.MOUSE_OVER, markerOver); marker.addEventListener(MouseEvent.MOUSE_OUT, markerOut); marker.addEventListener(MouseEvent.CLICK, markerClick); // Add the button to the holder. markerHolder.addChild(marker); // Position the marker. marker.rotation = 0; marker.x = _xCoord; marker.y = _yCoord; // Hide the over state of the marker. over.alpha = 0; // Increase the count. trace("button" + count + ": " + _locationList["button" + count]); count++; } // wrap it up if(done) { trace(_locationList["button43"]); removeEventListener(Event.ENTER_FRAME, onEnterFrame); } } private function markerOver(evt:MouseEvent):void { // Hide the over state of the marker. evt.currentTarget.getChildByName("over").alpha = 100; var currentMarker:String = new String(evt.currentTarget.name); _xCoord = _locationList[currentMarker][2] - X_SHIFT; _yCoord = _locationList[currentMarker][3] - Y_SHIFT; var currentThumb:String = new String(PATH_TO_THUMBS + _locationList[currentMarker][5]); loadThumb(currentThumb); evt.stopPropagation(); trace(evt.currentTarget.name); trace("over: " + evt.type); } private function markerOut(evt:MouseEvent):void { // clear thumb and return marker to proper color. clearThumbs(); evt.currentTarget.getChildByName("over").alpha = 0; //trace(evt.currentTarget.name); trace("out: " + evt.type); } private function markerClick(evt:MouseEvent):void { evt.updateAfterEvent(); //trace(evt.currentTarget.name); trace("click: " + evt.type); } private function drawThumb(evt:Event):void { if (!_thumbOn){ trace(_loader.hasEventListener(Event.COMPLETE)); // add a container to the stage for the thumbnail addChild(_displayedThumb); var loadedImage:Bitmap = Bitmap(_loader.content); var bitmap:BitmapData = new BitmapData(loadedImage.width, loadedImage.height, false, 0xffffffff); bitmap.draw(loadedImage, new Matrix( )) //put the bitmap in a var and display var image:Bitmap = new Bitmap(bitmap); image.x = _xCoord + 50; image.y = _yCoord - 25; _displayedThumb.addChild(image); _thumbOn = true; trace("compl: " + evt.type); this.dispatchEvent(evt); } else { clearThumbs(); drawThumb(evt); } } private function loadThumb(image:String):void { _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, drawThumb, false, 10); _loader.load(new URLRequest(image)); } private function clearThumbs():void { if (_thumbOn) { removeChild(_displayedThumb); _displayedThumb = new Sprite ( ); _displayedThumb.mouseChildren = false; _thumbOn = false; } } }}
View Replies !
View Related
Registering Different Event Classes To Instances?
OK, I'm going to explain what I wanna do cause I dont know that registerClass is the best way to do it.
I have four mcs that act as rollovers underneath invisible buttons, that do hittest and then go to next frame if true onEnterFrame. What I wanna do is create a class with this rollover property, and a seperate class with actions to stop at the end of the clip, so that when i click about, the about button stays highlighter while the others still do rollovers. Does that make any sense? Help is appreciated, thanks guys i love you.
View Replies !
View Related
ADDED_TO_STAGE Event Not Registering In Flash Timeline?
I'm using flash cs3. I'm trying to to add the eventlistener on a movie clip timeline (frane 1) that is in the library. If the code is in the timeline then the event is never registered when flash adds it to the stage. If however I put the code into an external class (doing the linkage stuff) it works fine. Can anyone help explain why this happens?
basic code is this
this.addEventListener(Event.ADDED_TO_STAGE , added);
function added(event:Event):void {
trace(this.x);
}
View Replies !
View Related
About Keyboard Event
hi,
i've been searching thoughout the board for awhile already
and tried to test the code out,
but still i don't have any luck yet to get my code running properly.
this is what i trying to do.
i want to have a textBox that the number inside will change(increase) whenever i press on 'q' and change(decrease) whenever i press on '-'
this is what i am curretly trying
on(release, keyPress"q")
{
mytext.text = ++;
// i think i need to parse the text out first as an int
// and then try putting it back
}
about 'mytext' i made it as a 'texttool' with 'dynamic property'
any help would be really appreciate.
Tom
View Replies !
View Related
Keyboard Event
hello,
I would like to know if there's a code to simulate the same thing when you type on the beyboard.
I would like to have by code the same thing as SendKeys({ESC}) in VB.
Thanks,
Jerome.
View Replies !
View Related
Keyboard Event
Hi all,
I am having this strange problem with keyboard event where it doesn't respond when I pressed on certain keys like c and some others. I am only having trouble with lowercase letters, when I hold shift then all the keys work.
And it's not my keyboard since I can type the letters fine, I event swapped out keyboards just to test ><.
Mahalo,
Wen
View Replies !
View Related
Keyboard Event Problem
Quote:
function mkey (event:KeyboardEvent)
{
}
function mkey (event:MouseEvent)
{
}
this.addEventListener(KeyboardEvent.KEY_DOWN, mkey);
mbutton.addEventListener(MouseEvent.CLICK, mbut);
I created a simple keyboard event that makes an object move. The problem I'm having is that when I try this out in the player the flash doesn't recieve any Keyboard events until I click an object that I made use a mouse event.
basically I have to click on the mbutton object for the keyboard events to be recognised.
Should I set a focus or what?
View Replies !
View Related
Trouble With Keyboard Event
Hello,
I'm trying to create a class (that controls a MovieClip), that is capable of listening for keyboard events on its own and then moving its x + y position.
I've highlighted the part of the code that must be causing the problem. I have placed a trace statement on one of the keys and it isn't working, so I'm guessing that its something to do with the event listener/ handler.
Code:
package fork
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import mcFork;
public class ForkClass extends MovieClip
{
var ySpeed:Number = 200;
var xSpeed:Number = 20;
public function ForkClass()
{
this.x = 225;
this.y = -150;
this.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
}
private function KeyPressed(evt:KeyboardEvent) {
switch (evt.keyCode) {
case Keyboard.UP :
this.y -= ySpeed;
trace("working");
break;
case Keyboard.DOWN :
this.y += ySpeed;
break;
case Keyboard.LEFT :
this.x -= xSpeed;
break;
case Keyboard.RIGHT :
this.x += xSpeed;
break;
}
}
}
}
View Replies !
View Related
Keyboard-event Only On Textinput?
Im trying to add a global key-listener that will listen on any key pressed...no matter what object that is active.
on frame1:
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
function onKey(event:KeyboardEvent):void {
trace(event.keyCode);
if(event.keyCode == 90 && event.ctrlKey){
GUI.doSoemthing(null);
}
if(event.keyCode == 37){
GUI.doThis(null);
}
if(event.keyCode == 39){
GUI.doThat(null);
}
}
For some reason this only works when a inputfield has focus.
If I with the mouse selects a row in a DataGrid, the listener doesnt work anymore.
All graphics on stage is in a class called "GUI.as" and is added to the displaylist from same frame the eventlistener is on.
Any solution?
View Replies !
View Related
Keyboard Event ENTER
I've looked at several posts on this and it SEEMS as if my code should be working , but I'm getting "ArgumentError: Error #1063: Argument count mismatch on MethodInfo-7(). Expected 1, got 0." I just want to give an press enter option to clicking on the button (go_mc) . What am I doing wrong??? Thanks!
Here's the relevant code:
Code:
package{
import flash.display.Stage;
import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.events.*;
import flash.text.*;
public class Main extends MovieClip{
public function Main(){
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterHandler);
go_mc.addEventListener(MouseEvent.CLICK, onClick);
go_mc.addEventListener(MouseEvent.MOUSE_OVER, onOver);
go_mc.addEventListener(MouseEvent.MOUSE_OUT, onOut);
function enterHandler(event :KeyboardEvent):void
{
if (event.keyCode == Keyboard.ENTER)
{
onClick();
}
}
function onClick(event:MouseEvent):void{
//blah blah blah
}
View Replies !
View Related
Delay With Keyboard Event
So I'm trying to convert this tile engine I wrote in AS 2.0 to AS 3.0... The problem is that when you hold down an arrow key to move, there is a delay. If I hold down right arrow, it moves one pixel to the right, pauses, then proceeds to move to the right at a continuous rate. The pause has to go! This did not happen in AS 2.0. If you pressed an arrow key and had code to move the x value of something, there was no pause. Here is some simple demonstration code:
ActionScript Code:
var land:Sprite = new Sprite();
land.name = "land";
addChild(land);
var landtile1:Shape = new Shape();
landtile1.name = "landtile1";
land.addChild(landtile1);
var mc=Shape(land.getChildByName("landtile1"));
mc.graphics.lineStyle(1, 0xFF0000, 1, false, "normal", "square", "miter", 3);
mc.graphics.drawRect(20,40,50,10);
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveStuff);
function moveStuff(event:KeyboardEvent):void
{
if(event.keyCode==39)
{
land.x++;
}
}
just copy/paste that into a 3.0 FLA and hold the right arrow key to see the effect.
Is there any way to fix this?
View Replies !
View Related
Not Reacting To Keyboard Event..
Ive had some succes now, learning AS3.
But i cant figure out why this code is not letting my keydown function execute.
I do this in the FLASH ide, I use a document class as my main class. Which then creates a instance of a Player class, where it has a keyboard eventlistener, but when i press a key nothing happens.
Code:
package classes
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
public class Player extends MovieClip
{
public function Player()
{
trace("Hero!");
addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
//this.setFocus();
}
private function checkKeysDown(event:KeyboardEvent):void
{
this.x++;
trace("kgkl");
trace("You pressed key: "+event.keyCode);
}
}
}
I have disabled the keyboard shortcuts in the flash player, but it is not reacting at all :.
I'd really appreciate it if someone can tell me what is going on here.
View Replies !
View Related
Keyboard Event Listeners
I'm definitely suffering with the lack of Keyis.Down! Anywhoo here is my code...
ActionScript Code:
public function Crung() {
this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
}
public function onKeyPressed(evt:KeyboardEvent):void {
switch (evt.keyCode) {
case Keyboard.RIGHT:
this.x += 1;
break;
}
}
}
This does nothing, and I'm thinking its because this isn't the document class and the event listener needs to be on the stage. 'public function Crung() {' is the constructor for the class Crung. An instance of Crung is created in Level1.as. And an instance of Level1 is created in Main.as which is the document class. So...
Main.as
...Level1.as
......Crung.as
Crung is basically a MovieClip which the user moves around the stage using the keyboard keys.
Any help in going about this? Not necessarily moving him around, just getting the listener to do anything in Crung.as
View Replies !
View Related
Keyboard Event Problem
It seems like the Keyboard.KEY_DOWN and Keyboard.KEY_UP events are fired continuously if youre keeping a key down. How can you make that the event KEY_DOWN is only fired the first time the key is pressed, and KEY_UP only one time when it's released?
ActionScript Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyDown);
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyUp);
function KeyDown(e)
{
trace("down"+e.keyCode);
}
function KeyUp(e)
{
trace("up"+e.keyCode);
}
If I keep shift pressed for a while, and then release it, this is the result:
Code:
down16
up16
down16
up16
down16
up16
down16
up16
down16
up16
down16
up16
down16
up16
[...]
... you get the idea...
View Replies !
View Related
Keyboard Event Problems
I keep getting an error from the Keyboard.NUMBER_2. If I use NUMPAD_2 it works fine, but I don't want to use the numpad if I don't have to.
Also, the keyboard events do the same thing in every frame - how can I get them to do different things for different frames?
stage.addEventListener(KeyboardEvent.KEY_DOWN,repo rtKeyDown);
function reportKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.F4)
{
gotoAndStop(4);
}
if (event.keyCode == Keyboard.F5)
{
gotoAndStop(6);
}
if (event.keyCode == Keyboard.NUMBER_2)
{
gotoAndStop (7);
}
};
stop();
View Replies !
View Related
Generating Keyboard Event?
I need to make my application more accessible to keyboard only users.
This requires me to add an eventlistener for keyboard activity and filter the TAB key. I wish to issue a keyboard event for the ENTER key when the TAB key is pressed by the user. How can I generate the ENTER key please?
View Replies !
View Related
Dynamic Keyboard-event
hello!
i want to make some dynamic buttons which are able to use by pressing a letter and klick them. the problem is, that i try do test it by using trace() and so on but there is no feedback by the flesh when i pressed something. does anybody know what's wrong?
the event looks like that:
private function mausMarkiert(n)
{
n.currentTarget.alpha = 1;
// AENDERN --- hier noch die möglichkeit des tastendrückens und exemplare verschiebens einbauen
container_kalkulator_variante.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
}
private function mausUnmarkiert(n)
{
n.currentTarget.alpha = .8;
}
the alpha-manipulation works. do i have to write something more? container_kalkulator_variante is a sprite.
thanks for reading, understanding and re-writing!
View Replies !
View Related
Keyboard Event Problems
I keep getting an error from the Keyboard.NUMBER_2. If I use NUMPAD_2 it works fine, but I don't want to use the numpad if I don't have to.
Also, the keyboard events do the same thing in every frame - how can I get them to do different things for different frames?
Attach Code
stage.addEventListener(KeyboardEvent.KEY_DOWN,reportKeyDown);
function reportKeyDown(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.F4)
{
gotoAndStop(4);
}
if (event.keyCode == Keyboard.F5)
{
gotoAndStop(6);
}
if (event.keyCode == Keyboard.NUMBER_2)
{
gotoAndStop (7);
}
};
stop();
View Replies !
View Related
Keyboard Event Woes
Ok here's what I got going on. I have an object that inherits from Sprite, and it's just a simple png. In the main class I go ahead and add it, and then I call these 2 methods:
Code:
addEventListener(Event.ADDED,addedListener);
addEventListener(FocusEvent.FOCUS_IN,focusInListener);
/**
*
*/
private function focusInListener(e:FocusEvent):void {
if (e.target == player) {
player.focusRect = 0; //I don't want to see that lame *** focus rectangle
}
}
/**
*
*/
private function addedListener(e:Event):void {
if (e.target == player) {
stage.focus = player;
}
}
now when i load up my swf , the player object is still inside a focusRect, I also tried setting it to false. However as soon as use the keyboard to move the player object it moves out of the focusRect (which just stays in it's orginal location) So what's the deal with that thing, and how can I rid myself of it?
View Replies !
View Related
Keyboard Event Listener Problem
i have built a space game. i am using numbers for the menu screen. when the user presses 1 i want 10 instances of a movieclip called blackhole to be added to the stage and when the user presses 2 i want 5 instances of the same movieclip to be added to the stage. This works as an easy and normal setting. However when the user presses 1 or 2 i get this error -
Error: Error #1023: Stack overflow occurred.
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position()
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position()
at spaceGameMobileMenuWorkingPublished_fla::MainTimel ine/position() etc.....
Here is my code -
Code:
stage.addEventListener(KeyboardEvent.KEY_DOWN, chooseStart);//adds an eventlistener to the stage to listen for a keyDown event
function chooseStart(evt:KeyboardEvent):void
{
if(evt.keyCode == 49)//listens for the 1 key
{
openingSoundSC.stop();//plays the openingSound
moon.visible = true;//shows the moon movieclip on the stage
for(i = 0; i < 10; i++)//executes the for loop for 10 times
{
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);//stops blackholes overlapping
blackHoles.push(moon);//stops blackholes and moon overlapping
blackHoles.push(gameTimer_tb);//stops blackholes and gameTimer overlapping
blackHoles.push(lives_tb);//stops blackholes and lives_tb overlapping
blackHoles.push(spaceship_mc);//stops blackholes and spaceship_mc overlapping
addChild(blackHole);//add the blackhole to the stage
}
gravity = 1;//sets the gravity to 1
timer.start();//starts the timer
addChild(spaceship);//adds the spaceship to the stage
spaceship.x = 30;
spaceship.y = 20;//positions spaceship
removeChild(startButton);//removes startButton from stage
removeChild(easy);//removes easy button from stage
removeChild(hard);//removes hard button from stage
removeChild(exit);//removes exit button from stage
removeChild(splashScreen);//removes splashScreen from stage
removeChild(instructionsText);//removes//instructions text from stage
stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseStart);//removes the start event listener
stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseHard);//removes the hard event listener
stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseExit);//removes the exit event listener
}
else if(evt.keyCode == 50)//listens for the 2 key
{
moon.visible = true;
for(i = 0; i < 5; i++)//executes the for loop for 5 times
{
blackHole.x = Math.random() * stage.stageWidth;
blackHole.y = Math.random() * stage.stageHeight;
position(blackHole);
blackHoles.push(blackHole);
blackHoles.push(moon);
blackHoles.push(gameTimer_tb);
blackHoles.push(lives_tb);
blackHoles.push(spaceship_mc);
addChild(blackHole);
}
gravity = 1;
timer.start();
addChild(spaceship);
spaceship.x = 30;
spaceship.y = 20;
removeChild(instructionsText);
removeChild(startButton);
removeChild(easy);
removeChild(hard);
removeChild(exit);
removeChild(splashScreen);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, chooseStart);
}
}
Can anyone help?
View Replies !
View Related
Keyboard Event Listener Problem
Hi there, I'm new to actionscript, and need some help. I want to play a movieclip when a user presses a key, and then play a different movieclip when they release the same key. I have the following small code which traces key codes, pressed and released. Could this be converted to do what I want?
stage.addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,checkKeysUp);
function checkKeysDown(event:KeyboardEvent):void{
trace("You pressed key: "+event.keyCode);
}
function checkKeysUp(event:KeyboardEvent):void{
trace("You released key: "+event.keyCode);
}
any help on this would be appreciated.
Morgan.
Edited: 05/26/2008 at 02:38:27 PM by noNick77
View Replies !
View Related
KeyBoard Event And Full Screen
Hi to everyone,
Look at this little sample of code. As you see, it lets the user go to full screen mode when he clicks on the blue restangle. A eventListener has been set to lesson to keyBoard events ...and the events detected are printed in a white textField
Here is what I noticed :
In FireFox
When I click to go to full screen mode, a keyboard event is detected ! ... a space bar keydown event !... I swear, i did not press this cursed space bar ! ... strange ...
In IE
No keydown event at all are detected .... and this time I pressed keys on my keyboard as if my life depended on it .... no effect ....
Thanks a lot to anyone who could give me a hint to get out of this problem. In fact, I really nead to make keyboard work in full screen mode (wich is, I guess, a pretty usual thing down here ...)
; )
Attach Code
# stage.quality = StageQuality.HIGH;
# stage.scaleMode = StageScaleMode.NO_SCALE
# stage.align = StageAlign.TOP_LEFT;
#
# var textField:TextField = new TextField();
# textField.x = 220;
# textField.y = 0;
# textField.width = 1000;
# textField.height = 500;
# textField.background = true;
# textField.backgroundColor = 0xffffff;
# addChild(textField);
#
# // pour le fullScreen
# var carre:Sprite = new Sprite();
# carre.graphics.beginFill(0x000099);
# carre.graphics.drawRect(0,0,200,200);
# addChild(carre);
# carre.addEventListener(MouseEvent.CLICK, fullScreenOnClick);
#
# function fullScreenOnClick(e:Event):void
# {
# stage.displayState = StageDisplayState.FULL_SCREEN;
# }
#
# // pour le clavier
# stage.focus = stage ;
# stage.addEventListener(KeyboardEvent.KEY_DOWN , reportKeyDown);
#
# function reportKeyDown(event:KeyboardEvent):void
# {
# textField.text = event.toString();
# }
here is the html code of the page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>.</title>
<style>
body {
margin:20;
padding:20;
background-color:#333333;
}
#tableau
{
height:100%;
width:100%;
border:0;
}
#anim
{
text-align:center;
vertical-align:middle;
}
</style>
</head>
<body>
<table id="tableau">
<tr>
<th scope="col" id="anim"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0" width="1000" height="750" id="full" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="testbug.swf" />
<param name="allowFullScreen" value="true" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<embed src="testbug.swf" quality="high" bgcolor="#000000" allowFullScreen="true" width="1000" height="750" name="full" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object></th>
</tr>
</table>
</body>
</html>
View Replies !
View Related
[AS3] Keyboard Event Wont Work :(
I decided to pick up a copy of O'reilly Actionscript 3 Cookbook today, and I have been going through. One of the first examples it has for keyboard events is:
Code:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class ExampleApplication extends Sprite {
public function ExampleApplication( ) {
stage.focus = this;
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onKeyDown(event:KeyboardEvent):void {
trace("key down: " + event.charCode);
}
}
}
But for some reason it will not work. According to the book stage.focus = this; is all you need for keyboard events to work, am i doing something wrong?
View Replies !
View Related
Onscreen Keyboard - How To Send Event?
Hello all. Relative newbie with AS3 but I need to make an onscreen keyboard for a touchscreen. Through some searching and coding I have a keyboard object that can send events based on clicks but I'm not sure how to go that "last mile" to trigger an actual keyboard event so the selected TextField gets updated.
Anyone do anything similar. Any advice.
Thank you SO much in advance.
Greypoint
View Replies !
View Related
Parent Movie Intercepts Keyboard Event
Hi,
posted this in the Flash MX forum a couple of days ago but it drew a blank!
Iim working in Flash MX, and I have an swf that I want to respond to keyboard events. Specifically, the swf contains a form with fields that I want the user to be able to hop between by pressing the TAB key. Unfortunately, this swf is loaded into a parent movie, which means that movie clips in the parent movie intercept the keyboard event rather than my fields in the child swf. The movie clips only have event handlers for mouse events attatched, but responding to the TAB key seems to be built in functionality.
Does anyone know how I can stop this from happening? There must be some way to switch the focus to the child movie or something?
Cheers!
View Replies !
View Related
Problem With Removing Keyboard Event From Stage
I'm trying to write a function that, when the mouse rolls over a MovieClip object, if the user presses the up/down button, then the movie clip will climb/descend in the containers child list. In other words, if the mouse is on the object, and I press up, the target object should come forward in depth.
So far this is what I have:
Code:
myMovie.addEventListener(MouseEvent.ROLL_OVER, changeDepth);
myMovie.addEventListener(MouseEvent.ROLL_OUT, changeDepth);
function changeDepth(e:MouseEvent) {var target = e.target;
trace(e.type);
var targDepth = container.getChildIndex(target);
var maxDepth = container.numChildren;
if (e.type == "rollOver") {stage.addEventListener(KeyboardEvent.KEY_UP, depthSwap);
} else if(e.type == "rollOut"){stage.removeEventListener(KeyboardEvent.KEY_UP, depthSwap);
}
function depthSwap(e:KeyboardEvent) {if (e.keyCode == 38) {if (targDepth+1<maxDepth) {container.setChildIndex(target,targDepth+1);
} else if (e.keyCode == 40) { if (targDepth>1) {container.setChildIndex(target,targDepth-1);
}
}
}
}
}
My issue is that the KeyboardEvent still fires off when I roll out of my target MovieClip.. (May of had some braces get unbalanced while copy pasting)
View Replies !
View Related
Any HTML Event That Could Lend Itself To An Onscreen Keyboard In AIR?
Still tinkering with AIR & have a rough proof of concept of a custom web-browser (using HTML objects to display internet-based HTML websites). This works fine but we're now looking into bringing a touch-screen keyboard to the mix for use on TabletPC and trying to determine if we can do so in-AIR or if we're forced to use a native OS application (e.g. WinXP Tablet Edition's onscreen accessibility keyboard EXE).
To do it in-AIR, I see the need to detect when any field within the HTML pane (including possibly HTML form input fields or embedded SWF-based forms) gets Focus. But I don't think this is possible given the limited reach of the HTML Events accessible by handlers in AIR, right? Seems doable if AIR contains no HTML objects (only native flash textfields etc) but not if it has any nested HTML objects, right?
Just wanted to confirm whether I'm stuck with an alternate 3rd party App (which AIR couldn't launch if it wanted to, due to security limitations, right?)
Thanks!
View Replies !
View Related
Animated Running Legs Stop After 1 Cycle With Keyboard Event
this code only does 1 cycle of the animation(btw, the KeyMover class moves the movieclip forwards and backwards, there is no issue with that):
Code:
import controls.KeyMover;
var keyMover:KeyMover = new KeyMover(character);
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, pressed);
this.stage.addEventListener(KeyboardEvent.KEY_UP, released);
function pressed(event:KeyboardEvent)
{
character.gotoAndPlay(2);
}
function released(event:KeyboardEvent)
{
character.gotoAndPlay(1);
}
i have the lower half of an animated character made. the first frame of the movieclip is set to stop at normal standing position, the second frame on is animated for one cycle of running and when it hits the last frame it automatically goes back to frame 2 for another cycle and so on. it actually goes a bit further than 1 cycle, which confuses me. i figure that the key to make the animation run is constantly setting off the function so it sorta overrides the code in the animation that makes it cycle over and over, but the fact that it doesn't stop at the end of the first cycle makes that an unconvincing theory. any help would be appreciated.
View Replies !
View Related
Capturing Keyboard Event - Disable Shortcuts Flash Player?
I'm trying to capture keyboard events with the following code. I'm testing in an external popup flash player in FlashDevelop and it ain't tracing anything. I reckon it might be something to do with keyboard shortcuts in the flash player.
But I can't find where to disable them?
ActionScript Code:
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class myTest extends Sprite {
public function myTest ( ) {
stage.focus = this;
addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onKeyDown(event:KeyboardEvent):void {
trace("key down: " + event.charCode);
}
}
}
View Replies !
View Related
Event.keyCode == Keyboard.ESCAPE Not Captured From Laptop During FULLSCREEN
I've encountered similar problems capturing keyboard events from laptops before, which is why I'm using keyboard.ESCAPE instead of keycode 21. The same keyboard event handler fires on some of the laptop keystrokes, but not all - so the handler is working. I'm wondering if the issue is not just the quirky key assignments in some laptops, but might have something to do with the FULLSCREEN state disengaging the keyboard. Maybe I should be listening for something else that is happening when the escape key is pressed while in FULLSCREEN state?
I can post my code if needed, but I think this is has more to do with knowing what event to listen for that is only hinted at in the documentation I've been looking at re FULL_SCREEN.
View Replies !
View Related
Help Asked For Updating Textfield Whitout Keyboard And The 'change' Event. (touchsrn)
Sorry for the 'second' post, but I figured the previous title was quite vague and 'incorrect'.
I'm stuck and out of ideas, so I'm looking for some help.
I'm currently creating a touchscreen application and I already have programmed a nice "mobilephone" input object, to insert numbers and strings.
Now I get to the tricky part: It works very well with one textfield. A timer assures me the textfield is updated regularly. But now I want it to work with multiple textfields.
I'm still new to AS3.0, so the coding isn't that neat. I tried some things with focus and timer events, but I only was able to add a string to a textfield after I "pushed" it to activate it. But I want the textField updated after every insert of a number or string.
I can't use the 'change' event, because I'm not using a keyboard, but a onscreen 'interface' (sms style).
The code I made :
ActionScript Code:
tText.addEventListener(TimerEvent.TIMER_COMPLETE, refresh_text);
function refresh_text(event:TimerEvent){
strText = NumPad.txtinput.join("");
tText.reset(); tText.start();
}
txtSurname.addEventListener(FocusEvent.FOCUS_IN, TextFocus);
txtLastname.addEventListener(FocusEvent.FOCUS_IN, TextFocus);
txtAge.addEventListener(FocusEvent.FOCUS_IN, TextFocus);
function TextFocus (e:FocusEvent):void {
(e.target).text = strText;
NumPad.txtinput = [];
}
I only have three textfields now, but I want to use a dynamic number of textfields. I know: I could fix it with a component Array, but I still don't get how to interact with the components in a array.
But the main problem: How can I update a field after activating it and keep updating this field until I select a different text field?
Ultimate goal: store all data from the textfields in a sharedComponent
Could someone help me in to the right direction?
View Replies !
View Related
Keyboard Domination - Best Tricks To Hear All Possible Keyboard Shortcuts
I'm looking to recreate a keyboard shortcut quiz in flash much like this example that's been done in javascript.... (Note: the example seems to only really work well on Windows - I'm hoping mine proves to be more compatible?). a timer counts down while it waits for you to correctly perrform the shortcut on the keyboard.
I've successfully implemented a key combination listener such as is detailed in a tutorial here. I've gotten it to parse my list of shortcuts from a delimited txt file, correctly analyze user combination held & advance/score if correct, drive score based on countdown time remaining, manage "pass" to skip tough ones, etc.
You can see my progress here.
http://www.realitytheory.com/clients...indexTest.html
However I've still got several things that don't work even though I'm using fscommand("trapallkeys", "true"); (does that even matter when used within browser plugin?)
1) Ctrl key doesn't register on Macs (tried Safari & Ffox) but Cmd key does. This is odd since it works fine when previewing in Flash via Ctrl-Enter (and having enable keyboard shortcuts disabled in that player). Not a showstopper as client's cool if it's windows only.
2) Any shortcuts that utilize the Alt key - seems flash doesn't detect a key event when I hit that key. I've seen another thread here intimating that Flash can't hear code #18 (alt) even though javascript can it certainly seems true in flash player. Is this true? Can it be somehow "pressed" by javascript via a JS key handler?
3) Any that conflict with browser default actions e.g. Ctrl-P, Ctrl-S. Before saying there's no way, note that somehow the JS on the example link *do* block those (on IE/Ffox Win anyways). Does anyone have a clue what part? Will disabling the browser's default actions mean Flash receives the input or will flash not hear them either?
Any help will I'm sure benefit anyone looking to listen for key combos.
View Replies !
View Related
[F8] OnRollOut Not Registering
The best way I know how to explain my problem is to show it. Go to www.wandohigh.com/index_test.html and you will see a big main flash movie smack in the middle of the page. There are dropdown menus, blah blah.
Direct your attention to the far left drop down menu. It's the one that says "Families." Well once it's dropped down, roll your mouse out of it to the left, so that your mouse leaves the flash object. Apparently the mouse leaves the flash object too fast and flash never registers that there was a rollout, therefore never dispatching an onRollOut event, which is required to have the dropdown menu disapear! Ahh!
Does anybody know how I can fix this?
Thanks!
feigner
View Replies !
View Related
[F8] Variable Not Registering
I am using as2. Having a problem with a variable tracing numbers but not being able to use those numbers for anything else. eg. _xscale.
aListener.onReceiveData = function(evtObj:Object){
//store the received data in a string
var str:Number = evtObj.data;
trace(str);
//this works fine. Numbers are traced from 0-200.
circle_mc._xscale = str;
//this does not work! str is just ignored and the scale remains at 100??
Can someone pls help me.
THanks!!
View Replies !
View Related
Key.ENTER Not Registering
For some reason, I can see the Key.getCode() for all my key presses except for the enter key. Am I doing something wrong here? I poured over other threads, and the answers seem to look like my code.
Files below
Thanks
View Replies !
View Related
Button Registering
I have a button and an MC.
The problem is that the button still registers when the MC rolls over it.
I need the button not to register while the MC is convering it.
I cant find out how and if it can be changed.
Please help.
View Replies !
View Related
MouseUp Not Registering
I have a doc class (seed.as) which I am having call a Pencil class (PencilTest.as). I can't seem to get the PencilTest.as to register MouseUp. In the onLoop function in PencilTest, it registers as true not matter what I do. I think it's because (???) I can't use the stage.addEventListener on a separate class?? Ideas?
Code:
//PencilTest.as
import flash.geom.*;
import flash.display.*;
import flash.events.*;
public class PencilTest extends MovieClip{
public var down:Boolean=true;
//public var seedHolder:MovieClip= new MovieClip();
public function PencilTest(){
trace("hello from pencil");//ok
this.graphics.lineStyle(1, 0x000000);//ok
this.graphics.moveTo(mouseX, mouseY);//ok
this.addEventListener(Event.ENTER_FRAME, onLoop, false,0,true);//"this" working
this.addEventListener(MouseEvent.MOUSE_DOWN, onDown, false,0,true);
this.addEventListener(MouseEvent.MOUSE_UP, onUp, false,0,true);
}//ends main function
function onDown(e:MouseEvent):void{
//working
down= true;
trace("true");
}
function onUp(e:MouseEvent):void{
//on up is working
down= false;
trace("false");
}
function onLoop(evt:Event):void{
//if down event registering no matter what the state
if(down){
trace ("it's true!");
this.graphics.lineTo(mouseX, mouseY);
}else{
trace ("its false!");
//this is not regisering
this.graphics.moveTo(mouseX,mouseY);
}
}
Code:
//Seed.as
package{
import flash.display.*;
import flash.events.*;
import classes.com.brewerthompson.drawing.*;
public class Seed extends MovieClip{
public var mySeed: PencilTest= new PencilTest();
public function Seed():void{
stage.addEventListener(MouseEvent.MOUSE_MOVE, startSeed);
//mouse move worked
trace ("seed says hello world");
}
function startSeed(e:MouseEvent):void{
addChild(mySeed);
trace (mySeed + " before remove");
trace("removed listener!");
stage.removeEventListener(MouseEvent.MOUSE_MOVE, startSeed);
}
}//end class
}//end package
View Replies !
View Related
Backspace Key Not Registering.
howdy
i was trying with textfield masking and came around a problem and that problem is that the backspace key is not getting registered. not fully, if you want the backspace key to register you have to click the textfield then only it will register. this is what i am doing.
Selection.setFocus(_root.passwordIB);
passwordIB.password=true;
passwordIB is name of the textfield. on the load of the movie i am setting the focus in the password field. how to make the text field recognise the backspace key.
View Replies !
View Related
Backspace Key Not Registering.
howdy
i was trying with textfield masking and came around a problem and that problem is that the backspace key is not getting registered. not fully, if you want the backspace key to register you have to click the textfield then only it will register. this is what i am doing.
Selection.setFocus(_root.passwordIB);
passwordIB.password=true;
passwordIB is name of the textfield. on the load of the movie i am setting the focus in the password field. how to make the text field recognise the backspace key without clicking again in the text field.
View Replies !
View Related
Course Completion Not Registering In LMS
A vendor had built courses for us a few years ago. There are 5 modules. The courses are SCORM and are tracked in the LMS from Learn.com.
We recently had 60 students sign up for a course, but they are not getting completion tracking for 4 of the 5 modules. The students are using IE7 and Flash Player 9.
Completion works for the module where the completion code is send from an HTML page. The completion does not work from any of the pages where the completion is sent from Flash. The flash files were coded with AS2, here is the code on the "Finish Button":
finishBtn.onPress = function()
{
import flash.external.ExternalInterface;
ExternalInterface.call("modCompCall");
trace (score);
trace (maxScore);
_root.finalScore = int((_root.score/_root.maxScore) * 100);
trace (finalScore+"final");
getURL("javascript:var value = mm_adl_API.LMSSetValue('cmi.core.lesson_status', 'completed')");
var mycall:String;
mycall = "javascript:var value = mm_adl_API.LMSSetValue('cmi.core.score.raw', '";
mycall = mycall.concat(finalScore);
mycall = mycall.concat("');");
getURL(mycall);
trace(mycall);
trace(finalScore);
}
Does anyone know if this problem is caused by the getURL function?
We do not know when this problem appeared as no one has registered for this course for over 2 years.
This is the code from the HTML page that works...
<input type="button" name="mm_finishBtn" value="Finish Lesson" onClick="modCompCall()">
and the supporting .js function:
function modCompCall() {
if (mm_adl_API != null){
// set status
mm_adl_API.LMSSetValue("cmi.core.lesson_status", "completed");
}
Thanks in advance for any ideas.
Text
View Replies !
View Related
Button Not Registering
Hi all. I've got a simple quiz form that I've set up using radio buttons. Everything works great where you have to log in to advance to the next frame. The only problem is that I cant get the submit button (which is on the 2nd frame) to register. I've tried using "._parent" which still didnt work. Im confused. Im not really using this for anything, but I was just messing around with some actionscript.
I'll attach the code and see what you guys think:
Code:
this.stop();
// variables for username and password
var sUserName:String = tUserName.text;
var sPassword:String = tPassword.text;
//input name and password to advance to next frame
mcPasswordSubmit.onRelease = function():Void {
if (this._parent.tUserName.text == "username" && this._parent.tPassword.text == "password") {
this._parent.nextFrame();
}
else{
this._parent.tUserName.text == "";
this._parent.tPassword.text == "";
Selection.setFocus(this._parent.tUserName);
}
};
// keeps track of score
function calculateScore():Void {
var bScoreOne:Boolean = (crbgName.selectedData == "Answer1");
var bScoreTwo:Boolean = (crbgLive.selectedData == "Answer2");
var bScoreThree:Boolean = (crbgWork.selectedData == "Answer3");
var nScore:Number = 0;
if (bScoreOne) {
nScore++;
}
if (bScoreTwo) {
nScore++;
}
if (bScoreThree) {
nScore++;
}
//Outputs score to user
tQuizScore.text = ("You Answered "+nScore+" out of 3 Questions Correctly");
}
// sets up submit button for results
mcSubmit.onRelease = function():Void {
calculateScore();
};
View Replies !
View Related
Some Keys Not Registering
I am using senocular's custom Key class to detect keypresses, and for some reason it is not detecting certain keys, such as the "A" key. Has anybody else had problems with this and would you maybe know what's going on? I am using it for a game, and I can get the player to move using the arrow keys, but when I switch to a WASD config, the "A" key does not register. Thanks in advance.
View Replies !
View Related
OnRollOut Not Registering
Hopefully I can keep this as general as possible as I am sure others have run into this.
I have a simple menu that consists of movieclips side by side horizontally across the bottom of the screen.
When you mouse over one of those movieclips, it will raise up. When you mouse out of the movieclip it will go back down. The same behavior applies for the rest of the movieclips.
The problem is that sometimes the menu item will not go back down when you mouse out. I believe this happens because of the windows' refresh rate.
When you move your mouse quickly across the screen, the points that are registered are not as dense as when you move your mouse more slowly.
I'm thinking that the onRollOut is not being invoked due to the reason above. I may have moved the mouse outside the bounds of the raised movieclip, but I never "rolled out" of it because the mouse "jumped" over the boundary.
Also, since the menu items are on the bottom of the window, the onRollOut does not run on a raised menu item when the mouse pointer exits the bottom of the browser window. This is due to the fact that Flash doesn't record mouse events when the mouse is outside of the activeX object (obviously).
Nevertheless, I'm trying to find a good solution for this bug of sorts. I was thinking of using a watcher on the mouse, but that may be too much of a waste just for a menu, especially when the focus is on the interactive content. I don't want to waste memory on something that is not consistently active.
Thanks for any help!
Chris.
View Replies !
View Related
Font Not Registering In Swf
I have been following the goto video tutorials and I managed to create buttons that highlight when moused-over and when depressed. However, when I test my new movie, the font does not register as shown in the image.
The webdings font is appearing as regular Arial font in the test and I am not sure why this is happening....
Also, I have been trying (unsuccessfully) to create a flash mp3-type player that uses an XML playlist and plays swfs instead of mp3s. Basically, I would like something like this, that uses swfs instead of mp3s. Can anyone point me to any available tutorials that could at least get me started?
View Replies !
View Related
Drop Location Not Registering
ok i will try and refine my question a little.
I have my movie(scene1) and on this is a movie clip(screen. Within this movie clip i have made a drag and drop scene. there is a ball that gets dropped into a pond.
the ball(silver) is a movie clip with a button inside it (where i put the action script) and the pond(Lake) is a movie clip. I can get the ball to drag and when dropped go back to its original location.. but it is completely irrelevant of whether the ball is dropped on the pond or not.. here is my script:
On (Press)
Start Drag ("../silver", lockcenter)
End On
On (Release)
Stop Drag
If (GetProperty ("../silver", _droptarget ) eq "../Lake")
Begin Tell Target ("../Lake")
Go to and Play (2)
End Tell Target
Else
Set Property ("../silver", X Position) = "-218.9"
Set Property ("../silver", Y Position) = "-75"
End If
End On
can someone please assist?
View Replies !
View Related
KEY_DOWN Not Registering All Keys
I just decided to attempt to convert my AS 2.0 program to AS3 and one of the first things I am attempting to do it just recognize when the user hits a key on the keyboard.
I am using the WADS keys for directional movement and only the W and the D keys work.
The code is pretty simple so far and I am at a loss as to why it doesn't work.
Any ideas?
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
function keyPressed(evt:KeyboardEvent):void {
trace(evt.keyCode);
}
View Replies !
View Related
|