Archive for category Air

Flash on iPhone – Automatically convert dynamic text to high performance bitmaps (with filters)

During the recent optimisation and performance experiments I have been building for running Flash/Air on iOS, it became important to develop a way to have dynamic text display that wasn’t going to slow down performance on the device.

For instance if you are building a game and need to display the players score on screen you’ll require a dynamic field that can display and update this value when required. Currently any form of vectors (text included) are generally not going to help your playback performance on iOS and mobile devices, I’ve pretty much made a rule to avoid using them all together on the final display list. Another surefire way to start slowing things down is to use dynamic filters – so in keeping with these concerns I built a simple class that will automatically convert your TextField into a dynamic bitmap based alternative. The best thing about it is that it’s very simple to use and can automatically replace the orignal TextField with itself.

bitmap_text
(click to see the demo)

Simple and effective, but far from perfect

Although the original text and the bitmapped versions look very similar in the above example, this BitmapText class is far from a complete solution. The aim isn’t to create a complete bitmapping solution – for anyone that has worked dynamically with text in Flash will know there are a lot of fruity areas where measurements and formatting results aren’t completely reliable. For instance while it is set up to deal with basic alignments (left, right and centred) the class is only currently built to work with single lines, so multiline dynamic text is not currently possible. The focus has definately been on what was the quickest most pragmatic solution for my needs. Large dynamic areas of text could just as easily be services by manually making a bitmap copy.

Usage and Quick Overview

The constructor for the class looks like this:

public function BitmapText(thisField:TextField,thisAlphabet:Object =null, thisCharList:String=null, thisProps:Object = null) 

You can see that the only required argument is the TextField object that you require BitmapText to replace, but you can also add the following:

  • thisAlphabet- a storage object of already created letter bitmaps, will be created by this instance if not supplied
  • thisCharList – a string containing the characters you wish to include and be stored as bitmaps for use with the BitmapText object, an internal default list contains all upper and lower case characters as well as numerals and basic keyboard symbols
  • thisProps – an object you can use to feed further property values in to the class

The simplest usage would be something like this:

var myBitmapText:BitmapText = new BitmapText(myTextField) 

Which will make a BitmapText copy of your existing on screen TextField named myTextField (and remove the orignal from the stage).
To update the text, you can simply use the following:

myBitmapText.text="New text to display"

Tweak properties

The class itself is quite simple and has a couple of properties you can tweak, the mor eimportant ones are:

  • margin – specifies the space between characters (bitmap text spacing is very simple – similar to monotype fonts)
  • edge_buffer – specifies an edge buffer in pixels to add when making bitmap character copies. This is particularly handy if you have drop shadow or glow filters that won’t be picked up or cropped otherwise

Thre are a couple more properties you can set within the class which shuld be self evident if you look at the code.

Download

Feel free to take, use or modify the class for your own projects, if you extend it or fill out some of the gaps, please ping it back and I can add the additions. The only request I make is that you keep the credit to me/codeandvisual.com in the code.
Bitmap Text for Flash on iPhone

Tags: , ,

2 Comments

Exporting for iPhone using Air 2.7 and FlashDevelop – Part Three, Generating Developer Certificates, Provisioning Profiles and .p12 files

Continuing on from Part Two of the Exporting for iPhone using Air 2.7 and FlashDevelop Tutorial You should have a FlashDevelop project built and ready to export your swf file for conversion into an iOS friendly .ipa file. In Part Three we will learn about the certificates required by Apple in order to create your .ipa file and get it on to your device. For the time being we will be compiling for testing directly on a device as opposed to uploading to the App Store, which requires slightly diferent certificates. A word of warning, although I’m generally a PC user, this stage will require a Mac in order to generate a certificate request and then convert our certificate into the right .p12 format. There is a PC alternative to this for which I’ve linked below.

Frank Costanza

Serenity Now

