How to use the new StageText in air with pure as3?

Edward Hackney picture Edward Hackney · Apr 23, 2012 · Viewed 8.3k times · Source

I've written an app for android and iPhone in pure AS3 (didn't have flash builder when i started so need to finish this project like this before i move to flex) but I'm now stuck and need to control the softkeyboard and can't work out for the life of me how to change the return key to say "search" or capture it being hit to submit my form?

I see i need to use the new stagetext but not sure how to implement this...

(I've updated air to 3.2 so can use it)

Is there anyway to do this using a normal textfield?

Answer

Chunky Chunk picture Chunky Chunk · Apr 23, 2012

looking at the StageText documentation, it seems that something like the following should work. note that StageText objects are not a members of the flash display list.

[untested code:]

import flash.text.StageText;
import flash.text.ReturnKeyLabel;
import flash.events.KeyboardEvent;
import flash.geom.Rectangle;
import flash.ui.Keyboard;

//

var myTextField:StageText = new StageText();
myTextField.returnKeyLabel = ReturnKeyLabel.SEARCH;
myTextField.addEventListener(KeyboardEvent.KEY_UP, keyUpEventHandler);

myTextField.stage = stage;
myTextField.viewPort = new Rectangle(10, 10, stage.stageWidth - 20, 20); 

// 

private function keyUpEventHandler(event:KeyboardEvent):void
{
    if (event.keyCode == Keyboard.SEARCH)
    {
        trace("search button pressed");
    }
}