BleepingComputer.com: Flex/AS3 Focus?

Jump to content


Register a free account to unlock additional features at BleepingComputer.com
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.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Flex/AS3 Focus?

#1 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

  Posted 13 October 2009 - 03:33 PM

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.

<?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>


#2 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,522
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 13 October 2009 - 03:44 PM

Does Flex have an onload function?
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#3 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 13 October 2009 - 03:48 PM

Well not on load, what I meant to say was on creationComplete I execute init(), can I use some sort of variant of stage.focus = this; to apply focus to the general application?

Thanks.

#4 User is offline   Wolfy87 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 414
  • Joined: 25-July 08
  • Gender:Male
  • Location:England

Posted 13 October 2009 - 05:28 PM

Apperently stage.focus=stage; would work although, it alowls me to comple it but when ran a error box appears and my label dissapears, do i need another import of some sort?

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users