显示标签为“Flash”的博文。显示所有博文
显示标签为“Flash”的博文。显示所有博文

2011年10月29日星期六

Building a Hangman iPad App with Flash – Programming Gameplay

Building a Hangman iPad App with Flash – Programming Gameplay:
Welcome to the second part in our tutorial series on building a Hangman game for the iPad with Flash. While the first tutorial primarily focused on getting setup to code iOS apps with Flash, this tutorial will focus on the ActionScript and game logic necessary to actually program hangman. Let’s get started!



Where We Left Off. . .


In the first part of this tutorial series, we went through the device provisioning process, adding an app icon and loading screen, and how to sync the app to your iPad during development. In this part of the tutorial, we will finish coding the gameplay.

Add the TweenLite Project


This tutorial will incorporate the TweenLite project, so go ahead and grab a copy. Once you have downloaded it, extract it and add the “com” folder to the same folder your hangman project is in. Finally, add the following along with the rest of your project imports:

import com.greensock.TweenLite;



Step 15: Adding a Guessword Text Field


Select the Text Tool, make sure the TextField is not selectable, and that the following properties are set:

  • Size: 45pt
  • Color: #0000FF
  • Align: Center



Draw a TextField out on the stage and set the following properties on it:

  • X: 98.00
  • Y: 110.00
  • W: 540.95
  • H: 54.00


Give it the instance name “guess_word_text”.




Step 16: Creating the Game Buttons


Select the Oval Tool and make sure the following properties are set on it:

  • Fill Color: #000000
  • Stroke Color: #0000FF
  • Stroke: 3.00
  • Style: Solid


Hold “Shift” to conform the oval to a circle and drag out a circle onto the stage.

With the “Selection Tool” drag around the circle to select both the fill and stroke. You can tell they are both selected by a “Hatch Pattern”.


With both the fill and the stroke selected give the circle the following properties:

  • W: 51.00
  • H: 51.00


Now right click on the circle and choose “Convert To Symbol”. Give it the name “GameButton”, make sure “Export For Actionscript” is checked and

that the class is set to “GameButton”.


Now double click on it to go into editing mode. Select the Text Tool and make sure the following properties are set:

  • Color: White
  • Size: 20pt


Drag out a TextField into the MovieClip and set the following properties on it:

  • X: 11.00
  • Y: 10.00
  • W: 29.00
  • H: 28.00


Make sure the TextField is not selectable:

Give the TextField the instance name “game_btn_text”.

Now Delete the Circle off the stage.

Step 17: Game Button Class


Go to File > New and choose “Actionscript File”. Save this as “GameButton.as” in the same folder as your “Hangman.fla”.

Enter the following code into the “GameButton.as”.

package  {

import flash.text.TextField;
import flash.display.MovieClip;
public class GameButton extends MovieClip{

public function GameButton() {
this.game_btn_text.selectable = false;
this.mouseChildren = false;

}

public function setText(theText:String):void{
this.game_btn_text.text = theText;
}
public function getText():String{
return this.game_btn_text.text;
}

public function disable():void{
this.mouseEnabled = false;
trace("YEAH");
}

}
}

Here we import the classes we need, set the game_button_text to not be selectable, set mouseChildren to false so the

TextField cannot recieve Mouse Events, added some getter and setter methods to set the text on the TextField, and a disable() function

that will disable the buttons from receiving Mouse Events. Get and set the text on the game_btn_text.



Step 18: Imports for the Main Game


Open “Main.as” which you should have available from part 1. Add the following imports to the top, underneath the package declaration:

import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.Sprite;

These are the classes we will need througout this tutorial



Step 19: Creating the Variables


Enter the following code just below public function Main extends MovieClip:

