Hi, I've been playing with Flex for a bit and I have been trying to get key presses to work, after about eight hours of grabbing what I can from tutorials I have realised my problem all along was the focus, I have since added in a click event to apply focus but I would like it to do it on load, is this possible?
Thanks for any help, Wolfy87.
Thanks for any help, Wolfy87.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" height="300" width="300" creationComplete="init()" enterFrame="refresh()" backgroundGradientColors="[0xffffff, 0xffffff]">
<mx:Script>
<![CDATA[
import flash.display.Sprite;
import mx.controls.Label;
public var mySprite:Sprite = new Sprite();
public var output:Label = new Label();
public function init():void
{
mySprite.graphics.beginFill(0x0000cc);
mySprite.graphics.drawCircle(50, 50, 25);
mySprite.graphics.endFill();
mySprite.x = 0;
mySprite.y = 0;
rawChildren.addChild(mySprite);
output.text = "Press a key";
output.width = 200;
output.height = 50;
output.x = 100;
output.y = 100;
rawChildren.addChild(output);
this.addEventListener(MouseEvent.CLICK, clickHandler);
this.addEventListener(KeyboardEvent.KEY_DOWN,keyPressed);
}
public function clickHandler(event:MouseEvent):void
{
stage.focus = this;
}
public function keyPressed(evt:KeyboardEvent):void
{
output.text = "keycode: " + evt.keyCode;
}
public function refresh():void
{
}
]]>
</mx:Script>
</mx:Application>

Help
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.




Back to top









