Setting focus on TextFields not on stage – Papervision3D

Well, I finally came up with a fix for this issue and thought to archive it.  Basically, the issue is that when you have textfields in a Sprite that you use for a material source for Papervision3D, you want to be able to set focus to those text fields.  Without them being on stage, however, it doesn’t work to say “stage.focus = myTextField”.

So, very simply, all you have to do is add the textfield to the stage, then use stage.focus = myTextField, then re-add back to your Sprite.  Bingo, you have focus in your TextField.  Now, I should say, that i’ve seen it work with just using stage.focus = myTextField, but in this particular situation, adding it to the stage first, then setting focus, then adding it back worked.  So give it a whirl either way.

example:

stage.addChild(myTextField);
stage.focus = myTextField;
this.addChild(myTextField);

Bam! done.  As long as you’re redrawing your material so that you can see what you’re typing ( bitmapMaterial.drawBitmap()), it’ll work just fine.

Tabbing is controlled easily with:


protected function handleKeyUp(e:KeyboardEvent):void
{
if( e.keyCode == 9 ) // tab
{
if( currentField == username )
changeToPassword();
else if( currentField == password )
changeToUsername();
}
}

hope that helps someone!

    • dave
    • December 20th, 2008

    totally wicked man.. tips like these makes all the difference. thanks!

  1. Well done!

    I found the same solution “stage.focus = myTextField”, but for a MovieMaterial or MovieAssetMaterial, the stage is null. I solved it passing the stage trough a parameter.

    Worked perfectly with your solution.

    Thanks a lot!

  1. November 16th, 2008
  2. February 19th, 2009

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s