public class Main extends MovieClip{
//Used for the TextFields on Our Game Buttons
var alphabetArray = ["A","B","C","D","E","F","G","H","I","J","K",
"L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z"];
//The original word
var theWord:String;
//The guess Word
var guessWord:Array;
//An array for our game buttons
var gameButtonArray:Array = new Array();
//This will hold all the words
var wordList:Array;
//A Sprite we draw the hangman into
var hangmanContainer:Sprite;
//Number of Wrong Guess
var numWrong:int = 0;



Step 20: Creating the Game Buttons


Enter the following code below the public function Main() constructor:

private function setupGameButtons():void{
var xPos=150;
var yPos = 600;
gameButtonArray = new Array();
for(var i:int = 0;i<alphabetArray.length;i++){
if(i == 8 || i == 16){
yPos+= 65;
xPos = 150;
}
if(i == 24){
yPos+=65;
xPos = 330;
}
var gameButton = new GameButton;
gameButton.setText(alphabetArray[i]);
gameButton.x = xPos;
gameButton.y = yPos;

gameButtonArray.push(gameButton);
addChild(gameButton);
gameButton.addEventListener(MouseEvent.CLICK,checkLetter);

xPos+=60;
}
}

We first declare two variables xPos and yPos. These hold the initial positions of our GameButtons. We then instantiate the

gameButtonArray
to a new Array. Next we loop through the alphabetArray, creating a new GameButton. We Check if i is equal to

8 or 16, and if it is we increment the yPos variable by 65, and reset the xPos variable to 150. We then check if i is equal

to 24, and if it is we increment yPos by 65 and set xPos to 330. This lays out our buttons in a nice grid.

We then create a GameButton and set it’s text to the current letter in the alphabet array by using (alphabetArray[i]) we then

set the button’s .x and .y by using xPos and yPos. We then push the button into the gameButtonArray

add it to the stage and add an EventListener to it.

Last, we increment the xPos by 60 so the next time through the loop the buttons will be staggered instead of on top of each other.



Step 21: checkLetter Function


Enter the following code below the setupGameButtons() you created above.

private function checkLetter(e:MouseEvent):void{
var tempButton:GameButton = e.currentTarget as GameButton;
var theLetter = tempButton.getText().toLowerCase();
trace(theLetter);

}

Here we set up a tempButton, and a theLetter variable which gets the buttons text and converts it to lowerCase. Then we trace theLetter to

the output panel.

Add the following within the public function Main().

public function Main() {
setupGameButtons()
}

Go ahead and test the Movie and you should see the Game Buttons nicely align on the stage, and if you click on them, the correct letter should

be traced to the output panel.



Step 22: Loading in a List of Words


We will be loading in an external .txt file that has the words used in this game, seperated by a newline character.

I downloaded a wordlist from SourceForge and am using the “variant_1-words.95″. I renamed it to

“wordlist.txt”.

Enter the following code below the checkLetter function you created above.

function doRequest():void{
wordList = new Array();
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest("wordlist.txt"));
loader.addEventListener(Event.COMPLETE,wordListLoaded);
}

Here we set wordList to a new Array, set up a URLLoader, load the “wordlist.txt”, and then setup an Event.COMPLETE listener

to the loader.



Step 23: wordListLoaded Function


Add the following below the doRequest function you created in the step above:

function wordListLoaded(e:Event):void{
var tempString:String = e.target.data as String;
trace(tempString);
}

Add the following to public function Main().

public function Main() {
setupGameButtons();
doRequest();
}

Go ahead and test the movie again. You should see the words from “wordlist.txt” traced to the output window.



Step 24: Creating the Guess Word


We will take the original word and replace all the characters with a “?”. However, some of the words contain apostrophes (‘), so we will replace those

where appropriate.

Add the following below the wordListLoaded() function you created in the step above:

function createGuessWord():void{
guessWord = new Array();
var randomWord = Math.floor(Math.random() * wordList.length);
theWord = wordList[randomWord];
trace(theWord);
theWord = theWord.substring(0,theWord.length-1);
for(var i:int = 0; i< theWord.length;i++){
if(theWord.charAt(i) == "'"){
guessWord[i] ="'";
}else{
guessWord[i]="?";
}
}
var newGuessWord = guessWord.join("");
guess_word_text.text = newGuessWord;
}

Since Strings are immutable in AS3, we will store each character in an array and then convert the array into a string. By using an array we can easily

change each individual character.

The first thing we do is set guessWord to a new Array. We then chose a random element from our wordList array and set theWord

