navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Flash Professional CS5: Creating a Simple Game for iOS Devices

Flash Professional CS5: Creating a Simple Game for iOS Devices

with Todd Perkins

 


In this course, Todd Perkins shows how to use Flash Professional CS5 to create a game to play on iOS devices, utilizing device hardware like the accelerometer and integration with a local database. The course covers the game development from start to finish, including planning and preparation, character and background animation, creating interactions and scoring mechanism, and finally testing and publishing the app. Exercise files are included with the course.
Topics include:
  • Optimizing assets
  • Planning game play and viewing class structure
  • Making the character move and jump
  • Adding sound effects
  • Adding accelerometer support
  • Creating reusable classes
  • Looping background animations
  • Detecting collisions
  • Using a timer
  • Increasing scrolling speed
  • Acquiring testing certificates and provisioning profiles
  • Troubleshooting performance issues
  • Submitting to the App Store

show more

author
Todd Perkins
subject
Developer, Web, Games, Projects
software
Flash Professional CS5, iOS
level
Intermediate
duration
2h 8m
released
Feb 25, 2011

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:03Hi! I am Todd Perkins.
00:05Welcome to Flash Professional CS5: Creating a Simple Game for iOS Devices.
00:11If you're familiar with Flash and ActionScript and watched develop iOS games
00:15using what you already know, this course is right for you.
00:18We will start by looking at the finished version of the game, which you can
00:22download from the App Store.
00:24You will see how the game's source files are organized and get a top-level view of
00:28developing iOS games using Flash.
00:31From there, we will begin creating the game.
00:33We will animate the skateboarder and add support to control him using the
00:37device's accelerometer.
00:39After that we'll look at how to detect swipe gestures and add sound effects.
00:43We will finish the game by adding parallax scrolling to the background,
00:48collision detection, and scoring.
00:50We will even look at how to save high scores to the device.
00:54By the time we are finished with this course you will have seen just about
00:58everything Flash has to help you create iOS applications and will have built a
01:02real world game as well.
Collapse this transcript
Using the exercise files
00:00If you are a Premium subscriber to lynda.com or have purchased this title on a disc,
00:05then you have access to the exercise files for this course.
00:09Exercise files are organized by chapters.
00:13Each chapter contains folders with all the files that we'll be using
00:17throughout that chapter.
00:20Whenever we edit a file in a movie, I save the final version inside of the Final folder.
00:27For example, in Chapter 2 there is a folder called character_move.
00:32In there, you'll find the start version and the final version of the files.
00:37The final versions are the versions that I saved out after recording the movie.
00:43So if you have any problems, you can check the code in the final versions
00:46to confirm everything.
00:48The only place in the scores where I didn't include all the Exercise Files I
00:56used is inside of the Submitting folder in Chapter 5.
01:01I didn't include the finished version of the application, because that is an
01:05application only I can submit to Apple.
01:08You can test this application on your devices, but I don't want you to send
01:12this game to Apple.
01:14So that's why I didn't include the final files that I sent to Apple inside of that folder.
01:20Other than that you'll have every file I worked with throughout the entire course.
01:25If you don't have access to the Exercise Files, don't worry.
01:28You could still follow along.
01:29I'll show you how my FLA file is set up, how my classes are organized, and all
01:36the code that you'll need to write to create the same kind of application.
01:40Now that you have an idea of how the Exercise Files for this course are
01:44organized we will start making the game.
Collapse this transcript
1. Planning and Preparing the Game
Reviewing the finished game
00:00Before starting your game it's good to have an idea of what the finished
00:04product should look like.
00:05To see the finished version of the game that we are going to build in this course,
00:09go to the App Store and search for SK8Bit, all one word.
00:17You can download this on your iOS device and play the game to see how it works.
00:22If you don't have an iOS device to test on, you can actually even test this in Flash.
00:27I have the FLA file open here and I could test the movie to preview the game.
00:33(Music playing)
00:35So here's the title screen.
00:37You can click the bottom-right icon to view controls for the game, and you can
00:46click anywhere else to start playing the game.
00:49When you're playing the game you could swipe up to jump and you can move the
00:52mouse back-and-forth to move the skateboarder.
00:57The goal of the game is to jump over the trash cans.
01:00If you're testing this on iOS device, you can actually move him by tilting the
01:05device like you're driving a car.
01:08Notice we have a score and a high score and that data gets saved to the
01:12computer if you're playing on a computer or to your device if you're playing on an iOS device.
01:19If you jump over 10 trash cans, the game speeds up a little bit.
01:24And when you fall, you see the falling animation and the game starts over.
01:29One thing to note is if you've updated Flash to the latest version, it might not
01:34test properly in Landscape mode.
01:37You can fix that through the Properties panel.
01:39You may notice that my panels are organized somewhat differently because I'm
01:43working on a lower resolution screen than I normally work on, so you can
01:47obviously expand or contract the panels however you want.
01:51But here's my Properties panel right here and I'll click the iPhone OS Settings
01:56Edit button and then there you could check Auto orientation.
02:00Now, you don't want this checked when you publish your app or else when you tilt
02:05your device it'll auto orient and change from Portrait to Landscape and you
02:09definitely don't want that to happen.
02:11So just for testing in Flash, if you're having trouble, you can check the Auto
02:16orientation box and then click OK.
02:21And when you test the movie, click on another application like Finder for
02:30example and then click the ADL app, which is the iOS emulator.
02:37And then in there you can go to Device and rotate left and rotate right, and you
02:42could see that it auto orients.
02:46So again that's only if you're having problems.
02:51In here I am just going to uncheck that and I'll click OK.
02:56So if you're having problems with the orientation of the app, follow those steps
03:02and while you're testing you could auto orient in the Emulator.
03:06When you finally publish your app, and obviously you don't want to publish my
03:10game here, SK8Bit. You publish your own game.
03:13You want to uncheck Auto orient if you don't want the device orientation to
03:17rotate as you rotate the device.
03:20Let's look at the finished version of our game.
03:23So now as you organize the art and write the code for this game, you'll have a
03:28better understanding of where the application is going.
Collapse this transcript
Optimizing assets
00:00It would be wonderful if it were possible to make high-end iOS games through Flash.
00:05However, in creating this game, I learned that Flash has some limitations when
00:10publishing content for iOS.
00:12I also learned a lot of optimization techniques that helped me develop the game
00:17and improve its performance.
00:19The official FAQ for the Flash Packager for iPhone can be found on the
00:24Adobe Labs web site.
00:26The URL is labs.adobe.com/wiki/index.php /applications_for_iPhone:developer_FAQ.
00:40It's probably easiest to find this if you just go to labs.adobe.com and do a
00:46search for iPhone FAQ.
00:48Here you can find information about how to set up your apps to get the best
00:54performance out of Flash.
00:56I'm not going to go over all of these tips right now, but there are few things
01:00that you should know.
01:01SK8Bit really pushes the limits of iOS applications created by Flash.
01:08I tested it on an iPhone 3GS and an iPhone 4 and their performance was pretty solid.
01:14However, after I released the game I heard from people that had older devices
01:20that said the performance was lacking.
01:22So ideally if you're going to create an iOS game with Flash you would create
01:27more of a puzzle type of game than an action game.
01:31So something that requires less animation.
01:33Through this FAQ and other FAQs from people that work at Adobe I learned that
01:40the best way to set up my artwork was to use bitmap graphics rather than vector graphics.
01:46So I chose bitmaps in my app.
01:49You'll also find that using things like alpha and blend modes and filters will
01:55decrease the performance of your applications.
01:57So I suggest reading through this FAQ to become familiar with all the nuances of
02:03publishing iOS applications through Flash.
02:06So for the most part, Flash works best for creating iOS games with small amounts
02:11of animation and other activity.
02:14In general, you are going to get better performance when you use bitmap graphics
02:18rather than vector graphics.
Collapse this transcript
Planning gameplay and viewing class structure
00:00Typically, it is a bad practice to start building an app without a proper plan
00:05regarding how the code will be organized.
00:07Because this code is already written, I can show you how it's organized and you
00:13can have a good top-level understanding of how the application is going to work.
00:19This application is organized using object-oriented programming.
00:24If you're unfamiliar with object- oriented programming, check out my course on it
00:29in the Online Training Library.
00:31In the main folder that contains my FLA file I have a folder called com.
00:37If I expand the com folder you will see that I have a folder called toddperkins
00:42and a folder called sk8bit inside of the toddperkins folder.
00:46This is the package for my classes.
00:50If you're unfamiliar with package, please watch the object-oriented course.
00:54So I have the Boarder class, the Game class, the Mover class, the Obstacle
00:58class, and the Sk8bit class.
01:01Let's take a look at these classes and see what code is written and we will
01:05discuss how they're going to work together.
01:09In the FLA file you could see in the Properties panel that my class is set to
01:14com.toddperkins.sk8bit.Sk8bit.
01:19So that is the Document class.
01:21Let's look at the code in that class.
01:23Now it looks like there is a lot of code here, but what's happening is
01:29actually relatively simple.
01:31So I have my package declaration, which I'm going to have in all my classes,
01:35and my import statements and I'm extending the MovieClip class. I have some
01:41properties like the Game object, which is an instance of the Game class which
01:46is going to be the main game functionality for the application, and some
01:52properties to control sound.
01:56In the constructor, I play the sound, wait for a mouse click.
02:01The great thing about Flash to iOS applications is that you don't have to
02:05listen for touch events. You can actually just listen for mouse events and they work just fine.
02:10So Flash translates them for you and you don't have to do any of that work.
02:14This makes it very easy for testing the application directly in Flash.
02:18So then I have the startGame method.
02:22The first thing we do is check to see if the object touch was now at
02:26the Controls button.
02:27That's a little button on the bottom-right that shows how the controls of the game work.
02:33If it's not that button, then we remove the MouseEvent.CLICK EventListener, stop
02:39the sounds, and play the background music.
02:42You'll see that this code is commented out and that's because I'm doing a lot
02:46of talking while the game is playing and I don't want to have to compete with
02:52the background music while I'm talking.
02:54So I'll uncomment this when we publish the game.
02:58So I create a new instance of the game class and add it to the Stage.
03:03If the Controls button was touched, then I add it to the stage in front of
03:08everything else, set its visible property to true, and play the movie clip.
03:13We will talk more about controls_mc in another movie.
03:18Then I have the gameOver method.
03:20That's a public method that runs when the game is over, so after the player bails.
03:28Let's go to Game.as.
03:30Now here I don't really have any code other than my import statements.
03:34So just a generic class definition.
03:38The Boarder class is pretty much the same thing except for in the constructor I
03:42add in an event listener to check for the ADDED_TO_STAGE event, and then I run
03:46the allLoaded method.
03:48Now, when we write the code for this we're actually going to write it inside of
03:51the allLoaded method rather than in the constructor.
03:53Now the reason that I did this is because sometimes when you're working with
03:58timeline code and timeline objects and object-oriented code, sometimes the class
04:04file starts running before the objects are on the stage.
04:07So you can't communicate with them.
04:09This way I make sure that all of the objects I need to communicate with are
04:13already on the stage before I start running my code.
04:16So it's good practice.
04:19Mover.as is just a basic skeleton of a class that extends the MovieClip class
04:25and Obstacle class follows the same convention that I followed for the Boarder
04:29class with the ADDED_TO_STAGE event and then I have a method called Update.
04:33Obstacle class is obviously going to apply to the obstacles in the application,
04:38the Mover class is going to apply to the background parallax scrolling elements,
04:44and the border class is going to apply to the skateboarder.
04:47Now, when I organize this application I wanted to have all the code in classes,
04:52but there are some cases where it's better to have the code in the Timeline.
04:56In particular, things like stop actions and actions that need to happen after an
05:02animation is occurred need to be inside of a timeline and will not work the same
05:07inside of a class file.
05:09Again, we'll look at the FLA in detail in another movie.
05:12But I just want you to know that ideally object-oriented code is the best way to
05:17organize your applications, but sometimes it's necessary to put certain actions
05:24inside of Timelines.
05:26Now that you have a better idea of how the application is set up and how the
05:29different classes are going to work together, it'll make more sense as we're
05:33writing the code for the application and will be easier to understand how the
05:37code works together.
Collapse this transcript
Viewing the FLA file
00:00In the same way that organized code is important, organized structure of your
00:05FLA can make your app easier to manage down the road.
00:09So let's take a look at how this FLA file is organized.
00:13On the main Timeline I have three layers. There is controls_btn which is the
00:20button that you click to open up the controls movie clip or to bring it to the
00:24front and display it.
00:26And there is the bg, which is the main background graphic, and that's not really
00:32anything special. It's a movie clip that has a bitmap inside of it.
00:37And then if you hide that you can see controls, which is an instance of controls_mc.
00:45Let's double-click that movie clip to enter its Timeline.
00:49In the Timeline of the controls movie clip, you can see that there is
00:52ActionScript on the first frame of the actions layer.
00:56If I select that it open up the Actions panel using Option+F9 on the Mac or F9
01:01on the PC, you can see that I have a stop action and a visible = false.
01:07Now since this code is on the first frame I could have written it inside of a
01:13class file, but there are only two lines of code and I want these two lines to
01:18run again after the movie clip plays in its entirety.
01:21So in this case it's better to have the code on the Timeline.
01:26So this is just a simple animation of the controls of the game.
01:31Now I made a point not to use any alpha or blend modes or filters here. That way
01:39the game has better performance.
01:42So let's go back to the main Timeline and then we'll go into the game movie clip.
01:47I go to the Library and I'll double-click Game. Note that it's already
01:53exported for ActionScript.
01:56The class is com.toddperkins.sk8bit.game class that we looked at in a previous movie.
02:05So I'll double-click Game to enter its Timeline.
02:08Now here we have a lot of layers so I'll expand the Timeline a little bit so we
02:13could see them all and pan around a little bit.
02:18At the top there is a movie clip called updateSpeed. This movie clip is
02:24actually hidden right now.
02:26So if I double-click it's really hard to see, but the easiest way would be to
02:32just lock the score layer and then do a Command+A or Ctrl+A to select all and
02:37in the Properties panel you can see that it's called speedUp. So you could
02:40double-click it to enter it's Timeline or you can just double-click the
02:43transformation point on the stage.
02:46Now here I used a motion tween to have the movie clip play and move upwards.
02:55On the first keyframe of the actions layer there is a simple stop action.
03:00Notice there is no art on the first frame, so it's invisible until we play the
03:05movie clip and it just simply plays the animation, loops back to frame one and
03:10stops where there is no art on stage.
03:12Back to the Game movie clip.
03:16The score layer has text fields for the score and high score objects.
03:23If you select the number text that says 0 right after the word score,
03:28you can see that its instance name is score_txt and the number next to high score is high_txt.
03:39On the stage I have a mask that masks out everything except for the part of the
03:45stage that is on the Timeline.
03:49So if I hide the mask you can see there is much more content, so the background
03:54extends a little bit.
03:57If I unlock the Boarder layer you can see that's an instance of a movie clip called
04:01Boarder and the instance name is boarder_mc.
04:06Let's double-click that to enter it's Timeline.
04:08Now here I have a motion tween of the skateboarder falling down and on the first
04:14keyframe of the actions layer I have a simple stop action.
04:17And you can drag the playhead to see the animation and at the end of the
04:25animation I have another action. I am stopping the Timeline and then I make
04:32a call to this.parent.parent, which is going to be the document class, or sk8bit.gameOver.
04:38So it's going to call that gameOver method.
04:45Go back to the Game movie clip, lock Boarder, and unlock Trash Can.
04:52You could see that there are some trashcans at the bottom right of the stage right there.
04:57Two trashcans. If you double-click the trashcan you can enter its Timeline and
05:02at the top you'll see the can, which is just a bitmap graphic, and underneath
05:06the can is a hit area movie clip.
05:09I made a custom hit area for the trashcan to make the game a little bit easier
05:13and that's called hit_mc.
05:16Back to the Game movie clip. And then the other significant things are the
05:23background in the far back layers.
05:25So unlock them and I will just click on this building here and that's selects
05:30the background, which is called bg_mc. This is just a bitmap graphic
05:35encapsulated in a movie clip.
05:37And then I have a buffer movie clip next to it which is just a copy and I named that bg2_mc.
05:44And then in the far background where the building silhouettes are, I have a
05:51movie clip called farback_mc and then another one called farback2_mc, which is
05:57also going to serve as a buffer so we can have an infinite loop of the
06:00background elements.
06:01Now these are all of the elements that we're going to be working with.
06:06I know that there are other layers inside of here, but they are just cosmetic
06:11things and don't really hold too much relevance in what we're doing.
06:14So we have like these things like the Sign layer, which you can find if you scroll around.
06:22And this is just an unused object and then we have the all the way back layer,
06:33which is just a gray background.
06:34So really nothing super impressive there.
06:39So those are all the movie clips that we're going to be working with and if
06:43you look in the Library you'll see a few more things. I embedded the Arial font.
06:47So you'll see that those high score and score text fields have an embedded
06:51font so I made that.
06:53And I've imported the sounds and bitmaps I'm using for the application.
06:57So there is the BailSound, the BGLoop, and the JumpSound.
07:02So that is how the FLA is organized.
07:05There is the main Timeline that has the main menu of the game and then the game
07:10movie clip which contains all of the gameplay assets.
07:16Now for those of you who don't have the exercise files, you can create a new
07:20Flash iOS document by going to File > New and choosing iPhone OS.
07:28You could also change your publishing target in your publish settings.
07:32Your document size should be 480x320 and other than that it's going to work just
07:39like any other application and the code is going to be the same as the
07:42code we write for rest of this course.
07:44So to recap, your FLA file should be organized in a logical structure,
07:49primarily using movie clips.
Collapse this transcript
2. Controlling Character Movement
Making the character move
00:00We'll start the game by controlling the characters movement.
00:03I'm going to add all that functionality inside of the boarder class.
00:07So before I write the code I'm going to connect the skateboarder to that class.
00:12So let's go to the Library and then right-click the Boarder movie clip
00:17and choose Properties.
00:18Check the box that says Export for ActionScript. You might have to click the
00:22Advanced button to expand that area so that you can see it.
00:26And right before Boarder in the Class field I'm going to type the full package name.
00:31So com.toddperkins.sk8bit. Boarder and then click OK.
00:40And you shouldn't see any warning messages and if you do you should check your
00:43folder structure and the way that you spell the package name when you're
00:48exporting the class for ActionScript.
00:51So I'll close that window and jump over to Boarder.as. In here I'm going to add
00:57a couple properties.
00:58I'll create one public property called speed, datatype it to a Number, and set it equal to 0.
01:06This is going to represent the speed of the skateboarder.
01:09Create another property called movePower.
01:12movePower is also going to be a Number and we'll give it a value of 20.
01:17This is going to apply to the sensitivity of the accelerometer or the mouse
01:22when the player moves left and right.
01:23So you can change this if you want it to be more or less sensitive.
01:28Scroll down to the allLoaded method.
01:30In here type addEventListener, capital E capital L, and the events going to be
01:36Event.ENTER_FRAME. Event has a E and ENTER_FRAME is all caps with an underscore
01:43in-between, and we'll run a method called update.
01:46Now you want to make sure that you've imported the right Event class, so that
01:50you won't get an error when your code runs.
01:52You can see that I've imported it at the top of my code.
01:55So let's create an update method. I'll make it private.
01:59Make sure to receive that event object with the datatype of Event. :void for no return data.
02:07And inhere we're going to update the X position of the skateboarder based on
02:12the speed property.
02:14So type x += speed.
02:18Now we set speed =0 on line 12 here, so the character is not going to move just yet.
02:24We'll go to the next line and we'll write the code to move the character based
02:29on the mouse position.
02:31Now when our game is published we want the character to move based on
02:34the accelerometer data.
02:36However, we're going to be doing all the testing of our application or at
02:40least most of it on a computer with Flash so we won't have access to our device's accelerometer.
02:47So for now we're going to set the speed of the player based on the mouse position.
02:52It's going to get the data based on the distance of the mouse from the center of the stage.
02:57So type speed = and then in the parentheses type stage.mouseX
03:06- stage.stageWidth/2.
03:12So the distance of the mouse from the center of the stage.
03:18We're going to divide that by the movePower property.
03:23Again you can adjust the value of movePower if you want to control the
03:26sensitivity of the mouse here.
03:29So let's save the file and test out the game.
03:32(Music playing)
03:38So you can move the mouse left and right and the player moves forward and backward.
03:46Nice! Now one thing we're going to add is a buffer area so the player can go off the screen.
03:52So let's look at how to do that.
03:54Create a public property. We'll call this bufferDistance.
04:00So bufferDistance with the capital D set that to a Number and we'll set it = 30.
04:08And this will be the distance of the player can be from the edge of the stage.
04:11So 30 pixels from the left or the right edge of the stage.
04:15Now let's write the code to update the player's movement accordingly.
04:19So right below that last line of code that we wrote inside of the Update method
04:23I'll go down a couple lines and create an if statement.
04:28We'll check to see if x is less than bufferDistance.
04:34If so we'll set x = bufferDistance.
04:37And so it's the left edge of the stage based on the buffer value.
04:42So to align the left edge since there is top left alignment for the character.
04:47We'll align that with that bufferDistance property setting a 30 pixels from the
04:52left edge of the stage.
04:54Go right below that if statement we create another if statement and in there
04:59we're going to check to see if x is greater than stage.stageWidth.
05:04It's the whole width of the stage, minus width, that's the width of the player, minus bufferDistance.
05:13So if the player is more than 30 pixels from the right edge of the stage and
05:19we're just set his position equal to that.
05:22So copy and paste all the code inside of that if statement at a semicolon at the
05:27end and change the greater than sign to an equal sign.
05:32Now we'll save the file and then test the movie again.
05:38This time the player should stop at the left and right edges of the stage.
05:43Now just like the movePower property you can adjust the value of bufferDistance
05:50to control the distance of the player from the edge of the stage.
05:52So now we've setup some of the basic functionality for our game and the
05:57player moves left and right based on the distance of the mouse from the
06:01center of the stage.
Collapse this transcript
Adding accelerometer support
00:00One of the great things about using Flash for iOS games is that you get easy
00:05access to some hardware features like accelerometer data.
00:09To access the accelerometer, make sure you first import the Accelerometer class,
00:13which is in the flash.sensors package, and then create a property to
00:18hold the accelerometer.
00:19So I am going to create a public property called acc, short for accelerometer,
00:24data type it to Accelerometer.
00:27In the constructor method I'll create a new accelerometer by typing acc = new Accelerometer.
00:38Note that you type this just like creating a new instance of any object.
00:42In the allLoaded function, right above addEventListener(Event.ENTER_FRAME, type
00:48acc.addEventListener and the event is going to be AccelerometerEvent.UPDATE.
00:55Keep in mind you are following a standard naming conventions here. Accelerometer
00:59has a capital A, Event has a capital E, and UPDATE is in all caps.
01:03The method that will run is called updateSpeed.
01:08Right below the Update method, we will define updateSpeed.
01:12So private function updateSpeed.
01:18And in the parenthesis we will receive that event object, which is going to be
01:22an AccelerometerEvent, :void for no return data, and some curly braces.
01:29So in updateSpeed, I'm going to set the value of speed based on
01:34the accelerometer data.
01:35So speed = movePower * event.accelerationX.
01:48That's the horizontal acceleration of the device.
01:53That's going to be like you are steering a car steering wheel.
01:57So if we are holding the device in landscape orientation, imagine it being a
02:01steering wheel and that's accelerationX.
02:03If you want more information about the Accelerometer class, you can always look
02:08up Accelerometer in Flash Help, but for now just note that this functionality
02:14is going to be pretty much the same as our speed is right now in the Update function.
02:20So it's going to be a positive or negative value based on the tilt of the device.
02:25And again, you can always adjust that movePower property if you find that is too sensitive.
02:30Now we don't want to have these two speed settings conflicting.
02:35So we are setting the speed on the ENTER_FRAME event and in the
02:39Accelerometer event.
02:40So what we want to do is make sure that speed is only set in the Update method
02:45if the accelerometer is enabled.
02:47So to check that right above speed = stage.mouseX in the update function
02:54create an if statement.
02:55In the parentheses, check to see if the accelerometer is enabled by typing acc.muted.
03:04The muted property checks to see if the accelerometer is disabled.
03:09So since my computer doesn't have an accelerometer, it's going to get speed from here.
03:14Of course, I first have to wrap this in some curly braces like so, and now I'm
03:20only going to set the speed in the Update method when I am testing the
03:24application on my computer.
03:26When I test it on an actual device, however, the speed will come from the
03:30updateSpeed method, which is set through the Accelerometer data.
03:36So if we save the file and test the movie now, it should still work just the same.
03:40So I can move the mouse and the player moves.
03:49Now I'm not going to test this on a device just yet, but rest assured if you did
03:53test it on a device right now, it would work just the same except for the
03:57accelerometer data would control the player's movement, and not the mouse.
04:01You will be able to see that in an action later on in this course when we put
04:05this app on a device and test it.
04:08But for now, just to remember that you can access the accelerometer data to do
04:13things like set the speed of a player through one simple line of code.
Collapse this transcript
Making the character jump
00:00The next step in creating the character is making him jump.
00:04Again, we will add all that functionality to the Boarder class.
00:08We'll start by creating a few properties.
00:10Right below where you create the Accelerometer property, create another property
00:15called speedY, data type that to a Number, and set the value equal to zero.
00:21Create another property called groundY:Number, also = 0.
00:29Create another property called gravity.
00:32That'll be a Number and we'll set it = 1.5.
00:37This is going to represent well gravity, and speedY is going to represent the
00:42vertical speed and groundY is going to represent the position of the ground.
00:47So we can detect that when the character jumps.
00:49On the next line we are going to create an object so we can dispatch an event
00:54when the character lands.
00:55So public static const.
01:01This is a value that can't change and it's static, so it's actually attached to
01:05the class and not the instance.
01:10So we access it by class name.property and not instance name.property.
01:16So here we are going to type LANDED, all caps, datay type it to a String and we
01:22will set it = landed, all lowercase.
01:26We can use this value to dispatch an event later on if we want to.
01:29Finally, we will create one more property also public and we will call this
01:35jumpPower, data type it to a Number, and set the value equal to 20.
01:40Now this represents the force being applied to the character when he jumps.
01:45So if you change the number, you can make him have a higher jump or a lower jump.
01:50Now scroll down to the allLoaded method.
01:54Right above acc.addEventListener, I'm going to say groundY = y. So we are
02:03setting the groundY property's value to the current position of the player.
02:06So that represents the ground.
02:08Keep in mind you don't want to put this in the constructor because it's possible
02:12that the code may run before the object gets added to the stage and then you
02:16have the problem that you're trying to modify a property that doesn't yet exist.
02:20So it's best to have it inside of the added to stage handler.
02:24So go to the next line and type stage.addEventListener and the event is going to
02:30be MouseEvent.MOUSE_DOWN and this is what we are going to do to handle the jump.
02:37So we will create a method, so type Comma and then space, and type touchStarted.
02:45Now notice event is MOUSE_DOWN but I'm calling the function touchStarted.
02:51Flash actually converts mouse events to touch events when you export the device to iOS.
02:57So you actually don't have to add any additional code to support touches.
03:03So let's define the touchStarted method. Scroll down below updateSpeed and
03:09create a private method called touchStarted.
03:13Make sure to make it receive an event object with the data type of
03:17MouseEvent, :void for no return data, and some curly braces.
03:23In here we will run a method called jump.
03:26So just type jump and some parentheses and Semicolon.
03:30Right below touchStarted we will define the jump method.
03:33No parameters, no return data.
03:36In the jump method we want to make the player jump; however, we do not want to
03:41make the player jump all the time.
03:44We only want the player to jump, if he is on the ground.
03:47So the first thing we are going to do is check to see if the player is on the ground.
03:51Let's type an if statement and inside of the parentheses check to see if the
03:57player's Y position is equal to, that's two equal signs, groundY.
04:03If so, then we can make the player jump by setting speedy, make sure you
04:09capitalize the Y, = -jumpPower.
04:13Remember the value is negative because we want the player to move upward.
04:18So negative values in Flash move things up and positive values move them down.
04:22So we set the speedY property, and then we are going to need to change the
04:27update method to support the vertical movement.
04:30So scroll up to the update method.
04:33Right below where you set the x value in there, create a new line and set the Y
04:38value by typing Y += speedY.
04:44Let's save the file and test the movie to see what we have so far.
04:48(Music Playing)
04:52So you should be able to click and see the character jump.
04:54Notice that he just flies off the string.
04:57That's because we haven't yet applied gravity.
05:00So, let's take a look at how to do that.
05:02Right below the code where I check to see if the accelerometer is muted, I'm going
05:07to add a line of code that applies gravity.
05:10So I am going to type speedY += gravity.
05:17So we are going to apply gravity to the character now.
05:21Save the file, and test the application again to watch gravity be applied.
05:26(Music Playing)
05:28Notice that the character just falls straight down.
05:31So we need to control it so that the character does not go below the ground.
05:36To do that, right below the line of code we just wrote, create a
05:40conditional statement.
05:41So type if, some parentheses, and some curly braces.
05:44There we are going to check to see if the character's Y position is greater than groundY.
05:51So if y > groundY.
05:57So if the player is below where it should be on the ground, then what we are
06:01going to do is set y = groundY.
06:04So the player can't go below the ground.
06:06So now let's save the file again, and test it in the Flash Player.
06:11(Music Playing)
06:15So I can click to jump and he doesn't go below the ground.
06:21If I click a whole bunch of times, you'll notice that he doesn't jump when I click.
06:25He just only jumps when he is on the ground.
06:29And here you can actually dispatch an event for when the player lands.
06:33I am not going to write that code right now, but I'll just make a mental note of
06:37that if you ever wanted to track that for something else.
06:41So remember, to make the character jump you apply a gravitational force and you
06:46update the character's Y velocity.
06:48To keep him on the ground, you store the ground position in a property and set
06:53the character at that position if he goes below it.
Collapse this transcript
Simulating a finger swipe
00:00When you publish your game to iOS, Flash will translate the mouse data to touches.
00:05This makes it easy to create support for gestures in your apps.
00:08So now what we will do is finish the jump animation by adding support for
00:13a swipe up gesture.
00:15We'll also complete all the rest of the code to make the jump work perfectly.
00:20So we'll scroll down and right below jumpPower, we'll create a few properties.
00:26First we will create one called currentTouchY, capital T, capital Y.
00:32That's going to be a number which will initialize to 0 right here.
00:35That's going to hold wherever the person touches their finger or mouse down when
00:41they start to do the swipe motion.
00:42So create another public property, we'll call this one isJumping, with a capital
00:48J. Datatype it to a Boolean and that's it.
00:52isJumping will represent whether the player is jumping.
00:56So it will be true while the player is doing the jump motion and once the player
01:00lands, it will be false again.
01:02So let's scroll down in our code and find the touchStarted method.
01:08Here we are going to delete the call to the Jump method, because we don't
01:12want to call that method until the swipe is complete, which is going to be
01:16when the touch has ended.
01:17So let's just copy this method right here and paste it a few lines below and
01:23change touchStarted to touchEnded.
01:27In touchStarted, we will set currentTouchY equal to the position of the mouse or touch.
01:34So currentTouchY =.
01:38We can access the Y position with the touch through our eventObject.
01:41The mouse event has a property called stageY.
01:45So type event.stageY and that's it.
01:49So we are capturing that value right there and we can compare it against
01:53where the touch ends.
01:55The next step is to remove this event listener for the touchStarted event.
01:59So scroll up in your code and find the line where we add that event listener.
02:04It's inside of the allLoaded method.
02:06So stage.addEventListener MouseEvent.MOUSE_DOWN.
02:10So copy that line of code with Ctrl+C or Command+C and scroll down to
02:16touchStarted and paste the code right under the currentTouchY line of code.
02:21In the pasted code, change addEventListener to removeEventListener.
02:25Go to the next line and paste the same code again.
02:29In the pasted code, change MOUSE_DOWN to MOUSE_UP, make sure it's all caps, and
02:36change touchStarted to touchEnded.
02:38So we are going to add the event listener for the MOUSE_UP event only after touch starts.
02:46So select the line of code you just wrote, copy that and we will paste it inside
02:51of touchEnded in just a second.
02:53First we are going to create a conditional statement.
02:55So type if, some parenthesis, and some curly braces.
03:00Paste the code inside if the curly braces.
03:03In the pasted code, change addEventListener to removeEventListener.
03:08So should say stage. removeEventListener(MouseEvent.MOUSE_UP, touchEnded).
03:13In the parentheses for the if statement, we are going to check to see if
03:17event.stageY < currentTouchY.
03:23So if the mouse or finger is above the location that it was at when it started
03:31the touch, then we are going to make the character jump.
03:35So the first thing we will do is remove this event listener and right below the
03:38line where you've removed the event listener, we'll call the jump method.
03:42Now we will scroll down and edit the jump method.
03:46The first thing you are going to do is check to see if the character is on the ground.
03:50So we already have that code written here, if(y == groundY).
03:54After that, type a space and two ampersands.
03:58Then we want to make sure that the character is not already jumping.
04:01So type in exclamation point for the Not operator, then type isJumping.
04:06So we are going to leave speedY = -jumpPower and then on the next line, we will
04:11set isJumping = true.
04:15Now before we test the movie, let's add a little bit more code to the Update method.
04:21Find the Update method and then find the section that says if(y > groundY).
04:28Inside of that conditional statement, right below y = groundY, go down a few
04:33lines and we will check to see if the player is jumping.
04:36So type if, some parentheses and some curly braces, and in the parentheses type
04:42isJumping, capital J.
04:45Inside of the curly braces for the if statement, we will add the
04:49EventListener for the touchStarted event and just to make sure I typed it
04:53exactly as I did earlier, I'm going to select it on line 33 in my code, which
04:58is inside the allLoaded method.
05:00It's the stage.addEventListener MouseEvent.MOUSE_DOWN line of code.
05:04I'll copy that and paste it inside of the if isJumping conditional statement
05:11in the Update method.
05:13So I'll add that event listener again so the player can jump again, and then
05:17we'll set isJumping = false.
05:21Remember this block of code only runs after the player lands back on the ground.
05:27So, we check to see if the player went passed the ground and then we set the
05:30Y position at the ground, and then and only then do we allow the player to jump again.
05:38So test the movie after saving this file and we will check it out.
05:43(Video Playing)
05:46So the player no longer jumps after we click; you actually have to swipe up. There you have it.
05:59So remember, to detect the finger swipe upward, check the Y position when the
06:04mouse goes down, capture that in a variable, and then compare it to the value of
06:09the Y position when the mouse is released.
Collapse this transcript
Adding sound effects
00:00Sound effects add an element or fun to your games you can't get any other way.
00:05So let's add sound effects to the jumping animation for the character.
00:09To start out we're going to look for some sounds in the Library to export them for ActionScript.
00:14So open up the Library and find BailSound.mp3. Right-click it and choose
00:21Properties, check the Export for ActionScript box, and then change BailSound.mp3
00:27for the class name to just Bail.
00:30Click OK and then click OK again to close the warning window that says Flash is
00:35going to create the Bail class for you.
00:38Remember, it's a subclass of the Sound class so it has all the properties and
00:42methods that the Sound class has.
00:43So we'll go to JumpSound.mp3 and we'll do the same thing. Right-click, choose
00:49Properties, check Export for ActionScript, you may have to click the Advanced
00:54button to reveal that, change the Class to Jump.
00:58Click OK and OK again and jump over to Boarder.as, and here we'll create a
01:06couple of new properties.
01:08Create a public property called bailSound, data type it to Bail, that's
01:15the exported class.
01:17Create another public property called jumpSound, data type it to Jump, and
01:21finally create another public property called soundControl. Data type it to SoundChannel.
01:30This is going to be the object that controls all the sounds that play.
01:34In the constructor, we'll create new instances of Jump and Bail using our properties.
01:41So right below where we create the Accelerometer in the constructor,
01:46type bailSound = new Bail and the same thing for jumpSound.
01:52So jumpSound = new Jump.
01:56Scroll down to the bottom of your code and below the jump method create another
02:01private method called controlAudio.
02:05In the parentheses type (and:Sound), :void for no return data, and some curly braces.
02:15So when we run controlAudio, we're going to pass in a sound object.
02:19So it's going to be either the jumpSound or the bailSound and this method is
02:23going to make this sound play, and it's going to set its volume.
02:26So the first thing you're going to do is create a variable to hold the
02:30SoundTransform object that we can use to control volume.
02:34So create a variable called trans, data type it to SoundTransform.
02:38We'll set to a new SoundTransform, and in the parentheses type 0.5.
02:47That's the volume of the sounds.
02:48So it goes between zero and one. Anything above zero or below one is going to get distorted.
02:55So go to the next line and type soundControl = snd.play.
03:05That's the sound that was passed in, and we'll start at the beginning.
03:09So the first parameter startTime, which is a number. We'll set it to zero.
03:13Second is loop, so we don't it want to loop, so we'll put zero and third is
03:17a SoundTransform. We'll type in trans and close up the parentheses and type a semicolon.
03:22Now when you test the movie when you have it like this, you might find that the
03:26sounds overlap, because every time you run the controlAudio method, you're
03:30creating a new SoundChannel object with your sound property.
03:35So to make sure we've better control over that, above var trans, create an if
03:40statement to see if the SoundChannel object already exists.
03:44If so, we'll destroy it so we're not overlapping creating a new sound object every time.
03:51So in here we'll check to see if soundControl exists, then we'll type
03:56soundControl.stop, so we'll stop the playing sound and then we'll set
04:01soundControl = null.
04:03Now the last thing we want to do is run the controlAudio method. We'll do that
04:09right under isJumping = true in the jump method.
04:12So type controlAudio and the parentheses pass in jumpSound.
04:20Save the file and test the movie to hear the jump sound when you make
04:24the character jump.
04:25(Music Playing)
04:28There we go.
04:29(Zoop, zoop!)
04:33See how much more fun it is now?
04:36So to add sound, you just simply create a SoundChannel object and you set it
04:41equal to the playing sound.
04:44If you want to apply volume to it, you can add that in the play method by
04:49passing in an instance of the SoundTransform class.
Collapse this transcript
3. Creating Animated Background Elements
Creating a reusable Mover class
00:00Since many objects in the game will be moving, it make sense to write a
00:04reusable class file to manage all of them rather than writing the same code multiple times.
00:10Before we start writing the code, I want to show you what elements we are
00:13going to be moving.
00:15In the Library, open up the Game movie clip. Inside of there, you'll see some
00:21various background elements.
00:23There is the FarBack movie clip, which consists of the sky and silhouetted
00:28buildings, and then the closer background, which is the front buildings and the
00:33lights and the trees and everything.
00:35So these are the two main movie clips we're going to start with, connecting
00:39them to the Mover class.
00:40In this movie, we're just going to write a few lines of code in the Mover class
00:43to build the scaffolding for our parallax scrolling.
00:47So let's go to Mover.as and we're going to create one public property called speed.
00:54This is going to be a Number and we'll set equal to zero to initialize it.
01:00In the constructor, I'll add an ENTER_FRAME event listener.
01:03So addEventListener and the event is going to be Event.ENTER_FRAME.
01:12And when the ENTER_FRAME event occurs we're going to run the update method.
01:17So let's define the update method as a private method.
01:20It will receive an event with the data type of event, :void for no return data,
01:28and in here we're simply going to update the x position based on the speed. So x += speed.
01:36That's it.
01:37Make sure to save the file and now we have everything set up, so we can start
01:42adding parallax scrolling to our game.
Collapse this transcript
Linking the Mover class to the parallax elements
00:01Parallax scrolling will give the background of the game some more depth, which
00:04is really important when the artwork is relatively flat like in our game.
00:08Before you can make objects have Parallax Scrolling we will need to connect
00:12them to the Mover class.
00:14So I'll go to the FLA file and then open up the Game movie clip.
00:19In there, you'll see a few background elements.
00:22We have the silhouetted buildings and then the more foreground and background art,
00:28which is the lights and trees and the foreground buildings.
00:32So let's connect these to the Mover class. Right-click BG in the Library
00:38and choose Properties.
00:40Check to Export for ActionScript box and change the Base Class to
00:45com.toddperkins.sk8bit.Mover.
00:53This way Flash will use that Mover class as the base class and connect and
01:00create a custom class for the background.
01:02Remember, you can't use the same class from multiple movie clips, so if you
01:07want to connect the same class to multiple movie clips, you need to use the
01:12base class instead of the regular class and have Flash generate the regular class for you.
01:18So click OK and you should see that warning message that says Flash is going to
01:22create a class for you.
01:23So you can click OK and then we'll do the same thing for FarBack.
01:29So right-click the FarBack movie clip, choose Properties, check Export for
01:34ActionScript, and change the base class to com.toddperkins.sk8bit.Mover, click OK,
01:43and click OK for the warning message, and now we just want to confirm the
01:47instance names of these objects on the stage.
01:50So if I expand the Timeline panel, I could scroll down and unlock the background layer.
01:59Now when I unlock the background layer you'll see that mask shows now,
02:03so I don't want to see that mask.
02:04So I'm going to hide the mask and I can select the background and in the
02:09Properties panel I can see that it's called bg_mc, and then I want to select the
02:14far background now to confirm its instance name.
02:18So I'll select it and confirm that its instance name is farback_mc, all lowercase.
02:24So I'll lock those layers and then show the mask again and go to our Game class.
02:31Now I'll hide the Timeline panel so I've some more space to write code and
02:36I'll create a property in here, right above the constructor, and I'll call the
02:41property moveSpeed.
02:43So it will be private.
02:44It's private var moveSpeed, data type it a Number, and I'll set it equal to 5.
02:51This going to refer to the amount of pixels per frame that the objects move.
02:57So in the Game method, which is the constructor method, I'm going to call a
03:02method that I'll create in just a second called updateSpeed.
03:07Now below the constructor I'll define the updateSpeed method. public function
03:12updateSpeed, so ():void for no return data.
03:17So we'll type bg_mc.speed.
03:21Remember it has that property and so it is far back, because they're both
03:24subclasses of the Mover class, so they inherit the speed property.
03:28We'll set that = -moveSpeed.
03:32So that will move the objects to the left, making it look like the
03:35skateboarder's moving forward.
03:37Now we'll set farback_mc.speed = bg_mc.speed / 5.
03:47Now I deliberately did not use the moveSpeed variable when setting the speed of farback_mc.
03:52I want this speed to be exactly 1/5th the speed of the background.
03:57So if I ever change moveSpeed then the speed is proportional to bg_mc.
04:04That will keep our parallax scrolling looking accurate no matter how fast the
04:10movie clips are moving.
04:11So let's save the file and preview the parallax scrolling in the Flash Player.
04:15(Music playing)
04:21It looks like he is just riding along. I can jump and move back and forth.
04:28So notice that the background kind of ran out and that's something that we will fix later on.
04:33But for now our parallax scrolling is working properly.
04:36So now that these movie clips are connected to the Mover class, you can make any
04:41of these objects animate using minimal code.
04:43To add parallax scrolling to your game, simply set the object scrolling speeds
04:48to different values.
04:49Remember the closer an object is to the camera, the faster it should scroll, and
04:53using proportions like we have here, you can make sure all the animations are
04:58proportional to each other regardless of how fast they are moving.
Collapse this transcript
Looping background animations
00:00Now that we have scrolling backgrounds the next step is to make the
00:04backgrounds loop indefinitely.
00:06To do that I'm going to use a copy of the scrolling movie clips that's going
00:10to act as a buffer.
00:13If you go inside of the game movie clip and you hide the mask layer and you
00:21unlock the Far Back and BG layers you can scroll to the right and see that I've
00:29made copies of the background movie clip and the far background movie clip.
00:34Now if you look in the Properties panel you can see that I called them
00:38bg2_mc and farback2_mc.
00:44So in order to add that functionality you're going to need to clone your movie
00:47clips and just give them different instance names.
00:51So let's go over to Mover.as, and again I'll hide the Timeline panel so I have
00:56some more space to write my code.
00:58And here I'll create a new property. This will be Public, and I'll call it
01:03Buffer, data type it to a movie clip.
01:06Then I'll scroll down to the update method. Right below where I set the speed
01:11value, I'm going to check to see the position of the object. I want to see if
01:17it's gone off the stage.
01:19So in here I'll type an If statement and in the parentheses of the If statement
01:25I'm first going to check to see if there is a stage.
01:28So if the object has a stage property and it can reference it, then what I'm
01:32going to do is type two ampersands as to and operator, so both of these have to be true.
01:38And I'm going to see if x position is less than or equal to negative width.
01:44So that means that the right edge of the object is aligned with the right edge of the stage.
01:50If that's the case first we're going to check to see if there was a buffer, so
01:53in parentheses, so type an If statement and in the parentheses type buffer.
01:59You want to see if that value is set, and if so we'll set the x equal to the
02:04buffer's x position.
02:06So the buffer is actually going to be moving along with the main movie clip, so
02:11bg_mc and bg2_mc are going to be moving the same speed right next to each other,
02:18so it's going to have this seamless feeling to it.
02:22So there is a buffer and the main object has gone off the stage. We're going to
02:26swap positions, we're going to put the main object at the position of the buffer
02:31and then move the buffer back to the right of the main object. So we set the x
02:37position of the buffer and then we'll create an else statement. Type x = width - 10.
02:49So if there is no buffer we're simply going to have the main object loop around
02:54to align its left edge with the right edge of the stage.
02:58So it'll be all the way back at the right edge of the stage and totally off the
03:02stage, so it'll come all the way from outside of the left edge of the stage.
03:06So under this big If statement where we check to see if there's a stage and x is
03:11less that equals to negative width,
03:13I'm going to create another If statement and check to see if there is a buffer.
03:16So If and then buffer inside of parentheses we're going to set the x position of
03:21the buffer here, so buffer.x = x + width - 10.
03:23Now you may be wondering why I'm putting this -10 here and here.
03:37It just so happens at the way that my movie clips are set up,
03:41how the artwork works, is that in order to make them overlap more seamlessly I
03:46need to have them overlapping by 10 pixels rather than just flush with the side.
03:51So that's just something to do with this particular artwork.
03:54So let's save this file and then jump on over to Game.as and we'll set the
03:59buffer properties here.
04:01So scroll down to updateSpeed and below the rest of the code that you've
04:05already written. Set the buffer for bg_mc and farback_mc.
04:10So type bg_mc.buffer = bg2_mc.
04:13I'll do the same thing for farback. So farback_mc.buffer = farback2_mc.
04:22Now we've set the buffer for the background and the buffer for farback_mc. Now we can
04:32save and test the application.
04:38(Music Playing)
04:40Now we should see that the game scrolls indefinitely.
04:43Now we have a seamless transition between the buffer and the main movie clip.
04:48It looks good. So remember, to make background's loop, create a buffer clone and
05:06connect it to the main movie clip using a buffer property.
Collapse this transcript
4. Adding Obstacles and Scoring
Creating a reusable Obstacle class
00:00Even though this version of the game only has one obstacle, it's always a good
00:04practice to make your game scalable so you can add more features later on.
00:08In this movie we'll add some code to our Obstacle class, so you can make any
00:13object into an obstacle.
00:15Before we do that let's connect the TrashCan movie clip to the Obstacle class.
00:20So open up the Library and right-click to TrashCan movie clip, choose Properties,
00:25and then check the Export for ActionScript box.
00:28Remember, you want to connect the base class to the Obstacle class, not the main
00:33class, because you can only do that for one movie clip per FLA file.
00:37So we want to make this reusable, so again we'll apply to the base class.
00:42So in there type com.toddperkins.sk8bit. Obstacle. I'll click OK and Flash will
00:52create the TrashCan class for us, then we'll jump over to Obstacle.as.
00:57Right above the constructor I'll create a public property called leadingMover.
01:03data type it to a mover and we won't give it a value just yet.
01:07This is going to represent the background movie clip, so the trashcans will go
01:13the same speed as the background.
01:16Let's write the code to see how that works.
01:19Scroll down into the allLoaded method. In there add an EventListener to listen
01:23for the inter-frame event. So addEventListener and the event's going to be
01:28event.enter_frame. We'll run a method called Update which is already defined.
01:34And inside of the Update method the first thing we're going to do is to check to
01:38see if leadingMover is already defined.
01:41So we create an If statement and inside of the parentheses type leadingMover.
01:47So if it's already defined then here is what we're going to do.
01:50Inside the curly braces for the If statement, type x += leadingMover.speed.
01:59Notice that speed is highlighted in the code hinting window.
02:02It's a new feature of Flash CS5.
02:05So we're going to move the x position of the obstacle at the same speed as the
02:10leadingMover speed, which in this case is going to be bg_mc.
02:15If leadingMover is not defined then we'll define it.
02:19So right below the close curly brace of the If statement create an else statement.
02:24In the else statement type leadingMover = and then we're going to type
02:31parent.getChildByName and in quotes inside of the parentheses, type bg_mc.
02:41Note that if we just typed parent.bg_ mc we get an error because parent is a
02:47display object container, which doesn't have a property called bg_mc. Further,
02:52getChildByName returns a display object, so what we want to do is tell Flash to
03:01data type this information as a Mover.
03:04So I'll wrap (parent.getChildByName ("bg_mc")) in parentheses, so you should have
03:11two parentheses at the end.
03:13Right before the open parenthesis, before parent, I'm going to type Mover with
03:17a capital M. So Flash will take all this data and data type it to a Mover before
03:22setting the leadingMover property.
03:24So save the file and go back to your FLA file. In your FLA go to the Game movie clip.
03:33In the Game movie clip you'll see some trashcans at the bottom of the stage.
03:39These are on the TrashCan layer, so I can show and hide them there.
03:48Click-and-drag the trashcans onto the background, like so.
03:55Now at this point you should be able to test the movie and see the trashcans moving.
04:00(Music Playing)
04:04And there they are.
04:05So I'm just going to undo those changes and put the trashcans back to where they
04:13were to clean up the stage.
04:15So as you've seen the Obstacle class is now working and connected to the
04:19TrashCan movie clip.
04:20If you wanted to create other obstacles all you'd have to do is to connect any
04:25movie clip you want to the Obstacle class.
Collapse this transcript
Detecting collisions with the player
00:00Nearly every game needs a way to handle collisions between objects and this
00:05game is no exception.
00:06In the Obstacle class, let's add some code so we can support
00:10collision detection.
00:11Let's start by creating two more public properties.
00:16So public var mainCollider, and that will be a Boarder.
00:21This is going to represent the object that's going to cause a collision or the game's hero.
00:27Let's go to the next line and create another public property called hit.
00:32And this is going to represent the hit area of the movie clip.
00:36So let's type MovieClip for the datatype.
00:39Now, you don't have to have a customized hit area for your application, but for
00:44this one I wanted to make the game a little bit easier.
00:46So I created a custom hit area.
00:49If you want to see that, you can go to the FLA file, go to the Library, and open
00:54up the TrashCan movie clip.
00:56In there, you'll see a small blue rectangle that is smaller than size of the
01:00trashcan, and I named it hit_mc.
01:04So you can see if you expand the Timeline that the trashcan is hidden and when
01:10I show it, you can see it's bigger than the hit area.
01:12So it's your call how to handle that.
01:13Let's jump back to Obstacle.as, and then in the allLoaded method right above
01:20addEventListener(Event.ENTER_ FRAME) I'll type hit = hit_mc.
01:25Now, we'll write the collision detection code in the update method.
01:30Below everything else that's previously written inside this method, I am going
01:34to create another if statement.
01:36I am also going to create an else statement.
01:38So I'll just create the skeleton of that statement while we are at it.
01:41So I have if and else and for the condition of if, we want to check to see that
01:45mainCollider is defined and hit is defined.
01:50If so, then we go into check for the collision.
01:53So create an if statement in here with some parentheses and curly braces.
01:57The way that we detect a collision is by calling the hit test object method.
02:01So type hit. This would just be this if you were not using a special hit area,
02:06.hitTestObject, and in parentheses pass in mainCollider.
02:12Make sure you have two parentheses at the end of that if statement, one to close
02:17out hitTestObject and one for the if statement.
02:19We are seeing if the objects are touching.
02:22If so, then we'll run a method on the Boarder.
02:25So we'll create that later in this movie.
02:28But it's going to be called collidedWith and it's going to accept one parameter,
02:32which is an Obstacle.
02:33So type mainCollider.collidedWith, and in the parentheses pass in this.
02:42This will allow the Boarder class to have information about the object that it collided with.
02:46Go to the next line and we'll set mainCollider = null.
02:50That way we don't have any extra references to the Boarder in another class, so
02:54it can successfully be garbage collected.
02:56Go to the next line.
02:57We'll set hit equal to null as well and we'll remove the EventListener for the update method.
03:04To do that, I'm going to copy the AddEventListener line of code inside of the
03:08allLoaded method, Ctrl or Command+C, and I'll paste it in that if statement that
03:14we are working in, right below hit = null.
03:17In the pasted code change add to remove.
03:21So this is going to be what happens if mainCollider is defined.
03:25But we actually haven't defined it yet.
03:27We'll do that in the else statement.
03:30So scroll down in that empty else statement that you created earlier in this movie--
03:34let's close the Timeline here to get some more space--
03:37type mainCollider, and we are going to set its value in the same way that we set
03:42the leadingMover value on line 32 in my code.
03:45See how we datatyped parent.getChildByName to a Mover?
03:48We're going to do the same thing there but for the Boarder.
03:51So, after the equals sign after mainCollider type Border, capital B, and then
03:55type some parentheses and a semicolon.
03:58And inside of the parentheses, we'll type parent.getChildByName.
04:04In the parentheses for getChildByName type some quotes and then type the name of
04:10the skateboarder, which is boarder_mc. All right!
04:15Save this file and then remember that we have to define the collidedWith method
04:20inside of the Boarder class.
04:22That's going to happen when the collision happens.
04:25So go to Boarder.as, scroll all the way down to the bottom, create a new public
04:32method, because we are going to need to be able to call this from other classes.
04:36So public function and then collidedWith, capital W. In the parentheses we'll
04:43receive a parameter, we'll call it obj, short for object, and datatype it to an
04:49Obstacle, :void for no return data.
04:53Inside of the method, we'll type gotoAndPlay and we'll pass in 2.
05:01The animation of the Boarder falling is on the second frame.
05:05Now if we had more animations inside of the Boarder movie clip, it would make
05:09sense to use frame labels.
05:10But since it's always going to be on frame 2 and frame 1 is always going to be
05:13a static image of the boarder standing on the skateboard, I decided to just use a number here.
05:18Go down to the next line and run a method called controlAudio.
05:23In the controlAudio method we'll pass in the bailSound.
05:25Then we'll remove the event listeners from the stage for MouseEvent.MOUSE_DOWN
05:30and MouseEvent.MOUSE_UP.
05:32To do that, I am going to scroll up in my code and I am going to find
05:36the touchEnded method.
05:37In there, I'll select the line of code that says stage.removeEventListener, copy
05:41it and scroll down, and I'll paste it right below controlAudio.
05:44So we want to disable the mouse interactivity after the collision happens.
05:49So scroll up and we'll find the line where you removed the event listener in touchStarted.
05:53So find touchStarted and in there select
05:56stage.removeEventListener(MouseEvent. MOUSE_DOWN, touchStarted), copy it, scroll
06:02down to collidedWith, paste it at the bottom of that method.
06:05Now in here, we want to have a property that stores whether the skateboarder
06:10bailed and here we want to set it to true.
06:13We also want to send out an event that the boarder bailed so that we could
06:17check that from other classes in the future.
06:20That way we can handle the gameplay.
06:22So let's scroll up and go up to the section of your code where you define the properties.
06:28In here, we'll create two properties, both public.
06:32One called didBail, capital B, datatype it to Boolean, and then the next one is
06:39going to be a static constant, just like we did for landed earlier.
06:45So this is going to be BAILED and we can dispatch an event with it.
06:48So BAILED is a string and we'll set it equal to bailed as a String. So it's in quotes.
06:54So now scroll all the way back down to the collidedWith method and we'll set
06:59didBail = true and then we'll dispatch the BAILED event.
07:03So dispatchEvent, capital E, and in the parentheses type new Event with
07:10a capital E, and some more parentheses, and in those parentheses type
07:15Boarder.BAILED all caps.
07:17So we are setting out this event and we can listen for it in another class
07:22and react accordingly.
07:24We'll do that in another movie.
07:25I want to make one more change before we test the movie.
07:29Scroll up to the update method and in here when we check to see if(isJumping)--
07:35that's in the conditional statement where we check to see if y is greater than
07:39groundY where the character lands.
07:42We want to make sure that he is jumping and did not bail.
07:46So after isJumping type two ampersands and an exclamation point for the Not
07:51operator and then didBail with a capital B.
07:54So if the character is jumping and didn't bail and hits the ground, then we're
07:59going to set isJumping to false and add that event listener. Again, because if
08:03the character did fall over, then we don't want to re-add this event listener,
08:08because that will add mouse interactivity again.
08:11We don't want that to happen.
08:13Below that if statement, create another if statement.
08:17We're going to check to see if the boarder bailed.
08:21If he did, we're going to remove the event listener for update so the
08:25skateboarder stops updating.
08:27So the mouse or touch interactivity will be disabled and the accelerometer
08:32interactivity will be disabled as well.
08:34So in the if statement type didBail, capital B, and then we can type the
08:39removeEventListener line of code by scrolling up and copying the
08:42addEventListener line of code, which in my code is on line 42.
08:47Go to the allLoaded method and select
08:49addEventListener(Event.ENTER_FRAME, update).
08:52Copy the code, paste it in the if(didBail) statement you just wrote, and change
08:58addEventListener to removeEventListener.
09:01The last thing we want to do is just put a trashcan on the stage.
09:04So go to your FLA file and open up the Library and head over to the Game movie clip.
09:12In there, find the trashcans at the bottom-right of the stage and just drag one
09:19of them onto the background.
09:21Now let's test the movie and confirm that everything works.
09:24(Music playing)
09:28He can jump and then he hits the trashcan and falls over.
09:32So the interactivity for the boarder is disabled but the background is still moving.
09:37That's something that we'll fix in another movie.
09:39But for now, you can see that the collision detection is set up and when the
09:44skateboarder hits the trash can, he falls over, the sound plays, and all the
09:49interactivity for the skateboarder is disabled.
09:52Remember that whenever you want to add collision detection, use the
09:57hitTestObject method and pass in the object that you want to test the collision with.
Collapse this transcript
Ending the game when the player bails
00:00Now that you have collision detection in your game, we will add some code to end
00:04the game when a collision occurs.
00:06Before we start writing code, I want to show you the Boarder movie clip.
00:10So let's open up the Library and double-click Boarder to enter its Timeline.
00:14So on the first frame we have a stop action, but on the last frame after the
00:19falling animation is complete, let's take a look at the code by opening Actions panel.
00:24See how it says Object(this .parent.parent).gameOver?
00:27That's the code that ends the game.
00:30So we are taking this.parent, which is the game, .parent, which is Sk8bit or the
00:36main timeline, data typing it to an Object so we can apply whatever properties or
00:41methods we want without getting an error and calling its gameOver method.
00:46So the gameOver method happens after the animation is complete.
00:49So let's define what happens in that method right now.
00:52Jump over to Sk8bit.as and find the gameOver method at the bottom of the code.
00:58I am going to double-click the Timeline panel to minimize it so I have more
01:01room for writing my code.
01:03In here we are basically going to reset the game.
01:06So we will type SoundMixer.stopAll.
01:13That's going to stop all the playing sounds that are controlled with ActionScript.
01:17Then we are going to set the sound transform object's volume equal to 1.
01:23If you look in the properties, you will see that we have some properties
01:26to control the sound.
01:27So we have bgSound, bgChannel, and bgTransform.
01:28So we will set the transforms volume to 1.
01:34So bgTransform.volume = 1.
01:37So we will set it to full volume, because we minimized the volume inside of the start game.
01:44Now I have this code commented out, but remember that's only because I'm going
01:48to be talking over while we are playing the game and I don't want that to
01:52conflict with my talking.
01:53So we will uncomment that later on.
01:56But see how the code set to volume of point 3, so the volume is
01:59quieter when game plays.
02:01When it goes back to the titles screen, we are going to make the volume equal to 1.
02:05So let's go the next line and we will play this sound.
02:08So bgChannel = bgSound.play and in the play method we will pass in 0.
02:19That's the starting time. 999.
02:20That's the number of loops, which is essentially infinite.
02:25Then bgTransform to pass in the sound transform object and apply the volume.
02:30Then we will take the game off the stage.
02:32So removeChild(game).
02:36This will put us back on the title screen, and we will set game = null so it can
02:40be garbage collected, and then we'll add the event listener to start the game.
02:44Instead of typing that out I am going to copy and paste it.
02:47So I am going to go to the constructor method, select
02:49Stage.addEventListener, copy with Command+C or Ctrl+C and paste it right
02:54under game = null in the gameOver method.
02:56Now you may be wondering why I always copy and paste these methods instead
03:02of writing them out.
03:03For one it saves time, but the more important reason is that I don't want to
03:08accidentally write the wrong method name or the wrong event and cause an error or anything.
03:13So when I'm recording movies or when I'm programming on my own, I actually
03:18always copy and paste the add and removeEventListener lines of code to avoid
03:22those types of errors.
03:24So let's save the file.
03:28Now before we test the movie, I want to make a change to the Game class.
03:32Remember that in the Boarder class, we set it to fire off the BAILED event
03:37when the boarder falls.
03:39So let's listen for that event and hear and define what happens when that event occurs.
03:44Go to your constructor and right above updateSpeed, we are going to add an
03:49event listener to the boarders.
03:50So boarder_mc.addEventListener, capital E, capital. It should be all blue if
03:58you typed it correctly.
03:59Then the event is going to be Boarder. BAILED, all caps, comma and a space, and we
04:07are going to run a method called finishGame.
04:11The whole purpose of this method for now is to stop the background elements from moving.
04:16So we are going to wait until the boarder falls and then we are going to stop
04:19scrolling the background elements.
04:21So go down a few lines below the constructor and create a private function
04:27called finishGame that will receive an event object with the data type of Event,
04:32because that's the datatype we used when we fired off the event in the boarder
04:35class, :void for no return data.
04:39In the curly braces we will set a speed of bg_mc and farback_mc = 0.
04:47So bg_mc.speed. Remember that's the property that controls how it moves, set it
04:53equal to 0, go to the next line and type farback_mc.speed = 0, and we will save
05:03the file and test it out in the Flash player to see that when you hit a
05:07Trashcan, the background stops moving and the game resets after the animation of
05:14the skateboarder following is complete.
05:16So let's test the movie. Check it out!
05:18(Music Playing)
05:20So I can jump, then I hit the Trashcan.
05:26After the animation is complete, it starts over and you can play it again.
05:29So now we have successfully made it so the game ends whenever you hit an obstacle.
Collapse this transcript
Using a timer to create trash cans
00:00The next step in creating our game is to add functionality to create obstacles
00:04automatically, which we will do by using the Timer class.
00:07Before we create those obstacles though, I want to go inside of the Game movie clip
00:12by double-clicking it in the Library and I will just delete that trash
00:16can off of the stage.
00:18So you see the trashcan that we've been using to do our testing with, I am just
00:22going to select it and delete it.
00:24And will from now on create all the trashcans dynamically using ActionScript.
00:29So jump over to Game.as and we will write the code.
00:33Start by minimizing the timeline.
00:35Then we will create some properties.
00:39So scroll up to the top and right below movesSpeed = 5,
00:42we will create a private property called canY, datatype it to a Number, and
00:50initialize it to 240.
00:52Now I didn't just make this number up, I put the can on the stage and just
00:58tested where I wanted its Y position to be in and then I wrote that number down
01:01and put that in here.
01:02Next, create another private property called closeTrashCans.
01:10So it will be a uint, a positive integer equal to zero.
01:14Whenever we create a trashcan we are going to have close trashcans and far trashcans.
01:20But we want to have a limit to the number of close trashcans that can exist.
01:24So this property is going to hold the number of close trashcans that there are on the stage.
01:31Create another private property.
01:32This is one's going to be called allowedCloseTrashCans.
01:42This is also going to be a positive integer and we will set it to the value of 4.
01:47So if you increase this or decrease it, you can alter the number of trashcans
01:52that are allowed to be close together.
01:53So create another private property called isFirstCan and we wanted to check to see
01:59if the trashcan is the first trashcan.
02:01So type isFirstCan.
02:06That's going to be Boolean and we will initialize that to True.
02:11So before anything else happens we are going to set the trashcan to be the first
02:15trashcan and then we will create all the trashcans dynamically.
02:20So scroll down, go to the next line, and we will create a final private property,
02:26and this is called obstacleTimer.
02:28Datatype it to a Timer, and we will initialize it right here to a new timer and
02:34then we will pass in the parentheses 5,000.
02:37That's 5,000 milliseconds.
02:40So if the timer is going to go off every five seconds, unless we change it.
02:45At the bottom of the constructor method add an event listener to obstacleTimer.
02:50obstacleTimer.addEventListener and the event is going to be TimerEvent.TIMER and
02:58we will run a function called makeObstacle.
02:59We will define that method in just a moment.
03:03On the next slide we will make sure to start the timer.
03:05So obstacleTimer.start and then we'll define,makeObstacle.
03:12So this will be a private method, so right below the constructor Private
03:16function makeObstacle.
03:17And the parentheses we will receive an event object with the datatype of
03:22TimerEvent, :void for no return data, and here we will make the trashcans.
03:28Now we've already exported the trashcan for ActionScript and there in its
03:33class called TrashCan.
03:35So we will create one by typing var can, datatype it to a TrashCan, and we will
03:41set it equal to a new instance of the TrashCan class.
03:45Then we are going to set the speed.
03:47So go to the next line and we will put the can on the stage.
03:50So addChild and in parentheses can.
03:54Now if we were to do this right now and test the movie, you see that the can
03:57would be in front of the skateboarder.
04:01We don't want that to happen.
04:02We want the can to be behind the skateboarder.
04:04So we will add the boarder to the stage again here.
04:07So addChild and then boarder_mc right in there.
04:12So make sure that the skateboarder is in the front and now we want to set the
04:16can's X and Y positions.
04:18So can.x = stage.stageWidth.
04:24So it will be aligned with the right edge of the stage.
04:26So it will just come from off of the stage and then we will set can's Y position = canY.
04:34Let's save the file and test the movie.
04:37So File > Save and we will test it out.
04:40(Music playing)
04:45So after five seconds there should be a trashcan and see if you can jump over it
04:51and see the next trashcan. There you go!
04:58So every five seconds there should be a new trashcan on the stage. Nice!
05:08Now what we will do is make it a little bit more interesting by randomizing the timer.
05:15So each time a trashcan is created, the difference between the time that a
05:21trashcan is created will be random.
05:24So a trashcan can be created after half a second or after 5 or 10 seconds
05:29or whatever we want.
05:30So let's go down a few lines and we will stop the timer.
05:34So obstacleTimer.stop, create a variable called newDelay, datatype it to uint,
05:43and then we will create some conditional statements to make the newDelay.
05:48So go down a few lines and I will type if, some parentheses, and some curly
05:54braces and here what we are going to do is check to see if Math.random.
06:00So we are going to generate a random number between 0 and 1. We'll try to see if
06:05it's greater than .5. So if so, Or. So two pipes. closeTrashCans is greater than or
06:15equal to allowedClosedTrashCans Or, two more pipes, isFirstCan.
06:25So if any of those things is true, then we are going to have a greater delay
06:30between the trashcan.
06:31So in that if statement type newDelay = Math.random() * 3000.
06:42That's three seconds. + 3000.
06:46So it will have three second randomness, but a minimum of three seconds.
06:52So somewhere between 3 and 6 seconds, that's going to be the new delay.
06:56Let's go down to the next line and type closeTrashCans = 0 and then we'll
07:04set isFirstCan = false.
07:08Now if this if statement is not evaluated as true, then we will create a closer
07:14trashcan with a lower delay.
07:15So right below that if statement, create an else statement.
07:19Inside of the curly braces of the else statement, we will check to see the delay
07:24of the obstacleTimer.
07:26So if statement in there, and inside of that if statement type
07:31obstacleTimer.delay is less than or equal to 500, so half a second.
07:39Then we are going to add two close trashcans.
07:41So closeTrashCans ++.
07:42So we've got to see every time we create a trashcan, we see how many close
07:50trashcans there are, and we can increment that if it's a close trashcan.
07:55Then right below that we will set a value for newDelay and we will set equal to
07:59Math.random() * 500.
08:03So anywhere between zero and half a second will be the new delay.
08:08Now under the else statement we will apply that change.
08:12So obstacleTimer.delay = newDelay.
08:20Then we will start the timer again.
08:22So obstacleTimer.start.
08:26So now instead of creating new trashcan every five seconds, it'll be randomized.
08:31It will either be a far trashcan, which is between 3 and 6 seconds, or a close
08:36trashcan, which will be between zero and half a second.
08:39So now before we test the movie, we need to disable the timer in the
08:45finished game method.
08:46So find the finished game method.
08:48You should be able to scroll down a little bit to see it, and right below
08:51farback_mc.speed = 0, type this.
08:55ObstacleTimer.stop, so we will stop the timer and then we are going to remove
09:02that event listener for the timer event and you can copy and paste that code
09:07from the constructor.
09:08So find obstacleTimer. addEventListener and select it, copy with Command+C,
09:13Ctrl+C, scroll to the bottom of your code, in the finished game, paste it right below
09:18obstacleTimer.stop, and then change addEventListener to removeEventListener
09:23in the pasted code.
09:24So we will save the file and you should at this point be able to test the movie
09:29and see the cans appear at random intervals after the first can.
09:33(Music playing)
09:34So now the game is going to be a little bit more challenging.
09:36So we wait for five seconds and the first can comes and then we see the second can.
09:50Then there are two cans next to each other.
09:53So this is going to be different every time you play the game.
09:55So now we have a little bit of a challenge.
10:04(Music playing)
10:05Then the game restarts if you hit a trashcan and you can play again.
10:08So you really have all the basic functionality for the game.
10:13We just need to add stuff like scoring and the rest of the features and then we are all done.
10:17So now that we've added the randomized timer, the game is a lot more
10:25interesting and you can jump over the trashcans.
10:27It goes on indefinitely. Trashcans are created at random intervals.
Collapse this transcript
Calculating points and deleting unused objects
00:00Adding scoring will add more fun to the game.
00:03Let's look at how to add points each time a player jumps over a trashcan.
00:07The first thing we will do is create a property called score.
00:11I'll create that at the bottom of our properties in the game class, private var score,
00:15data type it to uint and set it equal to 0.
00:20Next, scroll down to makeObstacle method and right below can.y = canY,
00:27type can.addEventLister, capital E, capital L and in the parenthesis type
00:32Event.ENTER_FRAME and we will call a method called removeCan.
00:38Now we haven't defined that yet and we'll do that right now.
00:41Before we define it, I want to select this line of code and copy it.
00:45So Command or Ctrl+C because we will use it in just a second.
00:48Right below make obstacle, let's create the removeCan methods.
00:54So private function, removeCan, capital C, receives an event object, with a
01:00data type of Event, :void for no return data and some curly braces.
01:05In here we'll create a variable called can that is going to be a TrashCan and we
01:13will set it equal to event.currentTarget.
01:17That was the object that added the event listener.
01:19However, this isn't going to return a TrashCan so we are going to need to typecast it
01:23and tell Flash to treat this data as a trashcan.
01:28So wrap event.currentTraget in parentheses and right before the parentheses type Trash with
01:33capital T, Can with a capital C.
01:36Here what we want to do is check to see if the trashcan is off the stage, because
01:40we don't want to add to the player score just when the player jumps over the
01:44trashcan because the player could backup into the trashcan, so we want to make
01:47sure that the score is not incremented until the trashcan is off the stage
01:52and the player can no longer hit it.
01:54At that point we also want to delete the trashcan so we are not wasting memory.
01:58So go to the next line of code and check to see if the Can is moved off the stage.
02:03So create an if statement and in there check the can's X position.
02:08So if can.x < -can.width.
02:14So that's going to be where the can's right edge is aligned with the left edge of the stage.
02:18So it's completely off the stage.
02:21So if that's the case, it's time to give the player a point and delete the can.
02:26So here we will paste the code that we copied a minute ago.
02:29Command+V or Ctrl+V to paste. That's the can.addEventListener line of code.
02:33If you don't have it in the pasteboard you can get it from the makeObstacle method.
02:39So in the pasted code, change addEventListener to removeEventListener. That will
02:43stop the trashcan from running that ENTER_FRAME event which is going to take up
02:47so much memory, and then we are going to take the can off of the stage.
02:52I am going to do that by calling can.parent.removeChild and in parenthesis
02:58I will pass in the can.
03:00So I have the can's parent remove it from the stage and then we will
03:04increment the scores.
03:05Score ++ and the last thing we want to do is put the score inside of the score
03:12text field, which is called score_txt.
03:15So go to the next line and type score_txt.text = score.
03:23Now remember score is an integer so this might give us an error.
03:26So I am going to tell Flash to treat this as a string, so we don't have any problems.
03:31Wrap score in parenthesis and right before the open parenthesis type
03:35String with a capital S.
03:37Now if you want to confirm an instance name of the score text field, you can
03:40go inside of the game movie clip and check that, but I am not going to do that right now.
03:45Save the file and let's check it out in the Flash Player.
03:49Remember what you're looking for. You want to see that when you jump over a
03:52trashcan and the trashcan goes all the way up to the stage, the score increments
03:56and shows it in the score text field.
04:00(Music Playing)
04:06All right! I am just going to make it over this first trashcan.
04:11The trick is that you slide your mouse as you slide up.
04:15So you can move in the air.
04:18So you can see my score is incrementing here. Great!
04:23Looks like everything is working.
04:25So now each time the player jumps over the trashcan, the score is increased by one.
Collapse this transcript
Using a shared object to save a high score
00:00Saving data to a person's computer or iOS device may seem like a complex
00:04process, but Flash has some built-in tools to make it surprisingly simple.
00:09Let's take a look at how it works to save a person's high score to their
00:13computer or iOS device.
00:15In the Sk8bit class right above the private var where we create the game, I am
00:20going to create a public static constant called HIGH_SCORE, in all caps.
00:28Set its data type to a string and we will set its value equal to highScore, with
00:36the capital S, SK8Bit.
00:44If you're creating this for another game, you can really call it anything you want.
00:48So we'll save the file and head over to Game.as.
00:53Right below the score property, I am going to create another private property
00:58called high, short for highScore.
01:01This will also be a positive integer and we will initialize it to 0.
01:05On the next line, we will create the object that will store our high score.
01:11The class is called SharedObject and it's in a package called Flash.net.
01:17So create a private property called score_so, short for shared object.
01:25Data type it to a SharedObject and we will set it equal to
01:30SharedObject.getLocal and in the parenthesis we will pass in Sk8bit, so the
01:43class name, Sk8bit.High_Score.
01:48So what this is doing is it's grabbing any data that may exist for this object.
01:54So if there is already a high score, say it is going to grab it. If not, we will
01:58check to see and control how that's going to work.
02:01So scroll down and we will write the code for that at the bottom of the constructor.
02:05So right below obstacleTimer.start, we will create a conditional statement to
02:10see if there is a high score property.
02:13So type if and some parenthesis, some curly braces.
02:17We are going to check to see if there is a high score already.
02:20So if (score_so.data.
02:25Now this is how we define our custom properties.
02:28We have this data object and you can save your data as a high score or any
02:33other data you want provided it follows the SharedObject specifications inside
02:38of this data object.
02:39If you want to read more about that, you can see it on Flash Help.
02:43So the property is highScore with a capital S. So if there is a high score, then
02:51we will set the high property = score_so.data.highScore, capital S.
03:02If high score is not defined then we will define it here.
03:05score_so.data.highScore = 0.
03:13Now we will put the high score inside of the highScore text field.
03:17So right below that else statement, type high_txt, which is the name of the
03:24highScore text field, .text = high and remember that this is an integer so we will
03:32need to data type it to a string.
03:34So wrap high in parenthesis and type the word String with a capital S right before it.
03:40Now we will add some code to update the high score.
03:43Scroll down and find the removeCan method.
03:47Right below where we reset the score text field, go down a few lines.
03:52We'll create an if statements that checks to see if the score is greater
03:56than the highScore.
03:58So if some parenthesis, some curly braces and an if statement. We type score > high.
04:07So if the score is greater than the high score, then we are going to set high =
04:12score and then we are going to set the data for the shared object.
04:17So score_so.data.highScore = high.
04:25And the last thing we will do is put the new high score in the text field.
04:31So right below that line, high_txt. text=String with capital S and some
04:38parenthesis. Inside of the parenthesis pass in high.
04:43So if the person playing the game happens to get the high score, we hold
04:47it in that higher property put it inside of the shared object and then set it
04:51in the text field, and that is literally all you have to do to save data to a user's device.
04:57So let's check this out by saving the file and we will test it in the Flash
05:01Player and watch the high score update as we score points.
05:08(Music playing)
05:13Okay, so I just go to make it over this first trashcan and you should see high
05:17score update to one.
05:20There we go. So now I run into this next one.
05:24(Music playing)
05:27Now when I play the game again, as we see high score is one and then so you
05:33can tell it's saved. And then if I go higher than that, you will see that it updates.
05:42Now for the real test. Close the application and then test the movie again.
05:49(Music Playing)
05:52When you start the game, note that your high score is saved.
05:55The data is actually saved on your computer so even if you delete the SWF file
06:01and you test the movie again, your high score will still be there, and the same
06:05code that works on your computer and the Flash Player, works on the iOS device.
06:10So that's all you have to do to create a high score.
06:13Simply create the shared object and store whatever data you want inside of that object.
Collapse this transcript
Increasing scrolling speed as gameplay progresses
00:00To make the game more difficult as time goes on, we'll make the scroll speed go
00:05faster and faster each time the player jumps over 10 trashcans.
00:09We'll add the code toward the bottom in the removeCan method.
00:15So find that method in your code. Mine is on line 70.
00:17We're going to write the code as the last block of code within the if(can.x <
00:26-can.width) if statement.
00:28So go right below if(score > high), and we'll add some code.
00:33What we want to do is check to see if the score is a multiple of 10.
00:41Now there is actually a mathematical operator that makes it really easy to find
00:45if something is a multiple of another number.
00:47Let's type an If statement, so if and some parentheses and some curly braces and
00:52in the parenthesis check to see if(score % 10 == 0).
01:00Now the % sign operator divides the value and returns the remainder.
01:07So it takes score, divides it by 10, and returns the remainder.
01:13So if the remainder of score divided by 10 is equal to 0, then we can run the
01:19block of code in the quotes.
01:21So that's when we want to speed up.
01:23So I'm going to increase move speed by 10%.
01:27To do that, type moveSpeed, capital S, space, asterisk, equals, space, we're
01:34going to multiply by its current value, and the value is going to be 1.1.
01:41We're going to multiply 1.1 times the current value of moveSpeed to
01:46increase moveSpeed by 10%.
01:49Go to the next line and then we'll run update speed to update the speed of
01:54background and far back.
01:55We already wrote that code earlier.
01:57So type updateSpeed with capital S. Remember, background and farback are going
02:02to update based on moveSpeed. You can see here in the updateSpeed method.
02:10Below calling updateSpeed we'll add the SpeedUp movie clip to the stage.
02:15That's inside of the Game movie clip, and that's just a simple animation that
02:20says speed up and it scrolls up on the screen.
02:23If you want to see what it looks like you can go to the FLA file and in the
02:27Library just double-click SpeedUp the movie clip, and then I'll just expand the
02:33Timeline and just click-and- drag to preview the animation.
02:37So it basically just slides up and that's it.
02:43It's off on the first frame where there is a stop action and then the animation
02:47just comes in and goes up.
02:48After it gets to the last frame, it goes back to the first frame where it's invisible.
02:53So we'll go back to Game.as and we'll show the SpeedUp movie clip.
02:58So type addChild and in parentheses pass-in speedUp_mc, because we want this
03:07to be in front of everything else, and then we're going to have the movie clip play.
03:13So speedUp_mc.play and some parentheses and a semicolon and that's it.
03:23So, you could save the file and test it, and in order to see the speed up
03:28happen, you'll need to get at least 10 trashcans that you jumped over.
03:33So to make things easier for the example in this movie I'm going to change the
03:3910 to a 2, so we'll only have to jump over 2 trashcans just to make sure this works
03:44and if it works we'll just change it back to 10.
03:47All I do that because it may take me a few tries to jump over 10 trashcans
03:52in the Flash Player.
03:53So let's save the file and test the movie.
03:57(Music playing)
04:02Now you've got to jump over at least 2 trashcans to see it speed up. So here we go.
04:09There is one and then here we go!
04:14All right, see there is the speed up movie clip.
04:18So if I jump over one more, it should happen again and should get a little bit faster.
04:26Looks great!
04:27So if you want to change that, you can change the number and you can have it
04:31speed up based on whether the score is in multiple of 2, 3, etcetera.
04:35I'll change it back to 10 and save the file.
04:41Another thing to note is that if moveSpeed is increasing by too much or too
04:45little every time the game speeds up, you can simply modify this number right here.
04:50So you multiply moveSpeed by whatever you want.
04:531.2 to increase it by 20%, or 1.05 to increase it by 5% each time.
05:00Since the updateSpeed method sets all the movement to be proportional, updating
05:05the speed is simply a matter of changing the moveSpeed property's value and then
05:10calling the updateSpeed method.
Collapse this transcript
5. Testing, Debugging, and Publishing Your Game
Acquiring testing certificates and provisioning profiles
00:00Before you can play your game on an actual device, you'll need the
00:03appropriate credentials.
00:05On a Mac, this is a pretty straightforward process that you can do using one of
00:09the built-in applications on your computer.
00:11If you have a Windows computer you can still do this, but just know you'll have
00:15to enter some command line code.
00:18I explained how to do all of that in my Flash CS5 Essential Training title in
00:24the Online Training Library.
00:26So for now, let's look at the Mac side of how to do it.
00:29First you'll need to open up Keychain Access.
00:32Keychain Access can be found in the Utilities folder within your Applications
00:37folder on your computer.
00:38So once you're in Keychain Access, you'll need to have downloaded and installed
00:43your certificates from Apple.
00:45This is talked about in Bill Weinman's course about publishing iOS applications.
00:53So you'll need to get a provisioning profile and a developer
00:57distribution certificate.
00:59Here I am working with a developer certificate.
01:02When you're in Keychain, you want to select the login keychain and then click on
01:07My Certificates at the bottom.
01:09When you click on My Certificates, you can find your development certificate and
01:14click the arrow to expand it.
01:16In there you'll see a key and you can right-click that key and choose Export.
01:22When you export the key, you can choose a file format.
01:26In this case Flash requires a p12 file. So save that file.
01:31You can call it anything you want.
01:33Just remember where you saved it and the name and everything.
01:37Click Save, create a password.
01:39You'll have to remember this password because Flash is going to ask you for it
01:43later on, and then just click OK.
01:46Your computer may then ask for an administrator password.
01:49So put that in and now I have my key.
01:54So in Flash asks for the p12 file I'll just simply link to that file.
01:58So once you have the development certificate and a provisioning profile, you're
02:03ready to prepare to test your game on an iOS device.
Collapse this transcript
Troubleshooting performance issues
00:00The Adobe web site has a document about optimizing iOS applications that
00:05you create in Flash.
00:07In this movie I'd like to point out two of those performance optimization
00:10techniques that you can use to increase the performance of your apps.
00:14The first one is to not use Alpha.
00:17When you're creating an application for iOS, don't use the Alpha slider in Flash.
00:23If something must be partially transparent, then make sure it's saved as a .PNG file
00:29with that partial transparency, then use it as a bitmap graphic in Flash.
00:35I've noticed a significant decrease in performance when I try to do things like
00:40fade an object in or out.
00:41So just make sure that you're doing that as bitmap images and not through Flash.
00:46The second thing is that you can actually cache a vector object as a bitmap.
00:52You may have heard of the cache's bitmap property that you can use to optimize
00:57fast-moving vector graphics.
00:59You can do the same in your iOS games but the code is a little bit different.
01:03Because my application here is using all bitmap graphics, I am not going to save
01:09it into the application, but I am just going to show you how to write the code.
01:12You're going to use the Matrix class, so make sure you import that into your application.
01:17Right below my score SharedObject, I'll create a new private property and I am
01:23going to call this mat, short for Matrix, data type it to a Matrix, set it
01:30equal to a new Matrix.
01:32Now actually for this exercise you don't really need to know anything about the Matrix class.
01:39If you want to find information about it, you can look it up in Flash Help or
01:42look up caching objects as bitmaps in Adobe's iOS Application document.
01:48So I'll scroll down to the constructor and at the top of the constructor,
01:53I'll write some code.
01:55I'll type boarder_mc.cacheAsBitmapMatrix. I'll set that equal to the matrix that
02:08we created as the property, so mat.
02:11And on the next line I'll type boarder_mc.cacheAsBitmap = true.
02:21Now if this were a vector graphic and if there were not more than one frame
02:27in the Timeline of boarder_mc, this could greatly enhance the performance of my applications.
02:33But from testing that I did initially I found that these graphics worked better
02:37as bitmap images, so I use them as bitmap.
02:39So this code actually doesn't really do anything to increase the performance in my game.
02:43So just keep that in mind if you want to increase the performance of your vector
02:48graphics, create a matrix and apply it to the cacheAsBitmapMatrix property of
02:53your object, and then set the cacheAsBitmap property to true.
02:57Again this does not work well if you have a movie clip with multiple frames.
03:01So a single frame movie clip that's completely vector, you can use this code to
03:07optimize your games.
03:08I am going to delete this code now and save the file.
03:15And what I want you to take out of this again, is that when you create a game
03:18target for iOS in Flash, make sure you're not using the Alpha sliders in Flash
03:24on any objects, and you can increase the performance of single frame vector
03:29movie clips by caching them as bitmaps.
Collapse this transcript
Finalizing code, adding an icon graphic, and setting a loading graphic
00:00Now we'll finish our game by finalizing the rest of the code, adding the icon
00:06images, and the default loading graphic.
00:09To finalize the code I am simply going to uncomment the comments where the code
00:15is disabling the volume while you're playing the game.
00:20So I am going to uncomment those two lines in the startGame method of the Sk8bit class.
00:25I'll save the file, and do a test.
00:30(Music Playing)
00:38And I can confirm that the volume is quieter when you're playing the game and
00:43now it plays while you're actually playing the game.
00:45So let's go to the FLA file and now we'll set the icons.
00:50Remember your app needs to have a few icons assigned to it so that it doesn't
00:54have a white icon on your device or in the App Store.
00:58Assigning the icons is a pretty simple process.
01:01Go to the main Timeline of your FLA and open up the Properties panel.
01:05In the Properties panel, click iPhone OS Settings.
01:10In there click the Icons tab. So you need three icon files that are PNG files,
01:16one that's 29x29 pixels, one that's 57x57, and one that's 512x512.
01:22You can create these icons in Photoshop or any graphic application of your choice.
01:27I actually created these in Flash.
01:30So just move around the artwork and export it as a PNG file if you want.
01:35So select the icon file that you want to set and then click the folder icon and
01:41go to the 29 image and do the same thing for 57 and 512.
01:46So I can click the icons in Flash and that's it.
01:55That's all you have to do to set the icons.
01:57Now what we do is set the default PNG file to show while the application is loading.
02:04Now that image is a slightly different story.
02:07I am going to go to the Finder on my computer. Now I am going to select
02:12Default.png and press the Spacebar to see a preview of it.
02:16Notice that it's in portrait orientation, or in other words I made it in
02:21landscape and I've rotated it 90 degrees clockwise.
02:25That's what you need to do for your loading graphic.
02:28Make sure the pixel dimensions are 480x320 Landscape and then rotate them so
02:33that they're Portrait.
02:34Of course if your game is Portrait then you just want to have a 320x480
02:39rectangle for your graphic.
02:41Name it Default.png. Back to Flash.
02:47Once you've created your default image, make sure it's in the same directory as
02:51your FLA file and then in the Included files section under the General tab,
02:56click the Plus button and select that file and click Open. So we have
03:07Default.png as our Included file.
03:10If you forget that then you won't have your default image show up because it
03:14won't be included when you finally publish your application.
03:18Another thing to note is that you want to include any other files that
03:22are loaded dynamically.
03:23So if you're loading audio while your movie is playing or you're loading
03:28graphics or anything, they need to be included here.
03:31So I'll just click OK and that's it.
03:34So we finished the game essentially.
03:36We've finalized the code, we've added the app icons, and set the default loading graphic.
03:42Remember that if you load any files in your app dynamically, you need to make
03:47sure to include those objects in the iPhone Settings window.
Collapse this transcript
Publishing the final version of the app
00:01Now we'll publish the app so that could test it on an actual device.
00:05I'll also show you the final way to publish your application for submission to Apple.
00:12In Flash open up the Properties panel and then click the Edit button next
00:16to iPhone Settings.
00:17Here you can choose the output file, and the app name, and the version of your app.
00:23Click the Deployment tab to tell Flash your certificate and your
00:28provisioning profile.
00:30So I have my certificate on the desktop.
00:32I am not including it with the exercise files for this course, because it won't
00:38work with your computer.
00:39You'll need your own certificate for that.
00:41So I'll check Remember password for this session, so I don't have to retype it
00:45if I ever come back to this menu.
00:47Then for a provisioning profile I'll click the folder icon and then choose the
00:52profile on my desktop.
00:54Again, this file will not work for you.
00:56So I am not going to include it in the exercise files for this course.
01:00Once you have all that set up, you can choose Quick publishing for device
01:04testing and click the Publish button.
01:07After you click the Publish button, Flash will begin publishing your app.
01:11This takes a few minutes with the testing version and a little bit more time if
01:16you're going to create your deployment version.
01:18Now before we test the app out, I want to point out the difference between this
01:24and the final version of publishing your app.
01:27So let's say your app is ready for submission to the App Store.
01:30You'll need to set everything up in iTunes Connect as you learned from
01:34Bill Weinman course.
01:36Also, you'll need to use a distribution certificate instead of the
01:41development certificate.
01:43You'll also need a distribution profile that's connected to your
01:48distribution certificate.
01:50This is all stuff that's covered in Bill Weinman's course about publishing iOS applications.
01:56When you set those here you also just want to click Deployment - Apple App Store.
02:02So if you make those changes and you click Publish, then you'll get the final
02:06version of your app which you can then submit to Apple.
02:08We'll look at the intricacies of doing that in another movie.
02:12But for now we have a version of our app that we can test on a device.
02:15So I'll just click OK and close that window and then I'll jump over to Finder.
02:21In Finder you'll see the Flash created an ipa file format.
02:25You're going to need to drag this into iTunes.
02:27You'll also need to drag your provisioning profile into iTunes as well.
02:31So let's tab over to iTunes and then tab back to Finder.
02:36Then I am going to first drag my provisioning profile into iTunes.
02:42Once you've done that, click- and-drag the ipa file into iTunes.
02:47So there you'll see the icon for the game and everything.
02:50Then select your connected device and click the Sync button.
02:53What you're looking for after you click the Sync button is no errors.
02:57You should see a message that iTunes is installing Sk8bit on your device and you
03:01shouldn't get an error.
03:02From there you can check to confirm that the application is indeed on your device.
03:09And that's it.
03:11So remember before publishing your app, you need to have the proper certificates
03:15and provisioning profile.
03:17For testing on your own device you can use a development certificate and profile.
03:21For publishing the app to the App Store you need to have a special App Store
03:26publishing certificate and profile.
03:30When you want to test your app on your device, you can drag the ipa and the
03:34provisioning profile into iTunes and simply sync your device.
03:38If you have any errors doing this process, go through all these steps and make
03:42sure you followed them exactly and that you have the proper certificate and
03:46provisioning profiles.
03:47that you're dragging the right files to the right place at the right time and
03:52everything should work.
Collapse this transcript
Testing on your iOS device
00:00Let's see what the game looks like on an actual device.
00:04I'll find the icon for Sk8bit.
00:07Notice it's the same icon that we set in our FLA file.
00:11So I'll tap the icon to launch the application.
00:14Notice the loading screen while the application loads and then you'll see the
00:18intro screen and hear the background music.
00:21You can tap the icon in the lower right corner to see the controls animation for the game.
00:27So that's a movie clip that's playing on an iOS device.
00:31Click the Start button to play the game.
00:34Note you can tilt back and forth to have the skateboarder move and you can swipe up and jump.
00:41Notice the sound that happens when you jump over an obstacle.
00:45You'll also see that you can have a high score for the game and it's all
00:49saved on your device.
00:51Notice that the score updates as you jump over trashcans.
00:56Notice that when you hit an obstacle, the animation plays, the sound fires off,
01:01and the game is over.
01:03So there is our game fully functioning on an iOS device.
Collapse this transcript
Submitting the app to Apple for release in the App Store
00:00The final step in creating an iOS game in Flash is submitting the game to the App Store.
00:06It may seem simple, but this step can be tricky if you don't follow it exactly.
00:11If you do anything wrong, then Apple will likely not accept your app.
00:15Before you start you're going to need two things.
00:18First you'll need an ipa file that's published from Flash using your
00:22distribution certificate and distribution profile.
00:25I am not going to include Sk8bit.ipa with the exercise files for this course,
00:30because I do not want you to submit this game to Apple.
00:34So you need to make your own game that's not Sk8bit and publish the game using
00:40your distribution credentials.
00:41So you should have an ipa file.
00:43The second thing that you need is an app called Application Loader.
00:48This is a Mac only application.
00:50So for this step you can't use a PC.
00:53You'll need to find a Mac to use to submit your game to Apple.
00:57You can download Application Loader through iTunes Connect.
01:01Of course, you need to make sure that Apple knows that your game is ready
01:05to submit the binary.
01:07So it needs to be in a state in iTunes Connect that says waiting for upload.
01:11Once you have all of those things prepared, select your ipa file and rename it
01:17so that the extension is .zip.
01:21Your computer will ask you if you're sure you want to rename the extension and
01:24I am going to choose Yes.
01:26Make sure it's a .zip file.
01:28Then I am going to unzip the file.
01:30Now this is very important.
01:32This will not work with a third- party un-archiving application.
01:37You need to use the OS X un-archiving app.
01:40So right-click and choose Open with Archive Utility.
01:46When the app is un-archived you'll see a folder called Payload.
01:50Expand that folder.
01:52Inside there you'll see your application.
01:55Right-click that and then choose Compress in the menu that pops up.
02:01So the zip file that I've just created is the file that I need to send to Apple.
02:07Now let's open Application Loader.
02:09So I'll go to my hard drive, go to the Developer folder.
02:13In there find the Applications folder.
02:16In the Applications folder, open up the Utilities folder and in there
02:21launch Application Loader.
02:25You maybe asked to login with your iTunes Connect credentials and I've already done that.
02:29So it's just asking me to choose an application.
02:31So I am going to choose Sk8bit 2.0, which is what I set up in iTunes Connect,
02:38and I'll click Next.
02:39I'll confirm that I've tested this on iOS 4.
02:44Then I'll click Choose to choose the file to upload.
02:48In the Payload folder, I'll select Sk8bit.zip and then click Open.
02:55Then I'll click Send to send the file to Apple.
02:57So usually if you get to the point that it says it's Authenticating with the
03:03iTunes Store, you're in good shape and it's going to upload.
03:07You may see an error like unauthorized code sign or something.
03:12That means that you didn't use the correct distribution certificate or profile.
03:17So you make sure that you're using a distribution certificate and profile.
03:22If you've done everything correctly you should see at the end Uploaded package
03:25to the iTunes Store.
03:27Again, please do not upload Sk8bit.
03:30Upload your own game to the iTunes Store. And you can click Next and then you'll
03:35get a notification that you've successfully sent your application to Apple and
03:40then you'll hear back from Apple through email once the application is approved.
03:44So I'll click Done and the game is now in Apple's hands for review.
03:48So again, if your app has the proper credentials and you follow these steps
03:53precisely, you should have no problem submitting your game to Apple.
Collapse this transcript
Conclusion
Goodbye
00:00Well you've now reached the end of this course.
00:03I hope you had a good time building that application and that you learned a lot
00:07about developing iOS games with Flash CS5.
00:12If you have questions about publishing content to iOS or find that you're having
00:16problems publishing your applications, be sure to check Adobe's FAQ and forums
00:22about the Flash Packager for iPhone.
00:24If you make a game using what you learn in this course, I would love to check it out.
00:28You can contact me through Twitter at asktodd.
00:31I'll see you next time!
Collapse this transcript


Suggested courses to watch next:


Flash Professional Power Shortcuts (2h 13m)
Todd Perkins


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked