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!

4 Responses to “Setting focus on TextFields not on stage – Papervision3D”

  1. localToGlobal » Blog Archive » news review -> 45th week of 2008 Says:

    [...] > Setting focus on TextFields not on stage – Papervision3D « RockOnFlash m/ [...]

  2. dave Says:

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

  3. Bookmark::090219 « Kuu2’s Blog Says:

    [...] Setting focus on TextFields not on stage – Papervision3D [...]

  4. Will Soares Says:

    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!


Leave a Reply