The title is a bit of a mouthful but it’s a very specific task that I’ve come across when making apps for iOS using AdobeAir. Often you want to tap in to some of the niceties of the operating system and one of those cases is the contextual keyboard – the specialised keyboards that appear when you’re entering in an email or a phone number for instance. There are 6 of these specified in the SoftKeyboardType class: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/SoftKeyboardType.html.
So the one thing to know when trying to use these keyboards on iOS is that you need to be using StageText – the standard TextField class will not be able to tap in to these as of yet because it’s really accessing an operating system level function that Adobe Air has not made available to the humble TextField. In that light, this quick tutorial explains how to go about using StageText to ultimately give you the option to use these different keyboard types. I’ve also included instructions on how to use customs fonts for this process too, just to complete the general use case requirements you may have.
- Firstly copy the fonts into your assets folder. By this I don’t necessarily mean the “Assets” folder (I have a feeling that this folder sits within a parent folder which is really what I’m talking about). Having said that, you might be able to place them there anyway and just make sure you include a relative path to them.
- Embed the font for the device. To do this, add the reference to the fonts into your application.xml file inside the infoAdditions section like so:
- Embed the font for AS3. You can do this by adding the font to your Flash library, or you can use an embed code. I’ve done the latter and just reference the same files that were placed in the assets folder for bundling. This is the relative path to the file you’re embedding on I believe (or it might just be relative to the src folder). In my case it was one and the same. Embedded as so:
1234[Embed(source = "../bin/BurbankSmall-Medium.otf", fontName = "Burbank Small", mimeType = "application/x-font", advancedAntiAliasing = "true", embedAsCFF = "false")]private var font_1:Class;
- Finally, if you have used the right name, it means all the hard work is done and you never have to worry about the name again because we can reference it like this:
1234var myFont:Font = new font_1()myStyle.font = myFont.fontName
- In terms of using StageText. I think the easiest thing is to place a standard TextField on to your scene in the Flash IDE and style it as desired (if that’s the way you’re building your interfaces). I’ve created a function that will automatically convert a TextField instance to a StageText instance and copy all of it’s properties over (font/size/colour/position etc.). I’ve wrapped it up in a little class and attached, but you can just extract the function and place it in your own class somewhere if you like. Download the TextField to StageText class. Usage is pretty self explanatory. var
123myStageText:StageText = TextAir.convertToStageText(myTextField)
- Finally, to set the keyboard type to email, use the following:
123myStageText.softKeyboardType = SoftKeyboardType.EMAIL
Just a note – you might find that it works on the desktop and not on the device, this is usually because there’s something wrong with stage 2 – either it’s not been added to the infoAdditions properly, or the relative path you think should work, isn’t.