I’ll start be releasing all of my Apple angst and putting it to the side. I found this part of the process to be confusing and frustrating, not in the least because in comparison to the Android work flow this whole process is unnecessary. The ironic part for me was that compared to how hard Apple have applied themselves to the “it just works” philosophy for consumers, I felt the exact opposite about the developer experience. A big part of the reason was seamingly arbitrary processes that weren’t well explained and used a lot of new jargon. The most telling observation is probably that from a standing start it took me about 2 days to complete on iOS what took about 20 minutes on Android – having had no previous experience with either. But let’s move on because it’s all worth it once you get your app playing on the device, just know that inside I’m gritting my teeth as we walk through most of these steps. Apoligies if some of my frustration seeps out.

Apple Developer Centre

The first thing you’ll need is an iOS Developer account (and a credit card because these cost $99 a year). Once you’ve paid your ransom you can log in to the iOS Dev Center (this seems to work better in non-ie browsers):

http://developer.apple.com/devcenter/ios/index.action

From a Flash developer’s point of view you’ll only need to come to the The iOS Dev Center in order to generate and register certificates. We’ll also need it to register the particular device we wish to test on but more about that later. I’d almost ignore everthing else as the bulk of the content is aimed towards Apple developers working in XCode. So, by way of explaination, we will require two things in order to build and test our app on an iOS device, these are:

  1. A developer certificate – this allows you to create a .p12 file to sign and compile your app to ipa format
  2. A provisioning profile – this allows you to test your app on your particular device

Maybe it’s just me, but even writing the above sounds a little confusing because they are new terms that I don’t have any past experience with. Ultimately these are just authorisation keys to register your app, one is for you as a developer, and the other is sort of like a sub-authorisation for your app/device combination. Here’s a handy glossary that Adobe put together to help do a bit of the explaining.

Developer Certificate

The first thing we need to do is to get Apple to generate us a Developer Certificate. Sounds simple enough, but unfortunately it’s a multistage process and in my workflow I switch over to my trusty Mac Mini to take the path of least resistance. For those of you without access to a Mac, there’s a windows alternative method that Adobe has graciously explained, click the link below for more info:

Generating a Certificate Signing Request for iOS using Windows

On the Mac we open up “Keychain Access”. Being unaccustomed to Mac I wasn’t sure what this was or where to find it, but it seems to be the central OSX authorisation manager covering various software and devices within the Mac ecosystem. You can find it by going to Applications>Utilities>Key Chain Access.

A quick reference on locating the Keychain Access, Step 1

Mac Utilities

step 2

Mac Keychain Access

The process is then as follows (from Adobe’s tech note):

  • On the Keychain Access menu, select Preferences.
  • In the Preferences dialog box, click Certificates. Then set Online Certificate Status Protocol and Certificate Revocation List to Off. Close the dialog box.
  • On the Keychain Access menu, select Certificate Assistant > Request a Certificate from a Certificate Authority.
  • Enter the e-mail address and name that matches your iPhone developer account ID. Do not enter a CA e-mail address. Select Request is Saved to Disk and then click the Continue button.
  • Save the file (CertificateSigningRequest.certSigningRequest).

Once you’ve saved the file to your hard drive you may as well stay on the Mac as we’ll be using it again later to create a .p12 file. Back at the iOS dev centre you can now upload this request file and get a developer certificate in return. Why all of this can’t be done magically behind the scenes on a web interface is a mystery, but that seems to be a common theme in this process.

In the IOS Provisioning Portal, click on “Certificates” in the right hand column, and then the “Development” tab in the main content area that appears on the right. From here you can go down to the bottom and click on the button to upload your Certificate Signing Request (CSR) for Apple to approve. Once you click Submit you can go back to the Development tab, if you’re not taken there automatically, and you should see your certificate listed. It might say “Pending” next to it, but if you refresh once or twice it should switch to “Issued”. Download it to your machine and then go back to Keychain Access so that we can add it to your machine. Select File > Import and then navigate to the certificate (the .cer file) you obtained from Apple. We’ll come back to Keychain Access later in order to generate a .p12 file.

Registering Your Test Device

In order to eventually test your app on an actual device you’ll need to register it and then add a provisioning profile on the device itself to allow your app to be installed.

