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.

Photo

Flex/AS3 Focus?


  • Please log in to reply
3 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:47 PM

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>


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:07:47 AM

Posted 13 October 2009 - 03:44 PM

Does Flex have an onload function?

#3 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:47 PM

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 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:01:47 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users