equal to the random element from the wordlist, which in turn gives us a random word.

Next we use the substring method to chop off the last character of the word. While testing I noticed the words had an extra space at the end of them. This takes care of that extra space.

We then loop through theWord character by character, check if the current character is an apostrophe(‘), and if it is we set the current index of the guessWord

array to an apostrophe(‘), otherwise we set it to a “?”.

Finally, we create a newGuessWord by using the arrays built in the join method which takes the elements of an array and turns them

into a string. Finally, we set the guess_word_text TextField’s text to the new GuessWord.



Step 25: Reset Game


The resetGame() function is where we will reset all of our game elements for a new game. For now we are just using it create the guessWord and setup our buttons.

Enter the following code below the createGuessWord function you created in the step above.

function resetGame():void{
setupGameButtons();
createGuessWord();
}

Change the code within public function Main() to the following.

public function Main() {
doRequest();
}

Next add the following line to the wordListLoaded function.

function wordListLoaded(e:Event):void{
var tempString:String = e.target.data as String;
wordList = tempString.split("\n");
resetGame();
}

Here we add the words to the wordList array using the Strings built in split() method, passing in “\n” since our words

are separated by newline chracters, then we call the resetGame function we created above.

Go ahead and test the Movie and you should see that guessWord has been replaced by “?” and “‘” where appropriate.



Step 26: Drawing the Hangman Container


Our hangman is dynamically drawn using AS3′s drawing API. The first thing we need to do is draw the container for the hangman. Enter the following code

below the resetGame() function:

private function addHangmanContainer():void{
hangmanContainer = new Sprite();
hangmanContainer.x = 180;
hangmanContainer.y = 180;
hangmanContainer.graphics.lineStyle(3,0x000000);
hangmanContainer.graphics.drawRect(0,0,400,400);
addChild(hangmanContainer);
}

Here we set the hangmanContainer to a new Sprite, set it’s .x and .y properties, and use the drawing

API to set the lineStyle to a 3px black line. Next we draw a rectangle using the drawRect() method and add it to the stage.

Add the following to the resetGame() function:

function resetGame():void{
if(hangmanContainer != null){
removeChild(hangmanContainer);
hangmanContainer = null;
}
addHangmanContainer();
setupGameButtons();
createGuessWord();
}

We first check to make sure hangmanContainer does not equal null. If it does not, then we remove it from the stage and set it to null, then we

use addHangmanContainer to add it to the stage.

Test the movie and you should see the hangman container positioned nicely above the buttons.


Step 27: drawHangman() Function


The drawHangman() function will be used to draw the individual hangman pieces as the game progresses. Enter the following code below the

addHangmanContainer() function:

function drawHangman(drawNum:int):void{
switch(drawNum)
{
case 0:
drawGallows();
break;
case 1:
drawHead();
break;
case 2:
drawBody();
break;
case 3:
drawArm1();
break;
case 4:
drawArm2();
break;
case 5:
drawLeg1();
break;
case 6:
drawLeg2();
break;
}
}

This function will take an int as a parameter and use a switch statement to decide which part of the hangman to draw.


Step 28: drawGallows() Function


The following code uses the drawing API to draw the gallows inside the hangmanContainer sprite. Add the following below the drawHangman() function.

function drawGallows():void{
hangmanContainer.graphics.moveTo(20,380);
hangmanContainer.graphics.lineTo(360,380);
hangmanContainer.graphics.moveTo(290,380);
hangmanContainer.graphics.lineTo(290,50);
hangmanContainer.graphics.lineTo(180,50);
hangmanContainer.graphics.lineTo(180,90);
}


Step 29: drawHead() Function


This code is used to draw the head of the hangman.Add the following code below the drawGallows() function.

function drawHead():void{
hangmanContainer.graphics.drawCircle(180,120,30);

}


Step 30: drawBody() Function


This code draws the body of the hangman. Add the following code belows the drawHead() function:

function drawBody():void{
hangmanContainer.graphics.moveTo(180,150);
hangmanContainer.graphics.lineTo(180,300);
}


Step 31: drawArm Functions


These two functions are used to draw the left and right arms. Add the following functions below the drawBody() function:

function drawArm1():void{
hangmanContainer.graphics.moveTo(180,200);
hangmanContainer.graphics.lineTo(130,190);
}

function drawArm2():void{
hangmanContainer.graphics.moveTo(180,200);
hangmanContainer.graphics.lineTo(230,190)
}


Step 32: drawLeg Functions


These two functions are used to draw the left and right legs. Add the following functions below the drawArm2() function.

function drawLeg1():void{
hangmanContainer.graphics.moveTo(180,300);
hangmanContainer.graphics.lineTo(130,330);
hangmanContainer.graphics.lineTo(120,320);
}

function drawLeg2():void{
hangmanContainer.graphics.moveTo(180,300);
hangmanContainer.graphics.lineTo(230,330);
hangmanContainer.graphics.lineTo(240,320);
}


Step 33: Creating the You Win Movie Clip


Go to Insert > New Symbol. Give it the name YouWin and make sure “Export for ActionScript” is checked and that the class is set to “YouWin”


Select the Text Tool and make sure the following properties are set:

  • Size: 14pt
  • Color: #00FF00


Drag out a TextField into the MovieClip and enter the words “YOU WIN!!” into it.

Next set the following properties on the TextField.

  • X; -49.00
  • Y: -8.00
  • W: 104.00
  • H: 19.00


We need to create a variable to hold our YouWin MovieClip so enter the following at the bottom of your variable declarations:

var youwin:YouWin;


Step 34: Creating the You Lose Movie Clip


Go to Insert > New Symbol. Give it the name YouLose and make sure “Export for ActionScript” is checked and that the class is set to “YouLose”.


Select the Text Tool and make sure the following properties are set.

  • Size: 14pt
  • Color: #FF0000


Drag out a TextField into the MovieClip and enter the words “YOU LOSE!!” into it.

Set the following properties in the TextField

  • X; -49.00
  • Y: -8.00
  • W: 104.00
  • H: 19.00


We need a variable to hold our YouLose MovieClip, so enter the following at the bottom of your variable declaration.

var youlose:YouLose;


Step 35: disableButtons() Function


Add the following code below the drawLeg2() function.

private function disableButtons():void{
for(var i:int = 0;i < gameButtonArray.length;i++){
gameButtonArray[i].disable();
}

}

This code simply loops through the gameButtonArray and disables all the buttons.


Step 36: Finishing checkLetter()


In this step we will finish off the checkLetter() function which is where the heart of the game lies. Enter the following code

inside the checkLetter() function you created earlier.

private function checkLetter(e:MouseEvent):void{
var tempButton:GameButton = e.currentTarget as GameButton;
var theLetter = tempButton.getText().toLowerCase();
var correctGuess:Boolean = false;
var newGuessWord;
tempButton.removeEventListener(MouseEvent.CLICK,checkLetter);
removeChild(tempButton);

for(var i:int =0;i<theWord.length;i++){
if(theWord.charAt(i) == theLetter){
guessWord[i] = theLetter;
correctGuess = true;
}
}
newGuessWord = guessWord.join("");
guess_word_text.text = newGuessWord;

if(!correctGuess){
numWrong++;
drawHangman(numWrong);
}

if(newGuessWord == theWord){
disableButtons();
youwin = new YouWin();
youwin.x = 375;
youwin.y = 400;
addChild(youwin);
TweenLite.to(youwin,3,{scaleX:3,scaleY:3,onComplete:resetTheGame});

}

if(numWrong == 6){
disableButtons();
for( var j:int = 0; j < theWord.length;j++){
guessWord[j] = theWord.charAt(j);
newGuessWord = guessWord.join("");
guess_word_text.text = newGuessWord;
}
youlose = new YouLose();
youlose.x = 375;
youlose.y = 400;
addChild(youlose);
TweenLite.to(youlose,3,{scaleX:3,scaleY:3,onComplete:resetTheGame});

}
}

The tempButton and theLetter variables were explained in the previous steps. The correctGuess variable is set to

false at first, if the user chose a correct letter we set this to true. The newGuessWord is a temporary variable we will use to construct the new word to display.