The first step in this process is to find out the Unique Device ID (UDID) of your iPhone/iPod/iPad. The quickest way I know of is to hook up your device to your computer and open up iTunes. Locate your device in the left hand column (under “devices”) and click on it to open up the summary page in the main area on the right. In the first section iTunes should be displaying information about your device including Name, Capacity, Software Version and Serial Number. For some reason Apple decided they couldn’t list the UDID of your device just blatantly out there for you to see, so instead you need to know the secret place to click in order for it to appear. And that place is on the serial number. One click on the serial number and it will show your UDID which you can copy and paste (trust me, even though there is no way to selct the text, once you click you can do a ctrl+C and the UDID will be copied to your clip board).

Find Your UDID

With your UDID in hand, return to the Provisioning Portal and on the left hand column select the “Devices” option. In the Manage tab on the right hand side click on the “Add Devices” button. Here you can name your device and enter in it’s UDID.

Creating an App Id

Next we will create an App ID which will register your app and allow it on to your iOS device. On the left hand column of the iOS Provisioning Portal select the “App IDs” option and then in the main content area on the right click on the “New App ID” button. Some of these options feel a bit arbitrary and it’s not immediately obvious when and how these will be used later down the track, despite the tips Apple have given.

The first thing you need to add is a title for your app, this is purely for identification within the Portal and can be something nice and pretty like “My Awesome App” – basically the title of your app will suffice.

Next it’s the bundle seed ID, and for our purposes we’re just going to take the simple route and choose “Generate New”. From what I can tell it’s possible to have more than one app bundled together into a sort of suite which can utilise the same Bundle seed, but let’s just consider this a one off for now.

Finally you have to add a unique Bundle Indentifier which is appended on to the end of the Bundle seed in order to create the complete App ID. Probably the best advice here is to follow the same approach most people use when creating package names in AS3 and use your domain url in reverse in order to be sure that you have something truly unique. (It seems that you have to provide something that is unique not only to your own projects, but to every other app out there in Apple land). So for me I’d enter in something like com.codeandvisual.myawesomeapp. It’s not important to understand too much else, just enter in those 3 things and click Submit. At this point you should be taken back to the Manage tab of the App IDs section and your new App ID should be listed at the bottom.

Creating a Provisioning Profile

Now we are able to create what is known as a Provisioning Profile. You’ll generate this using your certificate and your App ID and will be needed to allow you to get your App onto a registered iOS device. Click on the “Provisioning” option on the left hand menu of the iOS Provisioning Portal and then make sure you are on the “Development” tab of the page that loads. (You’ll switch to distribution when it’s time to actually submit your app to the AppStore). Here you can enter the required details:

  • Enter in a name. (I just use the same name as my App as they are ostensibly tied together anyway).
  • Select the Developer Certificate to use (you should only have one option to check there).
  • Select an App ID (again you should have only one at this point to chooseyour new Profile form).
  • Choose which device you’ll be uploading and testing on (again if this is your first walk through the process you’ll have only one).

Click Submit and you should see your new profile listed on the page that loads. Again this might have a status of Pending, but refresh the page and it should have updated to “Active”. We’ll install this onto our device next, so download the file and open up iTunes.

Make sure your device is plugged in and iTunes has finished synching or whatever it needs to do. Go to File>Add File To Library and select your provisioning file. Sync your device again one more time for luck and your device should be ready to receive your App when it’s compiled.

A little tip I read to double check that your provisioning file is actually installed is to try and add the file again in the same way – iTunes should tell you that a version already exists on the device if all was done correctly. You can be more categorical by going to your device and opening settings>general>profiles and seeing if your Provisioning Profile is listed.

Creating a .p12 File

You’re almost free of the Mac specific steps now besides one last thing, and that is to create the .p12 file which will allow you to compile your .swf to a .ipa file. For a quick footnote, here’s a definition I found about what a .p12 file actually is:

The P12 file type is primarily associated with ‘Personal Information Exchange File’. In cryptography, a public key certificate (or identity certificate) is a certificate which uses a digital signature to bind together a public key with an identity. The certificate can be used to verify that a public key belongs to an individual. This is a PKCS #12 file. In cryptography, PKCS refers to a group of Public Key Cryptography Standards devised and published by RSA Security.

All we really need to know is that it’s an authorisation certificate to please the Apple ecosphere Gods so they allow us to put our awesome app onto our device. Geez, thanks for that. In order to do so we’ll jump back to the Mac. Again there is a way to do this on windows machines which I will link to below, but for sake of ease I’m going to go the Mac path.

Click here to read how to create a .p12 file on a Windows machine

In Mac world we need to go back to the Keychain Access and from there Adobe’s notes say it best:

  • Select the private key associated with your iPhone Development Certificate.
    The private key is identified by the iPhone Developer: public certificate that is paired with it.
  • Select File > Export Items.
  • Save your key in the Personal Information Exchange (.p12) file format.
  • You will be prompted to create a password that is used when you attempt to import this key on another computer.

This .p12 file is the key to allowing you to compile a .ipa file from your .swf and install it onto your machine. Copy this to a folder handy to your development machine and you’re ready to rock’n'roll.

Licence to Ill

From this point on you shouldn’t require a Mac at all so, if you’re like me, you can power down your Mac Mini until next time you’re required by the powers that be to do something on a Mac just because they said you have to. That next time may well be when it comes time to create a deploy version of your app which will require you to redo a portion of these steps in order to upload an Appstore approved build. We’ll get to that in a later tutorial, but until that point you can fairly much develop away as you please.

Next.

In the Part Four we’ll go through the process of using the .p12 certificate and provisioning profile to generate your .ipa file ready for uploading onto your iOS device for testing.

Index

Part 1 – Installation
Part 2 – Creating an iPhone Project
Part 3 – Generating Developer Certificates, Provisioning Profiles and .p12 Files
Part 4 – Creating an Air Certificate and Compiling to .IPA
Part 5 – Loading your .IPA File onto a Test Device

Tags: , , , , ,

3 Comments

Exporting for iPhone using Air 2.7 and FlashDevelop – Part Two, Creating an iPhone Project

Continuing on from Part One of the Exporting for iPhone using Air 2.7 and FlashDevelop Tutorial you should now have FlashDevelop primed with the Flex/Air 2.7 SDK and you’re now ready to start building your amazing iPhone App. In Part Two you will see how to set up an iPhone Air project which will allow you to export an swf ready to be packaged up into an ipa file (the file format for iPhone Apps).

Developing for iPhone (and mobile in general)

We’ll skip through actually coding your application as this is a topic in-and-of itself, but for the most part it’s no different to coding any other SWF, you just have a few more considerations to make, eg. the touch interface and importantly, memory management. I don’t mean to brush over the topic but it will have to be covered in another tutorial.

Installing an iPhone/Air Template into FlashDevelop

In order to create iPhone projects the easiest thing to do is to install a template into FlashDevelop. Here’s a template you can download that I use:

iPhone Project Template

The original was created by a German blogger and contains a couple of handy dynamic .bat files that you will use to package your .swf into a .ipa file. I’ve editied it a little bit so that works with Air 2.7.

Once you’ve downloaded and unzipped the template you can install it into FlashDevelop by copying it into the correct Projects folder. This one confused me for a while as there are two projects folders. One is part of the FlashDevelop install directory and the other is in your user appData folder. There is a handy shortcut from the FlashDevelop interface that will open up your appData folder and it seemed to make sense that this woud be the location to copy the files to, but I’ve only been able to get results by copying directly into the applications install directory, so that’s what we’re going to do here.

Project Template Location

Once you find FlashDevelop in your Program files directory (hint if you’re using a 64 bit system it will be installed into “Program Files (x86)” ) go in to the directory named Projects. Here you will see that there are already some Project Templates installed as they come standard with FlashDevelop. Copy the downloaded iPhone/Air Template into this folder. Once you restart FlashDevelop it will be there for you to select when you choose to create a new Project.
Create a New iPhone Project

Next

