Talking about Actionscript 3, Flash and iOS.
It seems you can’t call yourself a developer if you did not build at least one iPhone application. For most developers, the biggest problem of getting started with iPhone development is they don’t have a Mac. Windows based notebooks are a lot less expensive, and having both a Windows notebook and a MacBook is not for everyone.
Moreover, a lot of readers of this blog are skilled with Flash and ActionsScript3, but they don’t feel comfortable with Objective-C, the programming language used to create native iPhone applications.
Well, I am going to show you a step by step detailed guide to help you publishing an iPhone application just with your Windows computer, thanks to Flash Professional CS5.5.
This will be a very long tutorial but once finished, you will be able to create a Flash application and make it run on your iPhone as a native application.
1 – CREATING THE FLASH APPLICATION
This is the easiest part, as you only have to do what you are really used to do: create a Flash application. Just remember to select AIR for iOS. Leaving all settings with their default values, you will create a 320×480 pixels document, which is the size of the non-retina iPhone display.
We will start with something simple, with this script:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Main extends Sprite {
private var circle:circleMc;
public function Main() {
circle= new circleMc();
addChild(circle);
stage.addEventListener(MouseEvent.CLICK,moveCircle);
}
private function moveCircle(e:MouseEvent):void {
circle.x=mouseX;
circle.y=mouseY;
}
}
}
Where circleMc
is just a small red circle. It’s quite obvious what this script is supposed to do: clicking (later: tapping) on the stage, you will move the circle under the mouse pointer (later: your finger).
Test the movie, and once you are sure everything works, it’s time to create the developer certificate
2 – APPLYING TO APPLE IOS DEVELOPER PROGRAM
If you never developed an iPhone application, probably you aren’t part of Apple iOS Developer Program, so you must enroll to it. This is a paid service which costs $99/year, or €79/year if you live in the Euro zone. Actually, the change is a bit unfair since the Euro certification may cost up to $10 more than the Dollar certification.
Anyway, everything starts from this page, click on Enroll Now and follow the steps filling forms with your information.
As you proceed with the enrollment, you will notice a warning:
“You must have an Intel-based Mac running Mac OS X Snow Leopard or later to develop Mac OS X and iOS apps for the App Store”.
Ignore it, as you won’t need any Mac.
According to Apple’s suggestions, if you intend to enroll in a paid Developer Program for business purposes, you may prefer to create a new Apple ID that is dedicated to your business transactions and used for accounting purposes with Apple, and your Apple ID is associated with an existing iTunes Connect account you should create a new Apple ID to avoid accounting and reporting issues.
They are right, I tried to upgrade my iTunes account, and my Developer certification was kept on hold because of some difference between my living and billing addresses, which is quite common if you work both at home and in a studio.
So I recommend to create a brand new account.
Once the (huge) process is done, you will finally see this screen:
Enter the activation code you should have received in your email after the purchase, and you are now an iPhone developer!!
In some cases, Apple will keep your certification on hold anyway, to ensure the (big) amount of data you entered is correct. It will be asked you to send a fax with a notarized copy of a government issued identification and wait “several working days” to get the certification. Before doing it, go to the contact page and send a form explaining you made everything right. In most cases, common sense will win and you will have your account approved in less than 24 hours.
3 – GETTING A DEVELOPMENT CERTIFICATE
Once you registered as developer, you need to acquire a Development Certificate, as well as register your Apple devices and applications.
Go to iOS Dev Center, log in and enter the iOS Provisioning Portal:
Then click on Certificates:
And since you are new to the iOS Provisioning Portal and don’t have any certificate, click on Request Certificate:
You will find yourself in front of a page where you are asked to choose a file and submit it to the page:
Don’t click anything at the moment, as you don’t have any file yet. We have to create it.
It’s time to play a bit with SSL protocols.
Go to the Win32 OpenSSL Installation Project and download and install both Win32 OpenSSL v1.0.0e Light and Microsoft Visual C++ 2008 Redistributable Package.
First install Microsoft’s package, then Win32 OpenSSL which will probably install in C:\OpenSSL-Win32
path. During this tutorial, I will refer to this path, but obviously you should change yours if different.
Open the command prompt window by entering cmd
into Start-Run or through Start->All Programs->Accessories
, and write:
cd \OpenSSL-Win32\bin
Remember I am assuming OpenSSL has been installed on C:\OpenSSL-Win32
. Anyway, access to bin
folder inside your installation.
Once you’re in the bin
folder, write:
openssl
To change the prompt from C:\OpenSSL-Win32\bin>
to OpenSSL>
.
If you get a warning you can’t open the config file, don’t worry at the moment. Write:
genrsa -out thekey.key 2048
To generate a file called thekey.key
in bin
folder. Feel free to change the file name if you want. I’ll assume you will use the same filename I used. Then write:
req -new -key thekey.key -out certificate.csr -subj "/emailAddress=info@emanueleferonato.com, CN=Emanuele Feronato, C=IT" -config "openssl.cfg"
Which will create a file called certificate.csr
in bin folder
. Just change thekey.key
with your key filename, info@emanueleferonato.com
with the email address you used during the registration, Emanuele Feronato
with the name you used during the registration and IT
with the country code of the Country you live in. -config "openssl.cfg"
is necessary only if you previously got the warning you couldn’t open the config file.
This is how my command prompt window looked like once I’ve finished (sorry for the italian text, it’s a real example):
Microsoft Windows [Versione 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Tutti i diritti riservati.
C:\Users\User>cd \OpenSSL-Win32\bin
C:\OpenSSL-Win32\bin>openssl
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
OpenSSL> genrsa -out thekey.key 2048
Loading 'screen' into random state - done
Generating RSA private key, 2048 bit long modulus
.....................+++
........+++
e is 65537 (0x10001)
OpenSSL> req -new -key thekey.key -out certificate.csr -subj "/emailAddress=info@emanueleferonato.com, CN=Emanuele Feronato, C=IT" -config "openssl.cfg"
Loading 'screen' into random state - done
OpenSSL>
Finally you can upload the file .csr
in the certificate page, and your certificate will be in Pending Issuance status.
Refresh in a couple of minutes, and your certificate will be issued! Download it (its name should be developer_identity.cer
) and for the sake of simplicity save it in the same bin
folder where you created the other files, as the process is not over.
Connect your iPhone to iTunes and get the UDID, you will find in the iPhone page and probably you will have to click on the series number in order to get it.
Return to the Provisioning Portal and click on Devices, then since you shouldn’t have any device installed, click on “Add Devices”.
Add a device name and the UDID you just got from iTunes, then click on “Submit”:
Your iPhone should be successfully registered now.
Time to register your app now. Go to App IDs page and click on New App ID.
You will be asked to enter a name, you will find a precompiled App ID prefix and you will be asked to enter the APP ID suffix. You can enter anything you want but you’d better follow Apple guidelines using the reverse domain name style. Click on “Submit”:
And now your App is registered.
One last effort and go to Provisioning to create a Development Provisioning Profile and click on “New Profile”:
Fill the form (it shouldn’t be hard at this time) and click on “Submit”
Your Provisioning Profile will appear in Pending mode:
And just like before, in a few minutes it will be Active. Download it (it should call Test_Profile.mobileprovision
if you named the Provisioning Profile as Test Profile) and save it in your friend bin
folder.
Open a new command prompt window, enter the old same
cd \OpenSSL-Win32\bin
and
openssl
and from OpenSSL>
prompt write:
x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
to create a file called developer_identity.pem
, then
pkcs12 -export -inkey thekey.key -in developer_identity.pem -out iphone_dev.p12
to create an iphone_dev.p12
file. You will be asked for a password, enter it (and possibly, remember it).
This is how my prompt command window looked like:
Microsoft Windows [Versione 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. Tutti i diritti riservati.
C:\Users\User>cd \OpenSSL-Win32\bin
C:\OpenSSL-Win32\bin>openssl
OpenSSL> x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
OpenSSL> pkcs12 -export -inkey thekey.key -in developer_identity.pem -out iphone_dev.p12
Loading 'screen' into random state - done
Enter Export Password:
Verifying - Enter Export Password:
OpenSSL>
Now finally we have everything we need.
4 – PUBLISHING WITH FLASH FOR IPHONE
Back to Flash Professional CS5.5, in your publish settings, add the certificate file, the password you entered before, the provisioning profile, and select the iOS development type as “Quick publishing for device testing”.
Publish the application. It will take up to some minutes, unlike regular Flash movies publishing. And finally the App is ready to be uploaded to your iPhone.
This should be the content of your Flash application folder: look at the iTest.ipa
file. It’s your App!!!
Go to iTunes connect the iPhone, and install the provisioning profile, using File->Add To Library
. Then, synchronize your iPhone to have it installed on it. To check if everything worked fine, in your iPhone select Settings->General->Profiles
and look for your profile.
With the profile installed, add your application with File->Add To Library
, and you will find it in your Sync Apps page:
Synchronize your iPhone again, and you will find the working application on your device:
Congratulations, you made it. Now, let’s port your Flash blockbusters on iPhone
Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.