Next, we remove the EventListener from the button and remove it from the stage.

We loop through theWord character by character and check if the current character in theWord is equal to theLetter, and

if it is, we set the appropriate letter in the guessWord array to theLetter.

We then use the join method of the String Class to turn our guessWord array into a String (newGuessWord), and set the guess_word_text to newGuessWord.

We check if correctGuess is false, and if it is we increment numWrong and call our drawHangman function passing in numWrong.

We then check if newGuessWordM is equal to theWord and if it is, we disable the buttons, instantiate our youwin MovieClip, set its .x

and .y, add it to the stage and call TweenLite to animate it with an onComplete function.

Lastly, we check if numWrong is equal to six and if it is, we loop through theWord and set every letter in the guessWord

array equal to the current character in theWord. We then use join as explained above and show the word. We disable the buttons, instantiate our youLose MovieClip,

add it to the stage and once again call TweenLite to animate with an onComplete function.


Step 37: resetTheGame() Function


The resetTheGame() functions are called when the animations of the youWin and youLose MovieClips are finished. Enter the following code

below the drawLeg2() function:

function resetTheGame():void{
if(youwin!=null){
removeChild(youwin);
youwin = null;
}
if(youlose!=null){
removeChild(youlose);
youlose = null;
}
resetGame();
}

This function checks whether the youWin and youLose are not null, and if they are not we call removeChild to remove

them from the stage and set them to null. Finally we call the resetGame function.

Step 38: Finishing resetGame()


We need to do some final cleanup in the resetGame function. Add the following code to the resetGame() function:

function resetGame():void{
numWrong = 0;
if(gameButtonArray.length>0){
for(var i:int =0;i<gameButtonArray.length;i++){
if(gameButtonArray[i].stage){
removeChild(gameButtonArray[i]);

}
}
}
if(hangmanContainer != null){
removeChild(hangmanContainer);
hangmanContainer = null;
}
addHangmanContainer();
setupGameButtons();
createGuessWord();
drawHangman(numWrong);
}

We first reset numWrong to 0, then we loop through the gameButtonArray, check if the buttons are on the stage, and if they

are we remove them.


Step 39: Adding the WordList


You will need to include the "wordlist.txt" to the included files. So go to the "AIR for IOS" settings and on the "General" tab click on the "+" button

and browse to the "wordlist.txt" adding it to the included files.


This completes our game! The next step is to publish for the App Store, and upload through iTunes Connect.

Step 40: Preparing for the App Store


You will first need to generate a "Distribution" Provisioning Profile. Follow the steps in Step 4 of the first part of the tutorial, but

make sure you are under "Distribution" instead of development.

Next you will need to download the "Distribution" certificate and convert it to a .P12 following the example from Step 5 of the first part of this series.

Then, go back to the "Air For IOS" and under the "DEPLOYMENT" tab, swap out the devlopement .P12 with the distribution .P12, and swap out the devloper provisioning file

with the distributuion profile, make sure you tick off "Deployment - Apple App Store" and click publish.

Lastly, log into iTunes Connect, Go to "Manage Applications" and add a new App, follow the instructions, the upload your app with "App Loader".

Conclusion


This series gave a good introduction to Mobile Development with Flash CS5.5. Hopefully you've learned something useful and thank you for reading! If you want to see more Flash CS 5.5 iOS development content, leave a comment below!

2011年10月19日星期三

Building a Hangman iPad App with Flash – Getting Started

Building a Hangman iPad App with Flash – Getting Started:
This tutorial will teach you how to develop a simple app for the iPad using Flash CS 5.5. In this two-part series, we’ll be building a simple hangman game. After completing this series, you should feel comfortable enough to start developing your own iOS applications with Flash.





Step 1: Generating A CSR


Before we get started actually building our application, let’s take a step back and get the development environment setup. If you’re Flash developer new to iOS development, then you probably have no idea how to test Flash applications on an iOS device. Unfortunately, it isn’t as simple as just clicking “Run”. You’ll first need to create what’s called a CSR, or Certificate Signing Request. You’ll need to upload this CSR to the Apple Provisioning Portal, which means you’ll also need to create an iOS developer account at the official iOS development site. We won’t cover all the steps of setting up an account with the iOS developer program here, but the instructions on Apple’s site are easy to follow. If you aren’t already an iOS development program member, sign up now.