In Part Three we will export our project and learn how to get a certificate from Apple in order to export and package up the swf into an ipa file.

Index

Part 1 – Installation
Part 2 – Creating an iPhone Project
Part 3 – Generating Developer Certificates, Provisioning Profiles and .p12 Files
Part 4 – Creating an Air Certificate and Compiling to .IPA
Part 5 – Loading your .IPA File onto a Test Device

Tags: , , , ,

4 Comments

Exporting for iPhone using Air 2.7 and FlashDevelop – Part One, Installation.

With the recent release of Air 2.7 Adobe has stepped up the performance of Flash on the iPhone, so here’s a quick guide on installing the new SDK for use with FlashDevelop.

Be a Lazy Coder with FlashDevelop.

If you use a lot of AS3 and have never tried FlashDevelop before then you don’t know what you’re missing out on. Someone once said that a lazy coder is the best sort of coder, and with FlashDevelop your level of laziness can truly soar! But lazy doesn’t mean writing bad code, quite the opposite, lazy means not wasting time on the no brainer stuff that is laborious and repetitive or just plain below us as humans – that’s what computers are for! And that’s just what FlashDevelop is good for. I could go on about all the great code completion and productivity features of FD, but you won’t truly understand until you give it a go yourself.

You can grab FlashDevelop from their site (it’s open source): http://www.flashdevelop.org/wikidocs/index.php?title=Main_Page

So assuming you have FlashDevelop installed and are reasonably familiar with it, lt’s go ahead and set things up.

Merging Flex and AIR SDKs.

The first thing to note is that this set up will be for a project compiled by FlashDevelop (not a Flash IDE project). If you’re still using Flash to do your compiling it might take a little getting used to but with the use of an SWC to hold your library items you can set yourself free from the main timeline and use FlashDevelop to do the magic for you. The advantages of this is that you’ll have faster compiles (as FD doesn’t need to repackage all of your library items with each compile) and you can for the most part have a very clean separation between your code and your graphics.

I’d suggest downloading the latest Flex SDK from Adobe so you can start with the latest and greatest: http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK The latest version is currently 4.5.1.21328

Once it’s downloaded, unzip the file to a folder on your harddrive where you will point FlashDevelop to.

Next download the Air SDK: http://www.adobe.com/products/air/sdk/ The latest version is currently 2.7

Unzip the Air package, and then you need to merge it with the Flex SDK files you’ve just downloaded. What this means is that you copy all of the files from the Air package into the folder of the Flex SDK so that all the newer files and overwrites come from the Air side. Trusting in the Windows Gods this is just a matter of going into the Air folder, selecting all and copying, then going in to the Flex Folder and pasting. Windows will ask if you want to overwrite and you can say yes. This will keep all of the Flex files that are in those folders if there aren’t newer versions in the Air SDK. Fingers Crossed.

Merge SDK Files

Pointing FlashDevelop to the SDK files.

Next we need to point FlashDevelop to the our new hybrid Flex/Air SDK location. You can do this on a per-project basis, or the way that we’re going to do here which is globally, so that by default every project you use will compile with this particular SDK. Open up FlashDevelop and go to Tools>Program Settings (or you can just press f10). On the left hand column you want to select AS3Context and you’ll see the right hand side will open up with a series of options. In the Language section there will be a “Flex SDK Location” property. This is where you want to point FlashDevelop to your SDK folder, so click on it and browse to the location where you made your AIR/Flex Hybrid. You want to select the folder that contains the ant, asdoc, bin folders etc. and press OK.

Point FD to SDK

Next.

An so now you’re ready to compile using FlashDevelop and AIR 2.7! In Part Two we’ll set up FlashDevelop to create an iPhone project that will generate an IPA file of your swf.

Index

Part 1 – Installation
Part 2 – Creating an iPhone Project
Part 3 – Generating Developer Certificates, Provisioning Profiles and .p12 Files
Part 4 – Creating an Air Certificate and Compiling to .IPA
Part 5 – Loading your .IPA File onto a Test Device

Tags: , , ,

No Comments