After you’ve registered with Apple as an iOS developer, you’re ready to continue setting up a CSR. Inside your applications folder on a Mac, you’ll find a folder called utilities, and within this folder, there is an application called “Keychain Access”. Open Keychain Access to get started with the certificate generation process.

NOTE: Unfortunately, you will need to be running the latest version of OS X in order to successfully, build, test, and deploy iOS applications, even though you are building them with Flash!

With the Keychain Access program open, choose the following menu options: KeyChain Access > Certificate Assistant > Request A Certificate From A Certificate Authority.


Figure 1

You will need to enter the e-mail address you used to register with apple, and then enter the same name as well. After you’ve filled these in, make sure “Saved To Disk” is selected and press continue. You will need to choose where to save the request. I chose to save it to the desktop.



Now we can upload it to the provisioning portal. Log into the developer center at developer.apple.com and on the left of the page you should see a link to the Provisioning Portal, go ahead and click that link.



Within the Provisioning Portal click on “Certificates” and then on the “Request Certificate” button.



At the bottom of the this page, browse to where you saved the CSR from the previous step, then click on “Submit”.



You will be returned to the previous page. It will say “Pending Issuance” under “Status”. Wait a few seconds, and refresh the page and your certificate should be available for download. Don’t download it just yet, we still have a few steps to go.





Step 2: Registering a Device


Plug in your device and open iTunes. Make sure your device is selected, and you will see some information about it. Click on the Serial Number and it will change to your device ID.





Go to Edit > Copy. This will copy the device UDID to your clipboard.

Back in the Provisioning Portal, click on the menu item “Devices” and then choose “Add Devices”



Enter a name for your device and the “Device ID” you copied in the step above and then click on submit. Your device is now ready.



Step 3: Generating an App ID


Still within the Provision Portal, click on the menu item “App IDs”, then choose “New App ID”.



Enter a name that you want to reference this app by. I chose “MobileTuts Hangman”. Next choose a Bundle Seed ID, choosing “Use Team Id” is most common.


Finally, choose your Bundle Identifier, I chose “com.mobiletuts.hangman”.



When you are finished entering the information click “Submit”.

If all goes well you should see your app enabled.





Step 4: Obtaining a Development Provisioning Profile


Choose the menu item “Provisioning”, then making sure you are under “Development”, choose “New Profile”.



On the next screen, making sure you are under “Development”, enter a “Profile Name” (I chose “MobileTutsHangman”), tick your certificate, choose the App ID you created in the step above, choose the device you are going to test on, and then click submit.



You will be returned to the previous page. The status will say pending, wait a few seconds and refresh the page, and your profile should be ready for downloading. Go ahead and download it now.

Next, go back to the “Certificates” link and you should see “MobileTutsHangman” listed under the “Provisioning Profiles” of your certificate.

Go ahead and download your certificate now, and, while still there, download the “WWDR intermediate certificate” as well.





Step 5: Adding the certificate to KeyChain Access and Creating a .P12


If you don’t have keychain access open, do so now. Then double click on the certificate you downloaded above, add it to keychain access, and double click on the “WWDR intermediate certificate as well”.

Within keychain access, choose certificates and then “twirl down” the certificate you just added, right click on your private key and choose “Export”.



I saved mine to a folder named “MOBILETUTS HANGMAN”. Make sure the type is set to “Personal Information Exhange (.p12)” and click “Save”.



You will be prompted for a password for your .P12, make sure you remember this password, we will need it when we import the .P12 to flash. You will also need to enter the password for your machine after entering this password.





Step 6: Create a New Flash Project


Now that we have set everything up, we are ready to begin our Flash Project.

Go to File > New and Choose “Air For iOS”.

Make sure the following properties are set, then press “OK”.

  • Width: 768
  • Height: 1024
  • Frame Rate: 24
  • Background Color: White



Save this document as Hangman.fla.


Step 7: Creating Main.as


Go to file > new and choose “Actionscript File”.



Save this as “Main.as”, and then enter the following code:

package{

import flash.display.MovieClip;
public class Main extends MovieClip{
public function Main() {
trace("Working");
}

}
}

Set your Document Class to “Main” and test the movie. You should see your Movie open up in the ADL, and see “Working” traced to the output window.



Step 8: Adding A TextField To the Project


Choose the “Text Tool” and make sure the following properties are set under the “CHARACTER” panel.

  • Size: 45pt
  • Color: #0000ff”



Now drag a textfield out onto the stage and enter the following text into it: “MOBILETUTS+ HANGMAN”.

Next, choose the “FILTERS” panel and click on the new filter button and choose “DROP SHADOW”.



Set the following properties on the Drop Shadow.

  • Blur X: 5px
  • Blur Y: 5px
  • Strength: 50%
  • Quality: Low
  • Angle: 45
  • Distance: 5px



Finally, set the following properties on the TextField:

  • X: 76.00
  • Y: 26.00
  • W: 561.00
  • H: 56.00

Lastly, make sure the textfield is set to “Classic Text” and “Static Text”.



Step 9: Setting the iOS Preferences and Building the App


Click on the Main Stage. Under “PUBLISH”, select the Air For iOS option.



Under the “General Tab”, Fill in the “Output File”,”App name”, and “Version”. I chose “MobileTutsHangman.ipa”, “MobileTuts Hangman”, and “1.0″ for the version. Next, select “Portrait” for the Aspect Ratio, tick off the Full screen, choose “Auto” for rendering, “iPad” for the Device, and “Standard” for the Resolution.



Switch over to the “Deployment” tab. Browse for the .P12 file you created in the steps above, enter the password you made for it, and tick off “Remember password for this session”. Next, browse for the provisioning profile you downloaded and add it.



Tick off “Quick publishing for device testing” and finally click “Publish”. It can take a few minutes to build your app.



Step 10: Uploading the “Provisioning Profile to iTunes”


To be able to test on the device, you must first put the Provisioning Profile onto it.

Go to the folder where you saved the Provisioning Profile and drag it into the iTunes “Library”. Next select your device under “Devices” and click on sync.



If you go to “Settings” on your IPad and select “General”, You should see a “Profiles” Menu. Click it and you should see that your profile has been installed.



Step 11: Installing the App onto the iPad


Now that we have compiled the app and installed the Provisioning Profile, we can upload it to the iPad and test it to make sure everything has gone as planned so far.

Drag the .ipa file that was created when you published the application into the “LIBRARY” section for your iPad in iTunes, and then choose “Sync”.

If all goes well you should be able to start the app and see the the text we added to the App.



Step 12: Creating the Default Image


We now have the app on our iPad, but it is blank when it starts up. In this step we will make the default graphic that will show while the app is loading.

I have included a file called Default-Portrait.png in the exercise files. You will need to make sure this is in the same folder as your .fla, and not in any subdirectories or it will not work. This image needs to be 768*1004 as per the instructions on the adobe site.

Back in Flash, go to the “Air For iOS” setting as you did in the steps above.

On the “General” tab, make sure all the settings are the same and click on the “Add” (+) button, browse to “Default-Portrait.png”, and then add it to the “Included Files”.





Step 13: Adding the Icons


The icons are used for the iPad itself as well as for the App Store. Go to the “Air For iOS” settings and click on the “Icons” tab. You must supply the icons in the sizes stated in this panel. I have included the icons in the “icon” folder of the download files. They are named icon(size).png, where size is the graphic size. Go through the icon sizes and browse to the respective icons.



Step 14: Republish the App


Make sure all the settings are the same on the “General” and “Deployment” tabs and click “Publish”. Then add the .ipa file to iTunes, make sure you

delete the previous version off your iPad first, and then finally resync the ipa file with the iPad.

You should now see the app has a picture associated with it and the “Splash Screen” shows when you first start up the app.



Conclusion


With all of the “hard” stuff out of the way, we can begin programming our hangman game. Be looking for the next part of this tutorial to do just that. And thanks for reading!