navigate site menu

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

Flash CS3 Professional: Creating Games for the Wii
Don Barnett

Flash CS3 Professional: Creating Games for the Wii

with Todd Perkins

 


The Internet Channel web browser for the Nintendo Wii supports Flash content, which means anyone can create games that take advantage of this console's intuitive and approachable controls. The Internet Channel only supports Flash 7, so not every modern Flash game will work. The strengths and limitations of this platform, as well as the limited input that can be detected from the Wii Remote, should be considered when creating a game. In Flash CS3 Professional: Creating Games for the Wii, Todd Perkins shares his insights on all aspects of this development process. Speaking to those with some experience in Flash CS3 and ActionScript, he demonstrates the creation of several complete games. Each game is focused on a different mode of interactivity: point-and-click, up-and-down, circular, and velocity-based. Example files accompany the course.
Topics include:
  • Creating a Wii game template in Flash Migrating to ActionScript 2.0 from ActionScript 3.0 Animating onscreen objects Determining hits and discarding destroyed objects Adding enemies and player interactivity Scrolling a background Winning and losing

show more

author
Todd Perkins
subject
Developer, Games
software
Flash Professional CS3
level
Intermediate
duration
2h 48m
released
Jul 18, 2008

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:00Hi, I'm Todd Perkins. Welcome to creating Flash games on the Wii.
00:04I'm going to walk you through the process of creating Flash content that's playable on the Nintendo Wii,
00:09through the Internet Channel.
00:11Creating Flash on the Wii is a very exciting topic
00:14and I absolutely love teaching about it.
00:16In this title, we'll learn how to detect left and right, up and down, point and click,
00:21and circular interactivity from the Wii Remote. You'll also be able to mimic velocity-based interactivity. Using those
00:27techniques, we will even create several games from start to finish.
00:31So, hope you are excited to learn about creating Flash games on the Wii because I'm sure excited to teach it. So, let's get started.
Collapse this transcript
Using the example files
00:00If you are a premium subscriber to lynda.com or if purchased this title on a disk,
00:05you have access to the exercise files.
00:07Exercise files in this title are organized by chapters.
00:11Each chapter contains the files that we will be working with for that chapter.
00:16The files are in order according to movie number.
00:19For example,
00:20for movie 2 the file begins with 02 or for movie 3, the file begins with 03. Final states for each exercise file are also provided
00:29and they all end with _final. If you don't have access to the exercise files, you can still follow along.
00:35Throughout the title, I will show how you can set up your files, so that they will be the same as the files that I'm working with. So,
00:41let's get started.
Collapse this transcript
Prerequisites for this course
00:00Now before you dive into start creating Flash Wii games, you should know that this is sort of an advance title and I expect you
00:06to know some of the things coming into it. Here are the titles that I expect you to have watched
00:11or at least have the equivalent knowledge of.
00:13First, Flash CS3 Fundamentals.
00:16If you haven't watched Flash CS3 Fundamentals,
00:19you should have at least watched Flash CS3 Essential Training. So you should basically understand
00:24the basics of the Flash interface,
00:26including movie clips structure, layers, and how to work with the Time Line.
00:31ActionScript 2.0 Essential Training, it would be ideal for you to have watched ActionScript 2.0 Essential Training,
00:37but since we're working in Flash CS3,
00:39it is more likely that you have watched ActionScript 3.0 Essential Training, which will also do.
00:44Just know that creating Flash Wii games uses ActionScript 2.0,
00:48so there is going to be a little bit different syntax.
00:51In this title,
00:52I have set up chapter 2 as a sort of a crash course in ActionScript 2.0 for those of you who already know ActionScript 3.0
00:59and for those of you who already are familiar with ActionScript 2.0,
01:02chapter 2 will be a review for you.
01:04So basically coming into this title, you should have a basic knowledge of Flash
01:08and you should have a basic knowledge of ActionScript. So you should be familiar with variables, functions, and events.
01:13As we go through the title,
01:15I'm going to speak as if you already know what these things are and I won't go into detail
01:19explaining the structure of the code, we will quickly go through the code and add interactivity that we are going to use and
01:25create the games that we are going to be creating. So if you don't feel comfortable with Flash or ActionScript, I recommend watching the titles
01:30that I have listed here. Otherwise, let's get started in creating some Flash Wii games.
Collapse this transcript
1. Getting Started with Flash on the Wii
Playing Flash on a Wii
00:01If you're watching this title,
00:02chances are you already know how to make Flash applications,
00:05but you may not know how Flash works on the Wii. Getting the applications that you develop on the Wii is actually incredibly simple.
00:12There are only two steps that need to be taken from the Wii to view Flash content.
00:16The first step is to download the Internet Channel.
00:19You can download the Internet Channel from the Wii Shop Channel for 500 Wii points or $5. The Internet Channel is made by
00:25Opera and is a simplified version of the Opera Web browser for your computer.
00:30One of the features of the Internet Channel is that it has Flash Player support built-in.
00:34The version of the Flash Player it supports is Flash Player 7. So you can view Flash Player content up to player 7
00:41and ActionScript up to version 2.0.
00:44The second step you need to take
00:46is simply browse through a site that has Flash Player 7 or earlier content.
00:50If you like to see Flash content on the Wii right now,
00:53you can use the Internet Channel on your Wii to browse through youtube.com
00:56and watch YouTube movies from your Wii.
00:59YouTube uses Flash Player 7 for its video player.
01:02On the Wii, the Wii Remote works exactly the same as the mouse and the A button on the Wii
01:08acts as a mouse click. Well that means to you as a developer
01:11is that you don't have to make any changes to your applications in order to make them work on the Wii.
01:16You simply create Flash Player 7 or earlier mouse-based applications
01:21and that's all there is to it.
Collapse this transcript
Creating a Wii game template in Flash
00:00Now we will create a Flash Template, so we can create Wii games quickly.
00:04If you are following along, I'm working in 02_template.fla in the chapter 01 folder.
00:09If you don't have access to the exercise files, just create a blank .fla file ActionScript 3.0
00:14and create a layer called actions and a layer called art.
00:17The first thing we are going to do is set the resolution for our Flash movie.
00:21We are going to click to Size button in the Property inspector and set the dimensions to 790 x 610.
00:28This is a resolution that will work on every television monitor.
00:32For the Frame rate, I will type 24 frames per second.
00:35Flash content on the Wii needs to be really optimized and will run slow
00:40if you set a Frame rate higher than 24 frames per second.
00:43So just keep that in mind.
00:44I'm going to click OK and then we will click the Publish Settings button
00:49in the Property inspector and go to the Flash tab.
00:53From there I will set the version to Flash Player 7, the ActionScript version should be ActionScript 2.0,
00:59then I'm going to jump over to the HTML tab and go down to the Scale area and set the Scale mode to No scale.
01:06That way your content will look exactly the same whether
01:08or not if the person viewing the content is on a wide screen television.
01:13Then we click OK to save those Publish Settings, and that's really all there is to it.
01:17Now we will just save this file as a template, so we can use it easily later on.
01:20I'm going to choose File, Save as Template and for the name I'm going to call it Flash Wii,
01:28for the Category, I'm going to type Games.
01:31Now if you don't have a Category called Games, Flash will automatically create this Category for you.
01:36For the Description I'm just going to type the resolution, which is 790 x 610, now on the next line,
01:43I'm going to type Flash Player 7 and then ActionScript 2.0.
01:47Now, I will click Save to save the template and now what I'm going to do is close this file and create a new file
01:53from our template to make sure everything is working ok.
01:56So in the Create from Template area of the Welcome screen, I'm going to click the More button and then I'm going
02:01to click the Games category and you can see that I have my Flash Wii template right there
02:07and my description is the same description I just typed in, so I will click OK and there is the file from our template.
02:12So, if you already know ActionScript 2.0 or just want to see your own Flash animations on your Wii,
02:18you can simply use this template, create your Flash content as normal, upload it to the web just as you normally would
02:25in any other Flash application and browse to its location on your Wii.
02:29For those of you who aren't very familiar with ActionScript 2.0, in the next chapter, I will explain the basic elements
02:35of ActionScript 2.0 that you will need to create Flash Wii games.
Collapse this transcript
2. ActionScript 2.0 Essentials
Knowledge prerequisites
00:00Due to the complex nature of this title,
00:03I expect you to know a few things about Flash and ActionScript before coming on board.
00:07Here is a look at what I expect you to know.
00:09I expect you have a basic knowledge of the Flash interface including how Timeline works,
00:14how movie clips are structured and how they can be organized, and other basic elements of the Flash interface.
00:20Basically, I expect you to know at least what's contained in the Flash CS3 Fundamentals title in the Online Training Library.
00:28You should also have at least a basic knowledge of ActionScript 2.0 or
00:32ActionScript 3.0.
00:34This includes understating variables, functions, loops, events, etc.
00:38If any of these terms seem foreign to you, I recommend watching ActionScript 2.0 Essential Training
00:44or ActionScript 3.0 in Flash CS3 Professional Essential Training in the Online Training Library.
00:50You should have an understanding of how Flash applications work and how to build them from scratch. That means you should know
00:56how variables, functions, loops, and events,
00:59all work together to create an application
01:01Again, if you don't feel comfortable with Flash or ActionScript,
01:04I definitely recommend watching the titles I mentioned earlier,
01:07but if you do feel comfortable,
01:08this chapter is going to be a refresher for those of you who already know ActionScript 2.0
01:13and ActionScript 3.0,
01:15focusing on the differences between the two languages.
Collapse this transcript
Migrating from ActionScript 3.0
00:00Let's talk about some of the differences between ActionScript 2.0 and ActionScript 3.0.
00:05Some of the main differences include Display Objects and the Display List, Properties,
00:09Classes and Data Types, Event Handling, and the use of Keywords.
00:13Display Objects are significantly different from ActionScript 3.0,
00:17for example MovieClip is the main display object container class
00:21and for that matter, it's also the main display object class.
00:24So we do have classes like Shape or Sprite or DisplayObjectContainer or Display Object, etcetera.
00:30You simply use MovieClip for just about every display object.
00:34There is also a different display list.
00:36Depths are not organized in the same Child way that they are in ActionScript 3.0,
00:41rather they are controlled using methods of MovieClips like getNextHighestDepth and a few others.
00:47In addition, when you create a MovieClip dynamically, Flash doesn't automatically creates a Depth for that MovieClip,
00:53you need to manually tell Flash the Depth of the new MovieClip.
00:58Properties are not very different in ActionScript 2.0, but this tends to be the biggest area
01:04of running into problems because it's so subtle.
01:08Property names typically begin with an underscore, so we have _alpha instead of alpha and so on.
01:14Property values range between 0 and a 100 instead of from 0 to 1.
01:19Like I said these are the most common pitfall for people going between ActionScript 2.0 and ActionScript 3.0.
01:25So remember that your Properties have underscores and your Property values go from 0 to a 100 in ActionScript 2.0.
01:33Creating instances of classes is pretty different in ActionScript 2.0, for example Display Classes
01:38like MovieClips, Text Fields etcetera are not created using the new Keyword rather they are created using MovieClip
01:45class methods like createEmptyMovieClip, duplicateMovieClip, and attachMovie.
01:50So we don't have the addChild method to create objects, and there is no addChild method to add objects to the stage.
01:58When using void for a return value and functions, the ActionScript 2.0 Void has a capital V.
02:03For Number Data Types, ActionScript 2.0 does not have support for int and uint Data Types,
02:09so the only Number Data Type in ActionScript 2.0 is the Number Class.
02:15Event Handling is significantly different in ActionScript 2.0.
02:18Instead of being done through adding listeners, it's done through properties.
02:22Most properties begin with on, so instead of MouseEvent.Click,
02:26we have the onRelease property or the onPress property.
02:31Values for these properties are functions and the functions or the listeners for the event.
02:37So when onRelease event happens, the function connected with that property is triggered.
02:43The keywords _root and this are different in ActionScript 2.0 as well.
02:47For example _root has an underscore instead of just being root and it always refers to the main Timeline.
02:54The use of _root is discouraged because it can change it's meaning.
02:58This is only in cases when you are loading external .swf files.
03:01Since we won't be doing that in this title, we will use _root to represent the main Timeline.
03:06The this Keyword is pretty different in ActionScript 2.0 as well.
03:10It's relative, so it represents the container that the word this is held within and instead
03:15of an event handler it works the same as a event.currentTarget does in ActionScript 3.0.
03:20So it represents the objects that's connected with that event.
03:24Outside of event handlers and outside of methods, the this represents the object where the word this is contained.
03:32For example in side of a MovieClip, this represents that MovieClip.
03:37On the main Timeline, this represents the main Timeline.
03:40So this is a look at some of the basic differences between ActionScript 2.0 and ActionScript 3.0.
03:46For more information, you can look at Flash help in the ActionScript 2.0 language reference.
Collapse this transcript
Working with variables and properties
00:00Now, we will take a look at writing the code for variables and properties in ActionScript 2.0.
00:05If you are following along, I'm working in 03_Variable_Properties.fla in the Chapter 02 folder.
00:11If you don't have the access to the exercise files,
00:13simply create a file from the Flash Wii template
00:16and create a MovieClip on the stage, name cow_mc.
00:20Also create a layer called Actions.
00:23Let's go to the first keyframe in the Actions layer
00:25and open up the Actions panel.
00:27Let's say I wanted to create a variable to hold the cow's alpha.
00:31I'm going to call this cowAlpha
00:33and remember in ActionScript 2.0, the only number data type is Number, so we don't have int or uint.
00:39Remember that alpha is 0-100 and not 0-1.
00:44So if I wanted to set the alpha to 50%,
00:47it would be 50 instead of 0.5.
00:49On the next line, I will set the alpha of the cow,
00:52cow_mc._alpha.
00:54Notice that I'm using an underscore and not just alpha.
00:58The one big mistake when people are coming from ActionScript 3.0 to ActionScript 2.0
01:03is to omit the underscore here.
01:05This is really tough because alpha is the keyword in Flash CS3 because it's a keyword in ActionScript 3.0,
01:11and ActionScript 2.0 doesn't have as good error handling, so you won't get an error if you try to set the alpha property of an object.
01:19So remember to keep that underscore there.
01:21I'm just going to set the alpha property here equal to cowAlpha.
01:25Now I will test the movie
01:26and see the cow's alpha,
01:29and there is our cow with 50% alpha.
01:31I will close the Preview window now.
01:33So when you are working with variables,
01:35make sure that you use the Number data type for numbers and remember to add the underscore for properties
01:40and that values tend to range between 0 and a 100.
Collapse this transcript
Understanding functions
00:00Now, we will take a look at writing the code for functions in ActionScript 2.0.
00:04If you're following along you can open up 04_Functions in the Chapter 02 folder
00:08or just use the same file from the last exercise.
00:11Let's go to the first keyframe in the Actions layer
00:13and open up the Actions panel.
00:15What we are going to do is wrap the code we have here
00:18in a function.
00:19So I'm going to create a standard function, I'm going to call it setCowAlpha.
00:26This is not going to return a values it's going to be Void and remember that it has a capital V
00:31and I'm going to run this setCowAlpha function at the bottom of my code.
00:38So you can see it's very, very simple, we have pretty much the exact same syntax for creating a function
00:43other than the fact that Void has an uppercase V. So if I test the movie,
00:47you can see that it's working.
00:49There is also another way to write functions in ActionScript 2.0 and that is to give the value to a variable so we
00:56can type setCowAlpha
00:59equals function,
01:01and that works as well.
01:06So that's how our functions work.
01:07So for the most part in ActionScript 2.0 functions are the same.
Collapse this transcript
Handling events
00:00In this movie we will write the code to handle Events in ActionScript 2.0.
00:04If you are following along you can open up 05_Handling_Events.fla in the Chapter 02 folder
00:10or you can just use the same file from the last exercise.
00:13Let's go to the first keyframe in the Actions layer
00:15and open up the Actions panel.
00:17As I mentioned earlier in this chapter,
00:19events are handled using properties instead of the addEventListener() method. So let's say I wanted something to happen
00:26when I clicked on the cow. I would type co_mc.onRelease
00:31and we can use one of our methods for writing functions
00:34and set the value of the onRelease property
00:37equal to a function that we created right here.
00:43So I just create my function right here and let's say I wanted the cow to say
00:47Moooooo,
00:51so I will test the movie, click on the cow
00:53and then I get my Moooooo message in the Output window.
00:57So I will close the Output window and the Preview window
01:00and maybe you don't like that method of setting a function value inline like this, maybe you'd rather have a normal function,
01:08well you can do that, it's just fine. So I push this function code down
01:13and I created a function called moo.
01:18Now I could set the value of cow_mc.onRelease
01:21equal to moo.
01:22Notice I'm not using parenthesis here after moo or else that would moo the return value of the function, which is Void
01:30and the value of onRelease tends to be a function. So here I get the same result,
01:34it's just little bit cleaner in the code.
01:39So in ActionScript 2.0 you set the value of the event property equal to a function
01:44and it doesn't matter whether or not your function is an inline function.
Collapse this transcript
Understanding "this" and "_root"
00:00Now let's take a look at the keywords this and root.
00:03If you are following along I'm working in 06_this_and_root.fla in the Chapter 02 folder
00:08or you can just use the same file from the last exercise.
00:11Let's go to the first keyframe in the Actions layer
00:13and open up the Actions panel.
00:16Here I have emptied out the moo function.
00:19 Now we will take a look at the value of this versus _root.
00:23As I mentioned earlier _root represents the main Timeline. So inside of the moo function
00:29if I trace _root
00:33and click on the cow, if I tested the movie then I get _level0 in Output window.
00:38_level0 represents the main Timeline.
00:40Essentially levels are depths.
00:42For more information about levels,
00:44you can look at Flash Help.
00:46So now let's say we trace(this)
00:48inside of the function.
00:50Let's see what we get.
00:52We get _level0.cow_mc so it's a reference to the cow.
00:57Because this function is attached to cow_mc through its onRelease property,
01:03this is referring to cow_mc.
01:07So if were to cut and paste this trace statement
01:10outside of this function
01:12then I would get the main Timeline. So we are going to press Cmd+X on the Mac or Ctrl+X on the PC to cut,
01:17Cmd+V on the Mac, Ctrl+V on the PC to paste.
01:21So now when I test the movie,
01:23in the Output window I get _level0.
01:25So you can see that this is relative but depending on its context.
01:29In a function that's attached to an Object like our eventhandler here,
01:34this represents the Object that the function is attached to
01:38and outside of functions and methods,
01:41this represents the object where the code resides,
01:44in this case the main Timeline.
01:46Now if I were to put this trace statement inside of cow_mc
01:51then this would represent that instance of cow_mc.
01:55So that's how this and _root work in ActionScript 2.0.
Collapse this transcript
Creating movie clip instances dynamically
00:00Common thing to do in games is to create movie clip instances dynamically,
00:05that is to bring them out of the library and on to the stage at runtime.
00:08In this movie we will talk about how to do that using ActionScript 2.0.
00:12If you are following along I'm working in 07_Movie_Clip_Dynamic.fla in the Chapter 02 folder
00:18or you can just use the same file from the last exercise, just make sure to delete the cow off the stage.
00:23The first thing we will need to do to create movie clip instances dynamically is to tell Flash
00:28to export this movie clip for ActionScript.
00:31So I'm going to right click on mcCow in the library,
00:34Ctrl+Click if you don't have a right click on your mouse, choose Linkage.
00:37From there, all you need to do is check Export for ActionScript.
00:42The difference between ActionScript 2.0 and 3.0 here is that we use the Identifier instead of a Class text field
00:49to export our movie clip for ActionScript.
00:51Now you can still use Class if you wanted to connect a movie clip to a Class but that's not what we are doing right here.
00:56Also, make sure not to change the identifier name, so it's the same as the name inside of the library.
01:02That way you can simply glance over the library to know the identifier name of your movie clip.
01:06So click OK, go to the first keyframe in the Actions layer and open up the Actions panel.
01:12The method that you use to create movie clips dynamically is attachMovie.
01:16So I'm going to type _root referring to the main Timeline _root.attachMovie, then you need to pass in some parameters.
01:25This is the identifier name associated with your symbol in the library.
01:29Next, is the new name, which is also a string and this is the instance name for the object that's being created.
01:36I'm going to call this cow_mc, the next parameter is depth, in this works like addChild,
01:43except for we need to explicitly tell Flash what depth we want the object to be created at.
01:48So I'm going to type _root.getNextHighestDepth and that's the method
01:54and that returns the next highest unoccupied depth.
01:58Using getNextHighestDepth we put the Object in front of everything else inside
02:03of its parent, which in this case is _root.
02:07Now I close out the parenthesis and let's test the movie and there is our cow, nice.
02:16Let's go to the next line and then from here what we can do is modify our movie clip in whatever way we want.
02:24I'm going to call it by its instances, so I can just type cow_mc.
02:27Notice that it's not a string here, I'm using sort of like a variable name and I can type .
02:34_x and set that to some value here.
02:36So let's say I set it to a 100 and I test the movie, I can see the cow has shifted to 100 pixels to the right.
02:43That's how to create movie clip instances dynamically.
02:46If you'd like to take a look at more methods for creating movie clip instances dynamically you can look
02:51up Create Empty Movie Clip and Duplicate Movie Clip in Flash Help.
Collapse this transcript
Initializing dynamically created movie clips
00:00When you create movie clips dynamically you can associate them with objects
00:06and have them adopt properties, methods and events of those objects.
00:10In this movie we will take a look at how to do that.
00:12If you are following along I'm working in 08_Initializing_Movie_Clips.fla in the Chapter 02 folder.
00:20You can also use the same file we worked with in the last exercise.
00:23Let's go to the first keyframe in the Actions layer and open up the Actions panel.
00:27Above all the code that I have here I'm going to create a new variable and this is going
00:31to be a generic object, so an instance of the object Class.
00:35I'm going to call this init.
00:37So I'm going to create a new instance of the object Class and I'm going to cut
00:44and paste where I set the cow's x position, cutting with Cmd+X, Ctrl+X on the PC,
00:51pasting with Cmd+V, Ctrl+V on the PC.
00:55Now I'm going to set the init object's _x property to 100.
01:00Now when we ran the attachMovie method, you may have noticed
01:03that in the code hinting there was an optional parameter called init.
01:08What you do is pass in your initialization object after the depth in the attachMovie Method.
01:15So I'm going to pass in my initialization object and once this cow_mc instance is created,
01:23it adopts all of the properties and methods connected to init.
01:27So if I test the movie, I will see that the cow adopts the x position of a 100 from its initialization object.
01:36So if I go to the next line below where I set its x position, I could set the init's y position equal
01:43to a 100 as well, to show you that, that works.
01:47Now why on earth would you ever want to do something like this?
01:49Let's say we are going to create a ton of movie clips in a huge loop and we want them all to have the same properties.
01:55we can create one init object and have all those movie clips adopt from that object.
02:00This doesn't just work with properties, it also works with methods and events.
02:05So let's say I wanted to have an onRelease event, so I wanted the cow to move for example.
02:13I could set the init object's onRelease property equal to moo and I could create that moo function
02:21and then in my moo function I will just trace moo.
02:29Test the movie, click on the cow and I get moooooo in the output window.
02:33So now I could create 100's of cows and they would all adopt the same properties
02:38as long as I passed in the init object here.
02:41So that's how to initialize movie clips using an init object.
02:44We will talk about this more in detail and these more advanced techniques with init objects
02:49as we go throughout this title and that's how we use this technique in applications.
02:53So now you can initialize dynamically created movie clips with whatever properties, methods or events that you want.
Collapse this transcript
Using the TweenLite engine
00:00For games we are going to be doing a lot of ActionScript animation, mostly in fading things in and out.
00:06Now we could write the code by hand that's a little bit tedious and we could use the built in ActionScript Tweens,
00:12but that's a little code heavy and tends to run a little bit slow.
00:15What I have choosen to do for these games is use an engine called TweenLite.
00:19The TweenLite class has great syntax and it enables to do ActionScript Tweens very powerfully, easily and quickly.
00:27In this movie we will have an intro to the TweenLite class and how to use it in your applications.
00:32If you are following along I'm working in 09_TweenLite.fla in the Chapter 02 folder.
00:37You can also just use any file with a movie clip instance on the stage.
00:42In this file the movie clip instance is called cow_mc.
00:44In order to use the TweenLite engine, you need to download it from tweenlite.com.
00:51I'm going to jump over to Firefox right now, going to tweenlite.com will take you
00:58to the ActionScript 2.0 version of Tween Lite.
01:01You will see that there are two links, one to download the class and one to donate.
01:06You don't have to make a donation to download the class but you can make a donation if you find the class very useful.
01:11Click download now to download the zip file, and once you downloaded the file,
01:15unzip the file to reveal the TweenLite folder.
01:18I'm going to jump over to my desktop now where I have already downloaded and unpacked the TweenLite class.
01:25The TweenLite folder contains two folders and some files, the folder that we are mostly concerned
01:30about is the gs folder, this contains the TweenLite class, TweenLite.as.
01:35So I'm going to select the gs folder, copy using Cmd+C on the Mac or Ctrl+C on the PC and paste the file
01:42to my desktop using Cmd+V on the Mac, Ctrl+V on the PC.
01:45From there I will open up the Exercise Files folder, open up the Chapter 02 folder and drop the gs folder in there.
01:53Now we can use the TweenLite class.
01:54So I will jump over into Flash and in Flash I'm going to select the first keyframe
01:58in the Actions layer and open up the Actions panel.
02:01Now to use the TweenLite class, the first thing we will have to do is import the class.
02:05So I'm going to import gs.TweenLite and then we can tween using one line of code.
02:10TweenLite has two main methods and they are both static methods.
02:14The first method is TweenLite.to, TweenLite.to tweens an object's properties to the values that you pass in.
02:23Let me show you how it works.
02:25It accepts three parameters, the first parameter is the object that you are going to tween, which is cow_mc,
02:30the second parameter is the amount of time for the tween to take in seconds, so let's choose 2,
02:37the third parameter is an object and is used
02:40to tell the TweenLite engine what properties we want the object to end up with.
02:45We use object to tell the TweenLite engine, where we want the object to endup, so we give it different property values
02:51that it has now and the TweenLite engine tweens the object to those properties.
02:57For example if I wanted to fade out the cow, I will type _alpha and use Object Notation set to 0.
03:05Now if I test the movie, in two seconds the cow will fade out to an alpha to 0, you can pass in as many parameters
03:13as you want here and the TweenLite engine will change the values of those properties over time.
03:17So let's say I wanted to also change _x to 0 and _y to 0.
03:24If I test the movie all the properties tween at the same time.
03:29Now the great thing about the TweenLite engine is that I can do all of this with one line of code.
03:33With ActionScript Tweens that are built into Flash this would take the three separate tweens
03:38and it wouldn't run as fast.
03:39So that's just one of the reasons why I love the TweenLite engine.
03:42I mentioned earlier that there were two methods of the TweenLite class for animation.
03:47The other method is TweenLite.from, TweenLite.from works basically the same as TweenLite.to except
03:55for it tweens the object to its current properties
03:58from whatever the properties you pass in through the tween object.
04:01So instead of the cow animating to an alpha:0, x:0, and y:0,
04:06it animates from alpha:0, x: 0, y:0 to its current properties.
04:12If I test the movie, we will see that in action, I will close the Preview window.
04:18That's mostly all there is to the TweenLite class.
04:20You can see that the syntax is extremely easy and its very powerful, very fast and it only takes one line of code.
04:28There is actually a lot more that you can do with the TweenLite engine and you can look up that information
04:32on the TweenLite website or inside of the TweenLite class, where you will also find some great documentation.
Collapse this transcript
3. Flash for the Wii Essentials
Understanding the limitations of Flash on the Wii
00:00Developing Flash Wii games is great, but you have to understand the limitations of Flash Wii games before you start creating them.
00:07For example,
00:08you don't have access to all the features of the Wii Remote including the Accelerometer and the De-pad.
00:14Also you can only capture input from the A button. So essentially a Flash Wii game is just like a regular mouse game.
00:21So you can think of it in the same way.
00:22You can track or the cursor is,
00:25and when the user clicks.
00:27Another limitation is that the Wii Remote must always point at the screen.
00:31If someone playing your game rotates their Wii Remote, so it's not facing the screen anymore, then your Flash movie will
00:37lose focus and your game will no long to be playable, that is, until the player points their remote back at the screen.
00:44Lastly we have some graphical limitations,
00:47earlier I mentioned that you want to keep your frame rates between 12 and 24 frames per second.
00:51On top of that you want it be a little bit more safe when creating Flash Wii applications than you would for say,
00:57a computer. That means you want to go a little bit easier on bitmaps, gradients, audio and video.
01:03So with all of these limitations, it presents a lot of challenges as a developer of games.
01:08The purpose of this chapter is to work with these challenges
01:11and find creative solutions to mimic console Wii game interactivity in Flash.
Collapse this transcript
Creating simple point-and-click interactivity
00:00The simplest interactivity for the Wii is point and click. So, here we will pretend that we are making a game where you pop balloons.
00:07If you are following along, I'm working in 02_Point_Click.fla in the Chapter 03 folder.
00:12If you don't have access to the exercise files, you can simply create three movie clips and name them anything you would like. I called them
00:17balloon 1_mc, balloon 2_mc and balloon 3_mc.
00:21So, I'm going to go to the first keyframe in the Actions layer and open up the Actions panel
00:25and here I have an array of all the balloons and a loop where I set the onRelease property for each of the balloons
00:32equal to the balloon, click function
00:35and my balloon click function is really simple, it just runs the unloadMovie method on whatever balloon you click on.
00:41So, I'll test the movie,
00:43click on a balloon,
00:44and they unload.
00:47So Point and Click interactivity is extremely simple, it works exactly the same as mouse click interactivity.
Collapse this transcript
Adding up-and-down or left-and-right interactivity
00:00Another type of interactivity is detecting if the player of the game is moving their Wii Remote up and down or if they're
00:06moving their Wii Remote side to side.
00:08In this movie we will talk about how to capture that information and to use it.
00:12If you are following along I'm working in .fla in the Chapter 03 folder.
00:17If you don't have access to the Exercise Files, you can simply create a file based on the Wii template.
00:22Create a movie clip, that's a pump.
00:25One frame of the pump up and one frame of the pump down
00:29and a movie clip that's a balloon,
00:31that's just a simple graphic. I named the pump, pump_mc
00:35and the balloon, balloon_mc.
00:37In this file I also have a hidden layer called Buttons.
00:40In the Buttons layer there are two invisible buttons, one on the top called top_btn and
00:46one on the bottom called bottom_btn.
00:49These button control all of the interactivity for this application.
00:53Let's take a look at the code and see how it works.
00:55I'm going lock and hide the Buttons layer first
00:57then select the first keyframe in the Actions layer and open up the Actions panel.
01:01You see the code for this application is extremely simple.
01:05When you roll over the top button,
01:07the up function runs and when you roll over the bottom button, the down function runs.
01:12I'm stopping the pump at the beginning to make sure that it doesn't animate.
01:16The up function is very simple, it makes the pump go to its up state and the down function makes the pump go to its down state
01:22and scales up the balloon.
01:25That's really there is to it. If you test the movie
01:28and move your mouse up and down, you see that you are pumping up the balloon.
01:32I'm going to close the Flash Player window.
01:35Now if you wanted to do this with left and right motion then you can simply create a button on the left half of the screen
01:40and a button on the right half of the screen and change your functions accordingly.
01:44So you can see this process is pretty simply, but imagine actually playing this on the Wii.
01:48You are moving the Wii Remote up and down or moving your hand up down simulating moving a pump.
01:53So using this formula you can successfully capture
01:56a player of your game moving their Wii Remote up and down or left and right.
Collapse this transcript
Detecting Wii Remote rotation
00:00So let's say you wanted to detect circular motion from the Wii Remote,
00:03whether the remote is moving clockwise or counterclockwise.
00:07In this movie we will take a look at how to detect that information.
00:10If you are following along I'm working in 04_Rotation.fla and this is in the Chapter 03 folder.
00:16If you don't have access to the Exercise Files,
00:18simply create a wheel movie clip that's just a simple graphic and then create some invisible buttons.
00:25Let's take a look at the invisible buttons here.
00:27I'm going to unlock and unhide the buttons layer.
00:31You will see that there four buttons here.
00:34I'm going to use these buttons to detect the direction,
00:37if the person playing the game is rotating the Wii Remote or rotating the mouse.
00:42Now I have named these buttons tl, short for top-left tl_btn, top-right button,
00:48bottom-right button, and bottom-left button.
00:51So if I unhide my guide layer, it's going to show you how my little system works.
00:56I'm going to lock the Buttons layer here.
00:58I'm going to store all these buttons in an array, so I have Index 0, 1, 2, 3.
01:05Now let's say the person playing the gaming is moving their Wii Remote in a clockwise motion, so they are going to go
01:11from 0 to 1 to 2 to 3 and then back to 0.
01:15Whether they start from 0, 1, 2 or 3 that's the progression that they are going to move.
01:20So from 0 the next step is 1, from 1 the next step is 2, from 2 the next step is 3 and from 3 the next step is 0.
01:27For counterclockwise motion it's the opposite, the movement goes from 0 to 3 to 2 to 1 and then back to 0.
01:36So what we are going to do is create some simple conditional statements to check to see what the current button rolled
01:43over is based on what the last button the person rolled over was.
01:47So let's take a look at the code.
01:49Select the first keyframe in the Actions layer and open up the Actions panel.
01:52In the Actions panel I have some variables here.
01:55The first one is an array of all the buttons and they are in the order that I showed earlier.
02:01So top-left(tl_btn), topright(tr_btn), bottomright(br_btn) and then bottomleft(bl_btn).
02:05We have variables representing the currentIndex and previousIndex of the buttons that are rolled over,
02:10the direction that's being rotated in, this is going to be +1 for clockwise, -1 for counterclcokcwise.
02:17The speed at which to rotate the wheel which I just set at 10.
02:21I have a loop here, connected each button's RollOver event to the rotate function.
02:25The rotate function is where all the magic happens.
02:28The first thing is we set the value of currentIndex, to do that I used the function called indexOf to get the index
02:35of the button that was currently rolled over.
02:38You scroll down you will see the indexOf function, simply passed in a button, use a loop to see if the button
02:46in the loop matches the button that was passed in, if so return that button's index, if there is no match, return -1.
02:54So let's scroll back up to the rotate function.
02:57These conditional statements here check to see whether the user is moving the Wii Remote
03:03in a clockwise or counterclockwise direction.
03:06First we are checking to see if they are moving clockwise.
03:09The main general rule for a clockwise movement is if the currentIndex is equal to the previousIndex,
03:16so the index of the button that is currently RolledOver is equal to the index of the previously RolledOver button +1.
03:23So in this sense it's capturing from 0 to 1, or from 1 to 2, or from 2 to 3.
03:28Now of course we have the fourth scenario, which is from 3 to 0
03:32for clockwise motion, so we need to check for that as well.
03:34So we check to see if the currentIndex is 0 and the previousIndex is 3.
03:39If so the user is rotating the Wii Remote in a clockwise motion, so we set the direction to 1.
03:46Checking for counterclockwise motion is exactly the opposite, check to see if the currentIndex is equal
03:51to the previousIndex-1, so that would be 3, then 2, and then 1, and then 0.
03:57Then the exception is moving from 0 to 3, so we check to see if the currentIndex is 3 and the previousIndex is 0,
04:04if so the player is rotating counterclockwise so we set the direction to -1.
04:09After the calculations are made we take the datas of the index of the button that was currently rolled over
04:14and we hold it in our previousIndex variable, that way we can use it the next time a button is rolled over.
04:21Then we simply update the rotation of the wheel.
04:24I'm adding onto it in the value of the direction which is going to be 1 for clockwise, -1 for counterclockwise,
04:31times speed which at the top I set to 10.
04:34Now let's see the game in action.
04:36Test the movie, move the mouse in a circular motion clockwise, the wheel rotates clockwise.
04:44If you move the mouse in a circular motion counterclockwise, the wheel rotates counterclockwise.
04:50I will close the Preview window and that is how
04:52to capture circular motion whether it is clockwise or counterclockwise from the Wii Remote.
Collapse this transcript
Adding velocity-based interactivity
00:00Now we will look at adding one more element to our Flash Wii games and that's Velocity.
00:04Now let's say we wanted to make a balloon pumping game,
00:07but to make the game a little bit more exciting the balloon is constantly loosing air,
00:11so you have to pump extra fast to get the balloon pumped up in time.
00:14If you are following along, I'm working in 05_Velocity.fla in the Chapter 03 folder.
00:20The file is actually pretty simple, there is a pump, two frames up and down, it has an instance name of pump_mc,
00:27there is a balloon with an instance name of balloon_mc.
00:33Two buttons one at the top called top_btn and one at the bottom called bottom_btn.
00:38Then we go to the first keyframe in the Actions layer and open up the Actions panel, let's take a look at the code.
00:44Two variables, one called shrinkAmt and one called growAmt, shrinkAmt is the rate at which the balloon is shrinking
00:52and growAmt is the rate at which the balloon grows.
00:55I'm going to scroll down to the bottom of my code and take a look at what runs immediately.
01:00We roll over the top button, the up function runs and we run over the bottom button the down function runs.
01:07I'm stopping the pump on frame one and executing shrink every frame.
01:13I'm going to scroll up a little bit and look at the up, down functions real quick.
01:16It is actually pretty simple when you roll over the top one, the pump goes to its up state and when you roll
01:23over the bottom button, it goes to it's down state and scales up.
01:27The real magic happens in the shrink function.
01:29Every frame the balloon is shrinking in the amount of the shrinkAmt variable,
01:34if the balloon ever shrinks too small then we just simply reset the balloon size.
01:41So now when I test the movie I move the mouse up and down to pump up the balloon, but you can see the balloon is a kind
01:48of fighting back and shrinking as I'm trying to pump it up.
01:54So you can use this technique to create an endurance game or to add a little fun to another game.
01:59This completes the look at the techniques that we are using to mimic the console interactivity for Wii games.
02:06If this is enough information for you, feel free to go out and create your own Wii games immediately.
02:11If you'd like to see some examples of these techniques in actual games then stick around to the next few chapters
02:17and in each chapter we will make fully functional games that use these techniques.
Collapse this transcript
4. Creating Point-and-Click Interactivity: Meteor Shooter Game
Viewing the finished game
00:01In this chapter we are going to create a Meteor Blaster game where your Wii window will act as your laser gun to shoot Meteors.
00:07If you are following along you can go ahead and open up 01_Finished.fla in the Chapter 04 folder,
00:13or you can do simply watch the application in action.
00:16I'm going to test the movie
00:17and you will see that we have this logo on the screen, level information, how many points to win the level, and a click here to start.
00:25If you run the keyboard shortcuts for test movie again you will simulate the download
00:31and you can see that there is a preloader for this application.
00:34I'm going to start the game and you will see that the gun shoot lasers and have sounds
00:40and you could advance through levels and so on.
00:44If the meteors hit your ship, your ship shrinks.
00:55You also hear an intense roaring noise, and if your energy goes down below zero then you get game over and you get some information
01:02about what level you made it to and you can click the button to play the game again.
01:06So that's and overview of our Meteor Blaster game
01:08so I'll start making it.
Collapse this transcript
Exploring the game's FLA file
00:01Let's take a look at how the .fla for our game is set up.
00:03If you are following along I'm working in 02_Exploring.fla in the Chapter 04 folder.
00:09The first thing is that this game isn't exactly from the Wii game template
00:14in that I changed the frame rate to 12 frames per second.
00:17Let's take a look at the layers.
00:18We have the actions layer with no ActionScript and no content, the preloader layer has no content
00:24and we have the end layer, if I unhide it; is what you see before you start playing the game
00:29and after you are done playing the game; and just shows the game's logo and some other text.
00:35There is one Movie Clip on that layer called end_mc
00:37and if you double click the Movie Clip you will see that the Movie Clip is fairly simple.
00:42There is the logo on the logo layer, on the button layer there is an invisible button,
00:46and the text in the background layer contains dynamic text fields and a black background.
00:50The text fields are level_txt, points_txt; level_txt, which will display the level that the user is on, point_txt,
01:00which will display how many points the user needs to get to win that level, and clickHere_txt,
01:06which is the message that's going to basically say click here to play the game.
01:10Let's go back to Scene1 and go down to the next layer, which is called station.
01:14I'm going to hide the end layer and lock it.
01:16Station is kind of the main graphical elements that we are looking at.
01:21There is a Movie Clip on the station layer called station_mc.
01:23So if you just double click any of the artwork on that layer then you will enter into station_mc.
01:28You will notice that inside of station_mc, you will see the cursor and that's going
01:33to represent the cursor while you are playing the game; so that is an instance of a Movie Clip called cursor_mc;
01:38then the players energy bar is in a Movie Clip called energy_mc.
01:41Energy_mc is farily simple; there is a Movie Clip called cover_mc at the top, and that represents the mask
01:49for the energy, so we can make it look like the player's energy is going down
01:52and it has the energy Movie Clip called bars_mc.
01:56Back to mcBattleStation, there is also this text field that has the user's score, which is called score_txt
02:04and two gun turrets; on the left we have gunleft_mc and on the right we have gunright_mc.
02:12At the top there is a Movie Clip called dome_mc and that's about it.
02:17So we have our main graphical elements, I'm going to lock station layer, unlock the container layer,
02:23and see that the container layer it simple contains an empty Movie Clip,
02:26which is and instance of mcContainer called container_mc.
02:29I will lock the container layer and unlock the stars layer.
02:33The stars layer is a very simple Movie Clip that just contains some star graphics, back to Scene 1.
02:39And that is it for how the stage is set up in our layers.
02:42There are also some Movie Clips that we are going to be using and some other library elements.
02:46If you jump over to the library you will see mcMeteor.
02:49If you double click mcMeteor you will see that it's a very simple Movie Clip with three frames
02:54and each frame has a different color of Meteor.
02:56The actions layers simply has its Stop action so that this Movie Clip will stop on frame one.
03:01Also in the library you will see some sounds the first one is called hit.mp3,
03:07which will play when the player shoots a Meteor; the next one is called laser.mp3,
03:12which will play when the user shoots the lasers, and the last one is called moo.mp3,
03:21which will play when the player gets hit by a Meteor.
03:28So that's how this .fla file is set up.
03:29If you don't have access to the Exercise Files you can simply set up an .fla file based on our game template
03:35and that way you can follow along with all the code that we write throughout this chapter.
Collapse this transcript
Setting up game variables
00:00Now we will take a look at some of the variable that we're going to use in our game just to start setting it up.
00:05If you are following along, I'm working in 03_Varibles.fla in the Chapter 04 folder.
00:11Let's go to the first keyframe of the actions layer and open up the Actions panel.
00:16I'm going to paste in some code, which can be found in code.txt also in the Chapter 04 folder and you could find the exact
00:22code in the Movie 3 section.
00:25The first thing we are doing is importing gs.TwenLite.
00:30If you are not familiar with TweenLite make sure to watch the TweenLite movie in Chapter 02.
00:34In order for this to work you will need to copy the gs folder into the Chapter 04 folder.
00:38Let's take a look at our variables;
00:40meteorNum represents the current meteor number that's being created. We'll talk more about that later once we start creating
00:47the meteors, meteorInterval is going to be used with the set Interval function to create meteors at certain intervals of time.
00:54meteorInit is our initialization object for our meteors.
00:58I'm initializing score to 0, initializing the pointsToWin the first level at 1000,
01:04initializing the currentLevel to start at 1,
01:07initializing the currentMeteors:Array equal to an empty array. The currentMeteors is going to hold all of the meteors
01:14that are currently on the screen,
01:16growthRange and spinRange represent
01:19the random range of growth and spin that the meteors can have,
01:24which we will also talk about more later when we start animating the meteors.
01:27maxObjects defines how many meteors can be on the state of maximum,
01:31which in this case is three.
01:33moo, hitSound, and laser are our game sounds and I'm setting them equal to new instances of the sound class.
01:39origX and origY represent the origingal X and Y position of station_mc respectively.
01:45So let's look at the variables that we are going to be using in our game. In the next movie we will take a look at the functions
01:50we are going to use to initialize our game.
Collapse this transcript
Initializing the game
00:00Let's take a look at writing some of the initialization code for our game.
00:03If you are following me along I'm working in 04_Initializing.fla in the Chapter 04 folder.
00:08And just like the other code I pasted in all of this code is inside of the code.txt file in the Chapter 04 folder.
00:14So I will paste it in and I'm simply using the attachSound method to attach sounds from the library
00:19to our sounds we created as variables earlier; and that's moo, hitsound, and laser.
00:24I'm also setting laser's volume to 50%, so unlike ActionScript 3.0 volume ranges between 0 and 100.
00:31So I'm not making the volume 50 times louder than it normally is.
00:35I'm setting it at 50%.
00:36Running this showScreen function, which I will show in just a second and stopping the timeline because later
00:42on we are going to have multiple frames in this timeline.
00:45So I will put the showScreen function in between the variable section and the run immediately section.
00:49The showScreen function essentially just shows the end screen.
00:53This is the same screen for starting the game, advancing through levels, and when you get a game over.
00:58Let's take a look at the specifics of the function.
01:00Showing end_mc; it is set by setting its _visible property to true.
01:05Tweening it in using the TweenLite engine, by the way if its already at an alpha
01:09of 100 you won't see any ActionScript tween at all.
01:12Setting the score 0, setting the text in the clickHere_txt text field which is inside of end_mc equal to Click here
01:19to start; adding 1 to the growthRange and that's just going to add to the speed that the meteors grow,
01:25which we'll talk about more when we look at animation for the meteors; disabling the onPress event
01:31for stars_mc by setting its value to null.
01:35Running the stopAllSounds function to stop all sounds that are currently playing;
01:39setting the invis_btn onPress event equal to statrtGame.
01:43What that means is that when the user clicks on the text that says Click here to start,
01:47which is where the invisible button is, the startGame function will run.
01:51We'll take a look at the startGame function in just a minute.
01:54I'm showing the Mouse and by the way the mouse is not going to hide on the Wii, it's only going to hide
02:00on the computer if someone plays it there.
02:02And I'm disabling _root.onEnterFrame by setting its value to null.
02:06Let's take a look at the startGame function; I will paste it right below the showScreen function.
02:10The startGame function actually starts the game, so when you click,
02:14Click here to play then the game starts and here you see what happens.
02:18Again, we set the score to 0, just to be safe setting the score_txt field equals to the score that the user has,
02:24setting the _xscale of the cover_mc movie clip that the one that covers the energy bar equal to 100.
02:31So as the player gets hit the cover will shrink and it will appear that the player's energy is going down.
02:38And this line of code is connected with the next line,
02:41which sets the mask of the bars_mc movie clip equal to the cover movie clip.
02:46So in ActionScript 2.0 you set a mask using the setMask method and not the mask property.
02:52Now we will started the game, I'm hiding the mouse, showing the cursor, which is going to follow the users mouse,
02:59disabling _root.onEnterFrame and then resetting it equal to updateAll, this code is just to be safe.
03:06First we disable it, make sure that everything is cleared, and then we add the value again
03:11to run the updateAll function, which we will also talk about later.
03:14Then I'm setting the pointsToWin variable equal to the current level time to 1,000.
03:19So for Level 1 the player needs 1,000 points; for level 2, 2,000 and so on.
03:23And then this block of code fades out the end_mc movie clip in 0.25 seconds.
03:31And notice this section here that says onComplete, hideEnd.
03:35The onComplete property that we can pass in to the object tells the TweenLite engine what function to run
03:42when the tween is complete and the function that I'm running is called hideEnd.
03:46First we will take a look at the updateAll function and then the hideEnd function.
03:50updateAll function is fairly simple, I will paste it right below the startGame function.
03:55All it's doing right now is it is setting the cursor's x and y position in every frame equal to the position of the mouse
04:03and notice that we are, kind of, offsetting it by the x and y position of station_mc.
04:07The reason for that is because the cursor is inside of station_mc.
04:12So to match its position with the mouse we need to offset its value by its parents.
04:18So to match the position of the cursor with the player's mouse we just need
04:23to simply offset it by its parents x and y positions.
04:26Now you may be thinking why don't we use the startDrag method.
04:29The problem with the startDrag method is it puts the movie clip under your mouse constantly so when you click,
04:35click Events can be captured by the object that you are dragging
04:38and that's definitely something we do not want to have.
04:41We don't want to click on the cursor, we just want to have the cursor be there
04:44and move around with the player's mouse, and this the simple way to achieve that.
04:48Next we will take a look at the hideEnd function.
04:50I will paste it right below the updateAll function and again this runs
04:54when the tween is complete for the end movie clip fading out.
04:58And I'm simply setting its visible property to false; the reason why I'm doing that is to make sure
05:03that it doesn't register any click events.
05:05So that we can click on the meteors and on the background and other objects on the screen.
05:10So let us take a look at what's going to initialize our game.
05:12So if I test the movie right now I should be able to click where it says Click here to start
05:17and run the startGame function, which starts the dragging of the custom cursor and close the preview window.
05:25The next step is to start creating meteors, which we will do in the next movie.
Collapse this transcript
Creating meteors
00:00We are also going to look at creating meteors.
00:03If you are following along, I am working in 05_Creating_Meteors.fla,
00:06or you can just use the same file from last exercise.
00:09Let's scroll down to the start Game function, at the bottom of the start Game Function,
00:13I'm going to use a function called setInterval, to run a function called, to create meteors every second.
00:21When you are using the setInterval function, it's best to use a variable to hold setInterval.
00:27We have already defined a variable, and that variable is called meteorInterval.
00:30So we're going to set meteorInterval = setInterval, again, setInterval runs a function every certain amount
00:37of milliseconds, and for the syntax, the first value you pass in is the timeline
00:43in which the function you want to run is attached.
00:45So I'm going to type _root, because our functions is going to be on the main timeline.
00:49The second parameter is the name of the function as a string.
00:54The function is called, createMeteors.
00:59The third parameter is the amount of milliseconds to wait before executing the function, and that's going to be 1000.
01:07whenever you setInterval, it's best to clear the interval before you set it.
01:12Now, basically clearing the interval is the same thing as calling, a setting _root.onEnterFrame = null,
01:19it stops the createMeteors function or whatever function you pass in from running.
01:24This is considered a best practice you can serve memory.
01:27So right above where we set the interval, we are going to call clearInterval and I'm going to pass in meteorInterval.
01:37For information on setInterval and clearInterval, see Flash Help.
01:41I'm also going to run clearInterval inside of the show screen function to make sure
01:47that meteors are not being created as soon as the game stops.
01:50So, at the very bottom of the show screen function, I am calling clearInterval, and I'm passing in meteorInterval.
01:57Now we write the createMeteors function.
02:01I will paste it right above the show screen function.
02:07The first thing I'm doing in here, is checking to see if the length of meteors array is less
02:12that the maximum number of objects that are allowed.
02:15If so, then it will create a meteor, I am holding the meteor in a variable called meteor,
02:21setting the variable's value = container_mc.attachMovie.
02:26So what this does is, is it creates a movie clip that I'm holding it inside of this meteor variable.
02:31That way I can quickly and easily reference it later on.
02:34In the attached movie method, I am passing in a few parameters.
02:37The first one is mcMeteor which represents the identifier name for the mcMeteor symbol in the library.
02:43Then I'm passing in the meteor's instances name, which is going to be meteor+meteorNum.
02:49This represents the number of meteor that's created, and I'm using a variable here,
02:53so that it will have a unique instance name every time I create a meteor.
02:58The depth I'm setting is container_mc.getNextHighestDepth, so that each meteor will be
03:03at the container's next highest available depth.
03:07The Init that I'm passing in, is meteorInit.
03:10On the next line of code, I am running meteor.initializeMeteor,
03:15initializeMeteor is not a built in method.
03:18It's a method that I'm going to define in just a minute connected to our meteorInit object.
03:23So not only the built in properties and methods apply to objects
03:27when they are attached via the Init object parameter, but custom, properties and methods attach as well.
03:33Next I'm clearing the meteorInterval, and then setting a new value to meteorInterval,
03:37which is pretty much the same thing, except for the time interval, which going to be a random number.
03:42This will make the game a little bit more interesting, so the player will not know exactly when a meteor is created.
03:47If you create a meteor every second, then the game will become easy,
03:51because the player will know when to expect a meteor to appear.
03:53Next I'm incrementing the meteorNum variable by one, and then adding the meteor to the currentMeteors array.
03:59Let's take a look at the initialized meteor method.
04:03I'm going to paste it right above the createMeteors function.
04:06Those are attached to meteorInit.
04:09So instead of MovieClip.initFrame = functions, I have meteorInit which is my Init object,
04:15.intializeMeteor that's a method that I'm defining now, and I'm setting it's value = a function.
04:20Let's take a look at what this function does.
04:22First it sets up a random frame, the random frame is mathematically calculated to perform a simple formula,
04:30and all it does, is it grabs a random frame from the meteor movie clip.
04:35As I showed earlier in this chapter, the meteor movie clip has three frames.
04:39So by multiplying Math.random by *this, meaning the meteor.
04:43_totalframes, and then rounding it up using math.ceil.
04:48we get a random frame that meteor has.
04:50So we either get one, two or three.
04:53Then I'm running TweenLite.from, so this Tweens the meteor and in from a certain value, so this being the meteor,
05:00the Tween will take 0.5 seconds, and it will Tween from {_alpha:0}to {_alpha:100} I'm setting the _xscale,
05:07and _yscale properties equal to Math.random * 50 + 50.
05:14This is a random number with a minimum value of 50 and a maximum value of a 100.
05:19Then I'm setting the growthRate, the growthRate is based on the growth range variable.
05:24The growthRate is the rate at which the meteor will grow, when it's starts animating.
05:28The spin is essentially the same thing; I'm setting the rotation to a random value between -180 and +180.
05:36I'm setting the X and Y properties to random values on the stage.
05:41Actually it's 2.0, notice that you get the width of the stage by Stage.width
05:44and the height of the stage by Stage.Height.
05:46So it's a little bit different in ActionScript 3.0.
05:49Next, I'm telling the media to gotoAndStop at the value of the randomFrame variable that we have defined earlier.
05:56Next, I'm setting the pointValue for this media.
05:59The point is also a custom property that I'm creating right here, and it's a whole number, as you can see by Math.floor,
06:06and the value comes from the growthRate *the currentFrame.
06:11So basically the higher the frame number the more points it's going to worth, * 25, and that will create our meteors.
06:19If I test the movie, then I will see meteors created, once I click, Click here to start.
06:24Meteor one, meteor two and meteor three, notice that they all fade in, nice and easy, and they have random rotations,
06:30random sizes, and random frame numbers, nice.
06:34I will close the preview window, and now we have successfully created meteors.
06:38Next, we'll take a look at animating these meteors.
Collapse this transcript
Animating meteors
00:00Now we will Animate the meteors, which is actually going to be pretty simple.
00:04If you are following along, I'm working in 06_Animating_Meteors.fla, in the chapter four folder. You can obviously just use
00:11the same file from last exercise as well.
00:13We are going to scroll down to the Update All function,
00:16and if you watch the title I'm creating a Particle System in ActionScript 3.0. This process will look very familiar to you.
00:21At the bottom of this function I'm going to paste in some code, and it's a loop
00:26that runs for each meteor in the currentMeteors array.
00:29I'm creating a variable here called meteor that holds currentMeteors index, open square bracket, I, closed square bracket, semi-colon,
00:33just so I can reference it shorthand,
00:35and very simply modifying the meteor, based on it's growth rate and spin properties. So I'm adding to the meteors X scale
00:43by it's growthRate, setting the meteors Y scale equal to it's X scale, and then adding to it's rotation based on it's spin amount.
00:51If I test the movie now, we will see the meteor spin and grow,
00:56once they are created.
01:01I'll close the preview window, and now our meteors animate.
01:04In the next movie, we will take a look at shooting the meteors, when you click on them.
Collapse this transcript
Shooting meteors
00:00Now add the functionalities, so that when you click on the meteors
00:03with your mouse or Wii-Remote the meteors will fly back.
00:07If you are following along, I'm working 07_Shooting_Meteors.fla in the chapter four folder
00:13or you can just use the same file from last exercise.
00:16Let's go down to meteorInIt.intializeMeteor and at the bottom of this method,
00:20we are going to add in the code for its onRelease event handler.
00:24So this.onRelease or the meteor.onRelease = hitMeteor.
00:32Make sure do not put any parenthesis, because we don't want to run the function now,
00:35we want to run it when the onRelease event happens.
00:38The hitMeteor function is fairly simple.
00:40I'm going to paste right below meteorInIt.intializeMeteor, it simply runs another function called hit and passes
00:47in two values, this which is the meteor, because this is connected to the meteor.onRelease event
00:54or onRelease property and a value of true.
00:57Let's take a look at the hit function, let's take a look at the hit function or paste it right below hitMeteor function.
01:04So it sets two parameters a meteor which is MovieClip and point which boolean.
01:09The point value is whether or not the player gets a point for this hit.
01:14We are going to use this function in two ways, when a player clicks on a meteor and when a meteor hits the player.
01:21So point just tells us true, if the player gets a point and false if the player got hit by a meteor.
01:28We have two variables here, one called randomRotation, that's a random value between -180 and +180 and random scale
01:35which is a random number between 0 and 50.
01:38Then I'm running TweenLight.to method passing in the meteor, that's passed in, the other meteor parameter.
01:45The animation will happen in 0.5 seconds and here are the properties that are going to be affected.
01:50The alpha will go to 0, the xscale will go to the randomScale,
01:54yscale will go to randomScale and rotation will go to randomRotation.
01:59Now if the value of point is true, then we are going to add on to the player score, in the amount of meteor.pointValue
02:07and just to make sure that value is an integer, I'm using math.floor here.
02:11Then we are taking the score and put it again inside of score text field.
02:15Now we should be able to click on the meteors and we test the movie and they should fade out and spin away
02:21and then added to the score at the bottom of the screen.
02:24Let's test the movie and see that works.
02:26Click here to start, then as I click meteors notice the points go up in the score text field
02:31at the bottom and the meteors float away.
02:33I will close the preview window and now we can shoot meteors, the next step is to fire lasers
02:40when you shoot the meteors and add the laser sound.
Collapse this transcript
Firing lasers
00:00Now let's take a look at firing lasers to shoot the meteors.
00:03The first step in firing lasers is rotation the guns toward wherever the cursor is,
00:08to do that I'm going to scroll down to the updateAll function.
00:12At the top of the updateAll function, I'm going to paste two lines of code, now that may not look like two lines,
00:18but I have word wrap on and have a large font.
00:20So it's not as intimidating as it looks.
00:23Let me walk you through it.
00:24What we are doing is we are controlling the rotation of gunLeft_mc and the rotation of gunRight_mc,
00:31both of these use the exact same formula to get the rotation of the guns.
00:35If you watch title on creating particle systems in ActionScript 3.0 this going
00:40to be the exact same formula used to rotate objects toward a certain point.
00:44What I'm using is math.atan2, atan2 is short for arc tangent 2
00:51and if you want more information you can look at up in Flash Help.
00:55But for this purpose, all you need to know is that you pass X an Y positions and you can use this function
01:02to make an object rotate toward a certain point and in Math.atan2,
01:07remember that you pass in the Y position before the X position.
01:12So it may not be quite as intuitive, but it's actually pretty easy to use.
01:16So the first parameters is the Y point, I want the gun to rotate towards.
01:20As this massive value here, sort of the Y position in the cursor inside
01:26of station_mc, then I subtract station_mc.gunLeft_mc.
01:33_y, so basically this value is the distance of the cursor from the gun MovieClip.
01:39For the X value it's exactly the same thing, the X distance of the cursor from the gun MovieClip
01:44and then the science happens when you take that value and you multiply it by 180 over pi.
01:51So again I multiply it by 180 divided by Math.PI, so you do that for the gunLeft MovieClip and the gunRight MovieClip
01:59and you have the guns that rotate toward the cursor.
02:02You will notice that if you look at the gunRight MovieClip the formula is exactly the same.
02:07I simply copied and pasted the code and changed the name of the MovieClip.
02:10So there is no magic that you have to do for the right gun or for the left gun.
02:14Alright let's test the movie and see what we have got.
02:15Start the game, move the cursor and watch the guns follow it, nice.
02:23The next step is to make the laser shoot out of the guns, to fire the laser,
02:28we are going to use a function called fireTheLasers, I'm going to paste that at the very bottom
02:33of all my elite functions here and I'm going to scroll up and walk-through, what this function does
02:38and it accepts one parameter which isHit and the value is Boolean.
02:42The value is true, if the player hit a meteor and false if the player did not hit a meteor.
02:47If the value is false then we run the stopAllSounds function to stop all the sounds.
02:52Here I'm attaching the laser.mp3 sound to the laser and then running the start method to start the sound.
02:58This large block of code here, simply draws some lines inside of station_mc there is movie clip called lasers_mc,
03:07that's just an empty movie clip, it's an instance of mc container.
03:11I'm writing the clear method to clear all the graphics that are previously drawn,
03:15inside of lasers movie clip then I'm setting the alpha of the lasers movie clip equal to a hundred.
03:20From there I simply define a lineStyle which going to be stroke of 5, the color Red
03:27and alpha of 100 and true for pixel hunting.
03:31That will make sure that it angle to point to the line or on whole pixels and not floating point numbers for pixels.
03:36The same thing is true here, make sure that our lines will not be jagged, when they display on screen.
03:42Then I run the moveTo method on the lasers to put starting point of line at gun X and Y position, simple it up,
03:50and draw a line to the cursor and that's for the left gun and then I move the line point to draw a laser starting
03:57from the right gun and ending up at the cursor.
04:00So we have these two red lines coming out, one from each gun and they both end up at the cursor
04:06and then I Tween the lasers out using TweenLite, pretty simple
04:11and now we will just have to run the fireTheLasers function.
04:13We are going to do that in a few places, the first place is going to be, in the hitMeteor function.
04:17So I'm going to scroll up and I'm going to find hitMeteor and in my code hitMeteor is on line 35
04:25and right below everything else I'm going to run fireTheLasers and if they hit meteor function runs
04:31and we know that we hit a meteor, I'm going to pass in true.
04:34Before we adjust the movie, I'm going to add fireTheLaser in a few more places.
04:37I'm going to scroll to the startGame function and at the very bottom of the function,
04:42I'm going type stars_mc.onPress equals fireTheLasers.
04:49By not passing in the value of true, Flash is going to assume about your false
04:53for our Boolean variable and fireTheLasers.
04:55So that way the lasers will fire, when we click on the background of the clip which is called star_mc.
05:00If we test the movie at the point, we'll be able to shoot the lasers and see them in action and here is some sounds.
05:06It looks like it's working great and just to manage the sounds a little bit better,
05:19I'm going to paste some more code inside of the hitMeteor function.
05:23So I'm going to scroll up, going to find hitMeteor and at the very top of the code,
05:28I'm going to paste in some sound modifying code.
05:30So I'm going to stopAllSounds always before hitting a meteor,
05:35then I'm going to attach the sound hit.mp3 to the laser and then start that sound.
05:40Now when I test the movie, I'm going to get a little bit more advanced sound when I shoot the meteors.
05:44I'm not only going to get the laser sound,
05:47but I'm also going to get the hit sound and that looks like it's working great.
05:56So now we have our meteor set up or guns point toward the cursor.
06:00We can shoot the meteors and lasers come out, we even have sound.
06:03The next step is to optimize the game by properly discarding meteors that are unused and effectively reset the meteors.
Collapse this transcript
Properly discarding meteors
00:00Now we'll take a look at properly discarding meteors, once we are done with them.
00:03If you are following along, I'm working in 09_Discarding_Meteors.fla in the chapter four folder.
00:10There are a few things we are going to do, to discard the meteors.
00:12The first one is going to be to get rid of all the meteors when we start the game or when we are done with the game.
00:18So I'm going to scroll down on my code and I'm going to find the showScreen function.
00:24At the bottom of the showScreen function, we are going
00:26to run a function called sweep, which we will define in just a minute.
00:29Sweep function is going to get rid of all the meteors inside of the current meteors array.
00:33I'm also going to run this sweep function inside of the startGame function, at the top of the function.
00:40Now let's define the sweep function.
00:42We are going to paste it in at the bottom of all of the other functions in my code.
00:49The sweep function is actually pretty straight forward, I'm using a while loop to go through all of the meteors,
00:56in the current meteors array, as long as the length is grater than zero and what I'm doing,
01:01is I'm running the shift method, on each meteor in the array.
01:04And what the shift method does, is it removes and returns the first element of an array.
01:10So we are taking that element and we are calling unloadMovie on it and unloadMovie simply discards the movie.
01:17So basically at one line of code here, we are taking the meteor
01:20out of the current meteors array and we are unloading it.
01:24The next place to get rid of meteors, is in the hit function.
01:27I'm going to scroll up to find the hit function.
01:29Fine, it starts on line 44, and I'm going to find the TweenLite.to line of code.
01:35I'm going to add some properties inside of the object area, toward the end of the block of code.
01:40Make sure your cursor is inside of the closed curly brackets and then we will add some additional properties.
01:46Once the meteor fades out after it's hit, I'm going to run a function called discard, so type onComplete:discard.
01:55Remember onComplete runs once the Tween is finished.
01:59So I'm going to run the discard function once this Tween is finished.
02:02Now I want the pass in a parameter to this function, and the way to do that is
02:07through another property called onCompleteParams.
02:13OnCompleteParams accepts an array of parameter values and the array is simply going to hold meteor.
02:21Now let's define the discard function.
02:23We'll define it below all of my other functions.
02:25I'm going to scroll down right below sweep, I'm going to paste in the discard function,
02:30which accepts one parameter called trash and that's a MovieClip
02:34and we are simply running the unloadMovie method on that MovieClip.
02:37The next thing we need to do, is make sure that these meteors that are unloading,
02:41are being taken out of the meteors array, so they stop updating in the update all function.
02:45So what I'm going to do, is scroll up, I am going to go back to the hit function,
02:49and at the bottom of the hit function, I'm going to run a function called remove, and I'm going to pass in meteor.
02:57The remove function is simply going to take a meteor out of our current meteors array.
03:01I'll write the remove function below all the other functions in my code.
03:05So right below the discard function, I'll paste it in, it accepts one parameter which is the meteor and some MovieClip
03:11and have a variable code index, then I'm looping through all the meteors in the current meteors array.
03:17If the meteor that's passed in is equal to currentMeteors index i,
03:22then the variable index is set to i and then I'm running break.
03:27Break simply stops this loop from running.
03:31Once we have the index removed then we run currentMeteors.splice and splice removes indices
03:37of an array starting with whatever index you pass in, so the index is whatever the index variables value is
03:44and then the next parameter is how many indices to remove and the remove count here is just one,
03:49because we want just to remove that meteor from the current meteors array.
03:53So once the meteor is removed from the array, it'll stop updating in the update all function
03:57and that will keep our code nice and efficient.
04:00So let's test the movie and meteor should keep on coming after we click them.
04:07Nice, so now our game is starting to look and feel a lot more like a game.
04:20We just have a few more finishing touches to add, until out game is complete.
04:24The next feature we are going to add is a system for advancing through levels, we'll do that in the next movie.
Collapse this transcript
Advancing through levels
00:00Now, look at building a level system for our game.
00:03If you're following along I'm working in 10_Levels.fla in the Chapter 4 folder
00:07or you can just see it's the same file from the last exercise.
00:10Let's scroll down to the Hit function.
00:12At the very bottom of this function, we're going to write a conditional statement to check to see
00:17if the player's score is greater than or equal to the number of points require to win the level.
00:25If so, the players are ready to advance to the next level.
00:28So I'm going to add on to the currentLevel variable, and then I'm going to run the showScreen function.
00:39We're also going to need to add some functionality to the showScreen function.
00:42So I'm going to scroll to the showScreen function.
00:46Here, I'm going to add some code right below score = 0.
00:52This is fairly simple, resetting the value of pointsToWin = currentLevel times of 1000.
00:59Then, I'm displaying some text in the Level Text field.
01:02So it says "LEVEL" + the value of currentLevel.
01:06Then, I'm putting the value in the Points text field to explain the points to win.
01:11So it'll show the value of the pointsToWin variable, and then it will say "Points To Win".
01:17That's really all there is to it.
01:18Now we pretty much have a level system.
01:20So I'll play the game and advance through a few levels.
01:23So we see LEVEL 1, 1000 Points to Win, start the game.
01:30So I beat LEVEL 1.
01:34Now I'm on LEVEL 2 with 2000 Points to Win.
01:40Let's start the game.
01:43So if you notice you can click the meteors really fast multiple times and get extra points.
01:56That's something that I kind of like the way it is, but if you want to change it, you can feel free to take
02:00on that project as a homework assignment and do a little research and figure how to do it yourself.
02:05So we can see that our level system works great.
02:07I'm going to close the Preview window, and we have a working level system.
02:11The next step in finishing up our game is to make some sort of difficulty or challenge
02:16for the players, so they can lose the game.
02:18The first thing we'll do for that is set up a system so that the player gets hit
02:22if the meteor gets too close to their ship.
Collapse this transcript
Handling ship hits
00:00Now, we'll make it possible for the player to get hit by meteors if they get too large.
00:05If you're following along, I'm working in 11_Handling_Hits.fla in the Chapter4 folder.
00:11You can obviously just use the same file from the last exercise as well.
00:14Let's scroll down to the updateAll function.
00:17In my code, you'll see the updateAll function on line 114.
00:20At the very bottom of this function, I'm going to paste in a block of code to check to see the size of the meteor.
00:27If the size of the meteor tested only by its x scale because the meteor has the same X and Y scale is >= 150
00:39and the meteor_alpha property is == 100, then the meteor is big enough to hit the ship and I'm going
00:46to run a function called shipHit on that meteor.
00:50For the shipHit function, I'm going to scroll down and I am going to paste the function below all the other functions.
00:57Now, this function is kind of big but it's actually pretty simple.
01:00I'll walk you through the function line by line, accepts one parameter and that's the meteor that hit the ship.
01:07We have a variable called numOfTimes, I'm setting it out = 0 starting the moo sound which is the sound that happens
01:14when the ship gets hit and I'm setting the onEnterFrame property of station_mc equal to a function.
01:20Now here's one part of the shipHit function.
01:24Our onEnterFrame block takes up the code that I have selected here.
01:28All it does is it shakes the ship.
01:31So it's actually pretty simple.
01:33It's x and y position, moves by a small random increment.
01:38It's x and y scale increases or decreases by a small random increment.
01:44The number of times variable goes up.
01:46If the number of times variable is >= 5, then I have reset the values of x and y position and x and y scale
01:54for the station and disable the onEnterFrame event by setting the onEnterFrame value equal to null.
02:01The other part of this function simply makes the meteor get hit where it passes in a value of false to the hit function.
02:08The rest of this function is pretty simple.
02:10I run the hit function passing in the meteor and a value of false because the user is not going to get a point
02:16when a meteor hits the ship and then the last two lines deal with the energy inside the station_mc.
02:22The cover for the energy's xscale decreases in the amount of the meteor's growth rate times (*) 2.
02:30So the faster the meteor is moving, the more energy it will take away from the player.
02:34Then I'm simply resetting the mask on bars_mc using the setMask method.
02:39That's really all there is to it.
02:41So let's test the movie and watch the ship shake and make a sound when the meteor hits it.
02:46So you can hear that chorus of roars when the meteor hits the ship.
03:01So we have successfully detected when the meteor is too big and it hits the ship.
03:05The next step is to make a way for the player to lose the game when the player's energy runs up.
Collapse this transcript
Losing the game
00:00Now, we'll create a way for the player to lose the game.
00:03If you're following along, I'm working in 12_Losing.fla in the Chapter4 folder.
00:08You can obviously use the same file from the last exercise.
00:10Find the shipHit function in your code.
00:13I'm on line 184 in my code, but yours may be a different line.
00:17At the bottom of the shipHit function, I'm going to paste in some code.
00:20In order to check to see if the player is lost, I simply have a conditional statement that checks to see if the cover
00:28of the player's energy or the mask for the player's energy xscale is < 0, if so, the player has lost the game.
00:37I'll just program my code there to make it a little easier to read and let's go through what this block of code does.
00:42It's pretty simple.
00:43First it makes the end movie clip visible, tweens it in, displays text for the level
00:49and points text fields, level text field says GAME OVER.
00:53The point text field says You made it to level and then whatever level you made it to.
00:58clickHere text field says click here to play again.
01:01The currentLevel is reset to 1, growthRange is reset to 2.
01:05I'm disabling the Stars on press so it's null, running the stopAllSounds functions, showing the Mouse.
01:15Nullifying the _root.onEnterFrame by setting its value to null, running the sweep function and setting the value
01:23of the invisible buttons onPress property = startGame.
01:28So this pretty much resets everything just as if we started the game all over again.
01:31So you can see it's actually pretty simple.
01:33Let's test the movie and see as an action and see if we can lose the game.
01:36And I'll just start the game and let the meteors destroy me.
01:55And there is the GAME OVER screen.
01:59It says You made it to Level 1, then you can play the game again by clicking the button.
02:04And it looks like everything is working great.
02:10So now we can lose the game, we can win the game and there's one more thing I want to add onto the game
02:15and that's a Preloader because this game is pretty intense graphically especially for a Wii game.
02:20We'll take a look at adding a Preloader to this game in the next movie.
Collapse this transcript
Creating a preloader
00:00Now we'll take a look at adding a Preloader to our game
00:02to make sure all the assets are loaded before the person playing the game starts playing.
00:06If you're following along, I'm working in 13_Preloader.fla in the Chapter4 folder.
00:11You could also use the same file from the last exercise.
00:14The first thing I'm going to do, first thing I'm going to do is move all of the frames on frame one over to frame two.
00:19So I'm going to select them all by clicking-and-dragging and then I'm going
00:22to click-and-drag my selection to frame two.
00:24I'm going to go to the first key from the Actions layer and I'm going to open
00:28up the Actions panel, and I'll paste it in my Preloader code.
00:32A Preloader code is very simple, it is running the Preload function on the onEnterFrame event for _root
00:38and I'm having the time line stop and we'll take a look at the Preload function of a variable called percent,
00:43it's a number and I'm simply rounding using Math.ceil, the value of _root.getBytesLoaded/_root.getBytesTotal
00:54so the loaded bytes for the movie divided by the total bytes for the movie times 100.
00:58So we may get a value between 1 and 100, pretty straight forward.
01:02And then I'm taking that value and I'm putting it inside of a text field which I'll create in just a second,
01:08and it says Loaded after the percent (%).
01:10If the percent is greater than or equal to 100 which by the way it's not likely that it'll ever be greater than 100
01:16but just in case I'll put the greater than (>) sign there,
01:18going to nullify_root.onEnterFrame and then move to the next frame.
01:23That's all there is to it.
01:24Let me close the Actions panel and on the Preloader layer, I'm going to create a Preloader text field.
01:28To do that, I'll have to unlock the Preloader layer and then click-and-drag to draw a dynamic text field on the stage
01:35and I'm going to give it an instance name of preload_txt and set the font to OCR A Standard.
01:45Make sure the text is not selectable.
01:48Set the font to a font size of 45 and white.
01:52I'm going to click the paragraph alignment center, center the text on the stage and that's it.
01:58So I'm going to test the movie and to simulate download, you can just press the Text Movie keyboard shortcut again.
02:04Before you do that, make sure your download settings are set to DSL.
02:07So I'm going to press the keyboard shortcut again to test the movie, and there's my percent loaded text
02:14and the game is loaded and you could see, you can play the game as usual.
02:21And that is our finished meteor game.
02:24So now that your game is complete, you can simply publish this file using Flash Publish Settings
02:29and then upload the HTML and the other files that are published to your server,
02:35browse to that file using the Internet Channel on your Wii and there is your first Wii game
02:39and you can play your first Wii game right on your Wii.
Collapse this transcript
5. Creating Up-and-Down Interactivity: Xylophone Master Game
Viewing the finished game
00:00In this chapter, we're going to create a xylophone game that will utilize our up-down motion with the Viewer mode.
00:06If you're following along, you could open up 01_Viewing.fla or you can simply just watch this movie and see the file in action.
00:13I'm going to test the movie and show the game.
00:16In this game, a ghost player or enemy player hits keys on the xylophone. Then the player of the game needs to use a trusty hammer
00:25to match hitting the same keys.
00:27The way that you hit the keys is by moving the mallet or the hammer up and down.
00:31So I have the mallet raised now. I'm going to hit the blue key, and the yellow key to match with the ghost or enemy player played.
00:42When you get something right,
00:45your score is increased at the bottom right of the screen.
00:48At the bottom left of the screen, the number of tries you have are displayed. If you get something wrong,
00:53then you get an oops message that tells you how many tries you have left, and you can click it to play again.
00:59If you run out of tries, you get a game over
01:05with information about how far you've got, and you can play the game again by clicking the message.
01:09So,
01:11you can see that the game is pretty simple, but it really takes advantage of some of the up-down interactivity that you can use in
01:18Flash with a Viewer mode. So in this chapter, we're going to go through the step-by-step process of creating this game, and then if you
01:23don't have the exercise files, just follow along and set up your FLA file in the same way as I have mine setup, and you can write
01:30the same code and your game will work in the same way. So throughout this chapter, we'll build this game writing the codes step-by-step.
01:36We'll start it by covering how the FLA file for the game is setup, so that if you want to build a similar game, you can set up
01:42your file in the same way.
Collapse this transcript
Exploring the game's FLA file
00:00Now let's take a look at how this FLA file is set up.
00:02If you're following along, go head an open up 02_Exploring.fla in the Chapter5 folder.
00:08If you don't have access to the exercise files, I'm going to walk you through this file
00:11and show you how the file is set up, so that you can set up your file in the same way.
00:15The first layer we have is actions layer which currently contains no code.
00:19The next layer is called message and contains a single movie clip called message_mc.
00:24If I double-click message_mc, I can enter its timeline and see if there are only two layers, window,
00:30which contains the button type graphic with some text fields.
00:34These text fields are going to contain information about advancings
00:37through the levels and have any game overs and such.
00:41The other layer is background; it's just simple semitransparent black background.
00:46The text fields inside of the window layer called message_txt at the top
00:52and info_txt at the bottom, which are in the scene 1.
00:56Let's go to the next layer.
00:58First I'll hide message, and then on the speed up layer, there is a very simple easy to miss movie clip
01:04at the bottom right that doesn't have any artwork on the first frame, but if you double-click the element,
01:09you'll see some artwork on the other frame if you scale the timeline.
01:13There is a simple animation of the text speed up, moving up and fading up.
01:21The actions layer simply has a stop action on frame 1 or into the main timeline.
01:28Lock the speed up layer and go to the hammer layer.
01:31The hammer layer has a few phrases; it's pretty simple.
01:35The first keyframe in the actions layer simply has a stop action.
01:38It has two labels in labels layer, one called up and another one called down representing the hammer in its up
01:45and down stage, and if I scroll the play head, you'll see the hammer is up on the up frame and down on the down frame.
01:50We are tuning the scene 1; I'll lock the hammer layer and lock the top elements layer.
01:57The top elements layer contains a few different elements, bullying behind everything else is called enable_mc;
02:04enable_mc is actually pretty simple movie clip; it's just a transparent graphic.
02:09This is what enables interactivity when the person is playing this game.
02:15In order to hit a key, you need to first move the Wii Remote or mouse up over enable_mc.
02:22That way, the person playing the game, won't be able to activate the keys by moving the hammer horizontally.
02:28The other element in the top elements layer is the Listen movie clip.
02:32This is an instance of mcPlayListen and which I'm going to double-click in the library.
02:37I'm going to set the background to black, so it's a little bit easier to see,
02:42and on frame 1 we have Listen and on frame 2 it says Play.
02:46This is just the visual indicator for what the users suppose to do while playing the game.
02:51I'm going to set the background back to white.
02:53I'm going to return to the main timeline.
02:54I'm going to walk to top elements layer and select the graphic on the keys layer.
02:59On the keys layer there is a movie clip called keys_mc which is an instance of mcKeys.
03:05If I double-click that movie clip; I'll see that there are four movie clips inside of the mcKeys movie clip.
03:10There is blue_btn; green_btn; yellow_btn; and red_btn.
03:18These movie clips are simple black graphics to cover the buttons so that we can fade them out and fade them in.
03:25Page contain two layers, one called hotspot.
03:30Hotspot is simply an invisible rectangle or rectangle within alpha of zero.
03:35We turn back to the Blue move clip.
03:38Layer 1 is the black graphic which is the same shape and size as each key.
03:43This is the part that's going to fade in and fade out.
03:46The hotspot is interactive area of each of these buttons.
03:50So the player will have to rollover the hotspot to activate the key or to hit the key with the hammer.
03:55We will return to mcKeys and you can see that green_btn is set up in the similar way.
04:02There is the hotspot, the solid color background, and if you look at the other movie clips,
04:08you'll see they are set up in exactly the same way.
04:12So we have a hotspot and a solid color background.
04:15We'll tune the main timeline now, lock the keys layer and unlock the Background layer.
04:19The Background layer is a movie clip, but it doesn't have an instance name
04:23because it's not going to be interactive at all.
04:25If I double-click the Movie Clip, you can see it's a simply a bitmap graphic with the keys on it.
04:31So the Background Movie Clip simply has a bitmap that has the xylophone in the background.
04:36Let's go back to Scene 1; lock the Background layer, unlock the bottom elements layer.
04:41The bottom elements layer is pretty simple.
04:43There is a bitmap graphic of a mini xylophone.
04:46The dynamic text field next to that graphic is called tries_txt,
04:50which will show how many tries the player has left, and then on the right we have score_txt,
04:55which is the dynamic text field that will show what the players' score is or how many levels they have advanced to.
05:02Other than that, the file is pretty straight froward.
05:06The only Library elements that we are going to be using dynamically are the sounds.
05:10There is C, C8, E, and G, and if you'd like you can select the sound
05:15and click the play button in the Library to preview the sound.
05:18So these are all exported for actions scripts as I can show you in Linkage Properties as their default identifier name.
05:26So if you don't have access to the exercise files, just export these elements
05:30for action script using their default identifier names and it will be good to go.
Collapse this transcript
Setting up game variables
00:00The first thing we are going to do write the code for a game is to create the variables that we are going to use.
00:05If you following along, I'm working in 03_Variables.fla or you can just use the same file from the last exercise.
00:11Let's go to the first keyframe with the actions layers and open the actions panel, I'm going to paste in some code
00:17and just like in the last chapter, the code that I'm going to paste in can be found
00:21in the chapter 5 folder in a file called code_txt.
00:24The code that we will paste in for each movie can be found in the file corresponding
00:29to the movie number we are currently working in.
00:31For the movie number, you can just look at the name of the file that I'm using
00:35for my exercise file which in this case is 03.
00:37Let's take a look at this code.
00:39The first thing we are doing is importing gs.TweenLite.
00:42Now if you are not familiar with TweenLite, I recommend watching the TweenLite movie in chapter 2.
00:46TweenLite is a powerful animation engine, that we are going to be using in this game to fade
00:51in and fade up the keys when they are hit.
00:53To use the TweenLite engine, you will need to follow what I taught in chapter 2 and download TweenLite
00:59from the TweenLite website, copy the gs folder into the chapter 5 folder.
01:03So make sure you have the gs folder and that TweenLite is inside of that folder before you move on writing your code.
01:09On to the variables.
01:10Four variables representing sounds.
01:13The names of these variables correspond to the names of the sounds in library.
01:16So we have C, C8, E and G. Pretty straight forward there and I have a buttons array that's going to represent all
01:24of the button keys that we will be hitting when playing the game.
01:28So we have keys_mc.red_btn.
01:32Then the green button, the blue button and the yellow button.
01:38So they all are inside of keys_mc.
01:41A variable called enemyInterval, this is going to hold the set interval value for the Ghost Hammer or Enemy Hammer.
01:49The intervalAmt refers to that amount of time in between hammer hittings for the Ghost or the Enemy player,
01:55decreasIntervalBy represents how much the interval is going to be decreased by as the game progresses
02:02so that the ghost or the enemy player will speed up.
02:06LowestInterval is the lowest possible interval for the ghost or the enemy player to play at.
02:12So never go below 250 in this case, increaseIntervalEvery is the amount
02:18of successful hits at which to increase the speed interval.
02:22So that way the game will get faster after five and after ten, after fifteen and so on.
02:27This makes the game a little more interesting.
02:30OriginalInterval has a simple value, it's just interval amount and then value is to reset the interval,
02:38if the player does a game over, enemyMovedelay is the amount of time to wait the before the enemy starts moving
02:47or the Ghost Hammer, enemyMoves is an array that holds the order of keys that were hit for the enemy player
02:54or the Ghost player, enemyCount represents the current index of the Array that the enemy is going to be on when moving
03:03through the enemyMoves array while the enemy is hitting the keys.
03:08PlayerCount represents where the player is and in the playerMoves array and this is used to compare
03:13against the enemyMoves array to see if the player is hitting the right key in the right index of the array.
03:19For example, if the enemyMoves Array contain red, green, blue, the playerMoves Array will need to contain red,
03:27green, blue as well for the player to advance.
03:30playersTurn is a Boolean value that represents whether or not it's a player's turn.
03:35It's initialized to false, because in the beginning of the game the enemy player or the ghost will move first.
03:41addHit is a Boolean variable that represents whether or not more moves should be put inside the enemyMoves array.
03:48We will talk more about this variable when we start discussing ememyLogic.
03:52triesLeft represent how many times a player can make a mistake without losing the game.
03:58It is set to one but you can set it to whatever you want if you want the player to have more chances.
04:02originalTries simply allows us to capture the triesLeft variable
04:07so that we can reinitialize the game when a player gets to game over.
04:12tweenTime and longerTweenTime are values that are used for elements that fade in and out.
04:18These elements include the Hammer, the message screen that tells the player
04:22to play the game and the keys once they are hit.
04:26minButtonAlpha represents the minimum Alpha for the keys that are hit and these aren't just the keys,
04:32these are the black areas over the keys and maxButtonAlpha represents the maximum Alpha of the black keys
04:40when they are hit, which is going to be zero.
04:42Now you may thing this is kind of reverse, so it is like minimum is 50 and maximum is 0.
04:47But these are the black keys that are the overlay so that as they fade in then the main keys fade out.
04:53Now you may think that these values are sort of backwards with minButtonAlpha being 50 and maxButtonAlpha being 0.
05:00But the way I thought about this when I prepared the game was that I wanted to refer to the minimum Alpha
05:05of the actual key and not the black faded key.
05:08So the black key will have an Alpha of 50 but that will represent the time
05:12when the key is the most faded out or the most black.
05:15So basically, at the max Alpha of 0 for the black key,
05:20the main key or the background key for the xylophone is at its full Alpha.
05:24So that's why I set-up the variables that way and that's all the variables that we have for our game.
05:28The next step is to write the functions that are going to initialize our game.
Collapse this transcript
Initializing the game
00:00Now we are at the code to initialize our game.
00:02The file I'm using is 04_initialize.fla and of course, you can just use the same file from the last exercise.
00:09I'm going to paste in some code.
00:11This file can be found in the code.txt file in the chapter 5 folder in the movie 4 section.
00:17Here I'm simply attaching sounds from the library using the appropriate linkage identifier names,
00:24running a function called initialize.
00:25I will paste the initialize function
00:28above the run immediately code I just pasted and let's take a look at how it set up.
00:32First we have a for loop that's running for each of the buttons in the buttons array.
00:38The first thing it's doing is it's setting the hitArea of each button which is going to be the hotSpot
00:43for that button equal to that button's movie clip called hotSpot_mc.
00:49So this way, we have a customs hotSpots for each button, using a hotSpot movie clip, that I created.
00:55Then we are setting the alpha of each button equal to minButtonAlpha.
01:00This is going to set each of the xylophone keys at the minimum visible alpha.
01:05So they are going to have a thicker black overlay.
01:08I'm setting the playLIsten movie clip to gotoAndStop at frame one (1) to display the Listen frame.
01:13Then I'm running a function called hideObjects which I'm going to show you in just a second.
01:18tries_txt is set equal to the String, which starts with a "x " and a space
01:24and then a String value from the number triesLeft.
01:28As we talked about in the last movie, the triesLeft variable has an initial value of 1.
01:32On the next line, setting the Score value in the score_txt.text field.
01:37It says "Score: " and then a space then the String value
01:40of the number (enemyCount) Then I'm running a setEnabled function with a value of false.
01:46We will talk about this function in a minute as well.
01:49Then I'm having the hammer_mc.gotoAndStop at the ("up") frame.
01:52Let's take a look at the hideObjects functions.
01:54I will paste that right below the initialize function.
01:57The hideObjects function is simply disables the message movie clip and makes it invisible.
02:04Now let's take a look at the setEnabled function.
02:07Remember that we are passing in a value of False.
02:09It accepts one parameter called isEnabled, which is Boolean of course.
02:13Then we have a loop for each button in the buttons array.
02:17The loop sets each button's Enabled property equal to the value passed in via the isEnabled parameter
02:23which this first time that we are running it, is false.
02:25Then we have a somewhat conditional statement that tries to see, if isEnabled is false and if it is not the playersTurn.
02:32If so and we will show the Mouse and then Tween out the hammer and that's it,
02:38that's all the initialization code for our game.
02:40I will test the movie at this point and we will see that our game is really simple.
02:46It just shows the Listen review clip on the Listen frame, displays the triesLeft and the score
02:51and the buttons have a semi transparent black overlay.
02:54I will close the Preview window and that's all there is to it.
02:57So now again to initialize.
02:59The next step is to set up the Ghost or the Enemy player.
Collapse this transcript
Creating the enemy player
00:00Now we will begin writing the code to create the enemy player or the example or Ghost player, whatever you want to call it.
00:06If you are following, well I'm working in 05_Enemy.fla or you can obviously just use the same file from the last exercise.
00:12Let's go up to the initialize function
00:14and at the very bottom of this function, I'm going to paste in a few lines of code.
00:18Here I'm running two functions,
00:21addEnemyHit
00:22and listen and then setting the onPress property of message_mc
00:28to run the listen function.
00:30Let's first take a look
00:31at the listen function. Let's scroll down to the bottom of the code,
00:35I'm going to paste the listed function right about my run immediately code. The purpose of the listen function is to
00:40run the functionality to listen to the enemy player hit notes.
00:45So the first thing I'm doing is running setEnalbed(False)
00:49disabling the OnRollOver event for enable_mc.
00:53If addHit is true,
00:56I'm running a function called addEnemyHit,
00:58which we will take a look at in a second.
01:00Then I'm setting the value of playersTurn equal to false, this is the enemies turn
01:05and fading out
01:07message_mc and running hideObjects once message_mc has faded out. Let's take a look at the addEnemyHit function.
01:15I will paste it right below the listen function.
01:18addEnemyHit is pretty simple. First we grab a randomIndex
01:22of the buttons array,
01:24so that picks a random button
01:26and then we put that button inside of the enemyMoves array.
01:31As you know that it sort of initialize the enemy player, but nothing is going to be too different if we test the movie.
01:37We simply have the same screen that we saw before.
01:41Now everything is set up though, so we can start having the enemy player hit the keys.
01:46We will take a look how to do that in the next movie.
Collapse this transcript
Making the enemy hit keys
00:00In this movie we will write the code to make the enemy player hit keys.
00:03If you are following along, I'm working 06_Keys_Enemy.fla or you can just use the same file from last exercise.
00:10In your code, find the listen() function.
00:12We are going to paste in some code at the bottom of the listen() function.
00:15Now it would be hard to tell where the code I just pasted in is, so it's start from line 76 and ends on line 81.
00:25First, I'm setting a value to enemyInterval and the value is equal to setInterval
00:30and the function resides on the _root or on the main Timeline.
00:34The function it's going to run is showEnemyMoves, which we will take a look at in a minute and it's going
00:40to run based on the variable value of enemyMoveDelay.
00:44Here we have a conditional statement that checks to see, if it's timed to speed up the game.
00:49The first check is to see if the intervalAmt > lowestInterval.
00:55If that's true and if enemyMove.length - 1, if that's true
01:03and if the player's value is a multiple of five, we will speed up the game.
01:07The way that you check to see if the player's value is a multiple of five is by checking the length
01:11of the enemyMoves array -1, that's just saying what the highest index of the enemyMoves array is.
01:19Then we use the % sign to give us a value of the remainder after division takes place,
01:23so we divide that enemyMoves.length-1 value by increaseIntervalEvery and it's value is five
01:30and the remainder is whatever is left over when that's divided, if that is equal to zero,
01:37then the player has a multiple of five correct
01:41and in that case increase the intervalAmt by the decreaseIntervalBy variable.
01:47Then we will play the speed up movie clip (speedUp_mc).
01:51Next we will take a look at the showEnemyMoves function.
01:53I will paste that right below this function, showEnemyMoves is what actually makes the enemy player hit keys
02:00on the xylophone.
02:02So we have a variable here called thisMove and the data type is a button and it is equal to enemyMoves(enemyCount).
02:09So it's dependent on the value of enemyCount, it's that index of the enemyMoves array.
02:16Clear the enemyInterval and then reset the enemyInterval here.
02:22Then we are on a function called hitButton on this move, hitButton which we will talk about in just a second,
02:28is what plays the animation and the sound for a button hit.
02:31Now I'm incrementing enemyCount by 1, then we check to see if enemyCount is greater than or equal to enemyMove.lenght
02:39and if so then we just clear the interval which is the enemyInterval and stop hitting keys.
02:46Let's just take a look at the hitButton function.
02:48I will paste that right below showEnemyMoves.
02:53This function may look a little massive, but it's not as intimidating as it may seem,
02:57hitButton expects one parameter which is btn, it's the button to hit.
03:02The first thing we do is set the alpha of that button equal to maxButtonAlpha.
03:08Now remember maxButtonAlpha has a value of 0,
03:10so maxButtonAlpha is completely revealing the background button.
03:14Then use TweenLite.to to tween the button, using the longerTweenTime variable,
03:22tweening it to an alpha of minButtonAlpha, which is 50.
03:26so the button will tween from completely revealing the xylophone key, to putting a semitransparent black overlay.
03:32Once the animation is complete we will run a function called checkIfLast.
03:38That will check to see if the button was the last button to be hit in the buttons array.
03:43The buttons array being, the array that holds the player moves or the enemy moves.
03:47We will take a look at the checkIfLast() function in just a minute.
03:50I'm running stopAllSounds to stop all sounds currently playing, you can see it's a built-in function.
03:55Then I have this large block of code, that's the switch case statement,
03:58that hits the different note, depending on which button was hit.
04:01If you are not familiar with the switch statement,
04:03you can look it up in Flash Help but I will give a brief definition here.
04:07A switch term is basically like an if-else statement, except for a switch statement you take the value of one variable,
04:13in this case btn, and you have a different reaction based on the value of that variable.
04:19So case checks to see the value of that variable.
04:24So if the button is the green button, then play the e sound,
04:29and after each case statement have a break to stop evaluating results.
04:35If the red button was hit start c8 sound, if the yellow button was hit, start the g sound,
04:41if the blue button was hit start the c sound and then default is what happens if none of the case values are true,
04:50I'm simply calling return to stop running this function and this function is not referring to the switch case statement,
04:57but referring to hitButton() and that's all there is to the hitButton() function.
05:02Let's take a look at the checkIfLast() function.
05:05I paste the checkIfLast() function right below hitButton().
05:08Let's take a look at how it is set up, it simply checks to see if enemyCount is greater than
05:13or equal to length of the enemyMoves array.
05:15So if the enemy has gone through all of the buttons in the enemyMoves array, then here's what happens,
05:22enemyCount is reset to 0, the onPress property of message_mc is set to run the playback function,
05:31which we will talk about in a minute, message_mc is hitted and it's alpha property is set to 0,
05:41the top text field says Your Turn and the bottom text field say Click to Play.
05:46Then I'm running the playBack function, which again we will look at in a minute.
05:51The enable_mc movie clip's onRollOver event is connected to the enableButtons functions,
05:56so that will run once that enable_mc movie clip is rolled over.
06:00Mouse is hidden, the hammer tweens into an alpha of a 100, the playerListen movie clip goes to the second frame,
06:08which is the play frame and that's really all there is to the checkIfLast() function.
06:13The playBack() function is pretty simple.
06:15I will paste it right below checkIfLast.
06:17The playBack() function simply resets the playerCount and playersMoves variables, sets the playersTurn to true
06:23because that's where the enemy has done it's move, it's the player's turn,
06:28then sets enable_mc.OnRollOver event to run the enableButtons function.
06:35The Mouse is hidden.
06:37The hammer tweens in and the hideObject() function runs.
06:42Let's take a look at the enableButtons() function.
06:44I will paste below playback and it simply sets the onRollOver value of enable_mc equal to null
06:53with disabled interactivity for enable_mc and then run the setEnabled function passing in a value of true.
07:00So that's enables all the buttons on the xylophone.
07:03So now that our enemy interactivity is set up, let's take a look at how it works.
07:08I will test the movie and there are two key hits from the enemy player and the enemy successfully animates.
07:17Notice you can't see my mouse here because we haven't shown the hammer or moved around the hammer.
07:22We will talk about how to do that in the next movie but you can see
07:24that the enemy player is successfully hitting the keys, which is great.
07:29The next step is to start moving around the hammer so that we can create some player interactivity.
Collapse this transcript
Moving the hammer
00:00Now we will set up the interactivity for the player to move their hammer and hit the keys on the xylophone.
00:05If you are following along, I am working in 07_Moving_Hammer.fla,
00:09which could be found in the Chapter 05 folder.
00:11In your code, find the initialize() function, mine starts on line 28.
00:16At the bottom in the initialize() function, set the onEnterFrame event of hammer_mc to run updateHammer.
00:22The updateHammer function is fairly simple, we will add it right below the initialize() function.
00:27It's simply set the x and y positions of the hammer equal to the positions of the mouse.
00:32Now if you test the movie, you can see that in action.
00:36As I move my mouse around the hammer falls in, nice.
00:41The next step is to enable the hitting of the xylophone keys.
00:45We will do that inside of the setEnabled() function.
00:47So scroll down, find that and at the bottom of the For loop in the setEnabled function, we are going to paste some code,
00:57and it sets the onRollOver and onRollOut events for each button based on the isEnabled value.
01:04You may be unfamiliar with the syntax, so I will do a quick walk through of it.
01:08Here I have (isEnabled) this is actually shorthand syntax for conditional statement.
01:14We wrap the condition in parenthesis, so whether or not isEnabled = true,
01:19then you separate the if-else results using a question mark(?).
01:23First you have if the value is true, if the value is true then onRollOver = handleHit,
01:29it's going to run the handleHit function.
01:32Then you have a colon (:) to specify the else code.
01:35If isEnabled = false, then set the onRollOver event for each button = null.
01:42You may find this shorthand syntax for conditional statements very useful as it also works in ActionScript 3.0.
01:48It's really best for just simple functionality like this where you are just executing one action or giving one value
01:54if the condition is true and one other value if the condition is false.
01:58So I'm doing the same thing for the onRollOut event except for if isEnabled is true, onRollOut will run, raise hammer.
02:07Let's take a look at the handleHit function.
02:09I will paste handleHit right below setEnabled, handleHit simply plays the hammer movie clip
02:18which will loop the Timeline back to frame one, run setEnabled with the value of false,
02:23which disables all the buttons on the xylophone then sets enable_mc.onRollOver event
02:29to run the enabledButtons function.
02:30So again the player will have to move the mouse or Wii Remote to the top
02:35of the screen in order to enable the buttons again.
02:38So that will force the player, they have to move up and down to play the game.
02:42Then I'm running hitButton with the value of this
02:45and this represents whatever button was rolled over to run the handleHit function.
02:52Remember handleHit is connected to each button's onRollOver event.
02:58Now let's take a look at the raiseHammer function.
03:00I will paste that right below the handleHit function.
03:04It simply has the hammer gotoAndStop at the up frame.
03:07It's pretty straight forward.
03:09The last thing we will do is add some code to the hitButton function.
03:14So find the hitButton function in your code, mine starts on the line of 118 by the way and at the very bottom
03:23of this function, we are going to paste in some code.
03:26If it's the player's turn, so if hitButton is running based on the playersTurn,
03:32then we put whatever button the player hit into the playerMoves array and add 1 to the playerCount variable.
03:38What this will do, is will store the data for each key the player hits inside of the playerMoves array.
03:44Now we have set up our basic hammer interactivity.
03:47If you want to test it out, go ahead and test the movie.
03:53Now try to hit keys, and notice that you have to move the mouse up and down or the Wii remote if you are playing
04:04on the Wii and you can hit as many keys as you want.
04:10The next step is to alternate between the playersTurn and the enemysTurn.
04:14So you can see that the hammer is working successfully.
04:17So we can go from the enemiesTurn to the playersTurn.
04:20What we are going to do in the next movie is have the ability to go back from the playersTurn,
04:24to the enemiesTurn to set up the rest of the functionality for the game.
Collapse this transcript
Alternating turns
00:00Now as for the interactivity for alternating between the player and enemy and back to the player again,
00:05if you are following along I'm working in 08_Alternating.fla in the Chapter 05 folder.
00:11You can obviously just use the same file from last exercise.
00:14So scroll over to hitButton and mine starts on line 118 and then scroll to the bottom of that function
00:20and find the conditional statement that we wrote in the last movie.
00:23At the bottom of that conditional statement, run a function called checkPlayerTurn.
00:28We will write that function right now.
00:30I will place that function right below the hitButton function.
00:33Now this function is rather large but it's not too complex and I will go through it step by step.
00:39This simply checks to see if it should still be the player's turn and it checks
00:44to see the player's moves against the enemy's moves.
00:47So in other words, if enemy hits green and then blue, the player must hit green and blue and if the player hits green
00:54and then red then the player has an incorrect move.
00:57Let's take a look at how it works.
01:00Here we have a variable called allCorrect, it's Boolean initialized to true.
01:04If not every move is correct by the Player then allCorrect will have a value of false.
01:09So here we have a loop that runs for the length of the playersMoves array.
01:16You see that the loop ends right where I have selected on line 164.
01:22So it's sort of a large loop and the body of it runs a conditional statement.
01:28The conditional statement checks to see each one of the player's moves against each one of the enemy moves.
01:34The conditional statement is true if index i of the player's move --
01:38so if any one of the player's moves is not equal to that position of the enemy move.
01:44So running through the loop it checks the first move pf the player and the first move of the enemy,
01:48then the second move of the player against the second move of the enemy and so on.
01:52So if the conditional statement is true or if there is a mismatch in the playerMoves
01:57and enemyMoves array then we set addHit to false, set allCorrect equal to false, hide message_mc,
02:08set some text in the message_mc text fields.
02:12The top text field will display Oops, the bottom text field will display how many tries left the user has.
02:19The tries text at the bottom left of the screen will show how many tries you are left.
02:25Message_mc.onPress event is set to run the listen function.
02:30message_mc fades in with a delay of 0.5 seconds so that it means it will start after 0.5 seconds
02:37and once the animation is complete the enableMessage function will run,
02:42which we will talk about in just a second.
02:44PlayListen goes to the first frame which displays listen.
02:49PlayersTurn is set to false and everything is disabled.
02:54Now I will scroll down to outside of the for loop and take a look at this conditional statement.
03:01If after the loop, allCorrect is equal to true and the length of the playerMoves array is equal to the length
03:10of enemyMoves array, then addHit is set to true, the score text field shows the new updated score,
03:21the playListen movie clip goes to the listen frame, the listen function runs and buttons are disabled.
03:28So basically, if the player hits all of the keys in the right order then it's the enemy's turn again.
03:34I mentioned earlier that we create the enableMessage function.
03:37So I will paste that right below this function and it simply enables message_mc.
03:43Now why to have a full whole function to change this value?
03:47That's because I don't want to enable the message until it's completely faded in.
03:52So that's why I'm using a function in this onComplete event that's connected to our Tween.
03:58Now if we test the movie, we should be able to go between the player's turn and the enemy's turn.
04:03So I will hit yellow and then red to match the enemy, then I will hit yellow, red, green and so on.
04:14You could see that my score is going up and everything is looking great.
04:24So now if I hit the wrong key then I get this Oops message.
04:28Now if I click the button, I can play again.
04:30If I hit the wrong key again, I get another chance.
04:40So, that's it for the basic functionality of our game.
04:42You can go back and forth between the player and the enemy, there is just no way to lose the game.
04:46In the next movie, we will finish the game by making a way to lose.
Collapse this transcript
Losing the game
00:00Now we will finish the game by making a way for the player to lose the game.
00:03If you are following along, I'm working in 09_losing.fla in the chapter five folder.
00:08Of course, you can just use the same file from the last exercise.
00:11In your code, find the checkPlayerTurn function, in my code it's on line 143.
00:16Of course, it maybe different in your code.
00:18In this function, find the for loop, into that for loop find a conditional statement that checks
00:24to see if the players move was incorrect.
00:28At the bottom of that conditional statement, I'm going to paste a large block of code.
00:31Just like the rest of the large block of codes that I have pasted in, this is a lot less intimidating than it looks.
00:37It starts on line 162 in my code with triesLeft -- (minus minus).
00:41All this code does is it decrements triesLeft by one, if the player gets to move on
00:47and then checks to see if the player has any triesLeft.
00:50If the player has no triesLeft then the block of code runs.
00:54The block of code simply shows game over on the screen
00:58and initializes all the variables so that the player can play again.
01:01Scroll up, we will talk about this line by line.
01:04There is a variable called finalScore and this represents the player's final score.
01:08For nearly every case, the player score is going to enemyMoves.length - 1.
01:14The exception to that rule is if the player loses the game without ever scoring a point
01:19because the enemyMoves array starts with two elements.
01:23So if the player doesn't get any of those two, ememyMoves.length is -1
01:28and the player score would be 1 where it should be zero.
01:31So I'm having this conditional statement, make sure that the player score is in bounds.
01:35So we check to see if ememyMoves.length - 1 is not 1, if so, the player score is ememyMoves.length - 1.
01:45If that conditional statement is false and the player score is one then I simply set the player score to zero.
01:52In the message text field, I'm setting -- I am displaying Game Over, new line which is n
02:02and the score displaying the player's final score.
02:07The info text field says, click to play again.
02:09From here I'm simply resetting the game's values.
02:14Emptying out enemyMoves and playerMoves, setting enemyCount and playerCount to zero.
02:18Resetting the value of intervalAmt to originalInterval, setting the score text field to display zero,
02:25which is the current value of enemyCount.
02:27Setting triesLeft equal to originalTries.
02:30Displaying the original amount of tries in the tries text field.
02:34Running the EnemyHit function.
02:36Setting playersTurn to false.
02:39Running setEnabled to disable all the buttons and setting addHit to true.
02:43That's really all that there is to it.
02:45Let's test the movie and see this in action.
02:47So I'm going to get a few points and then lose.
02:55Now hit the wrong key, so it says I have zero tries left and I have game over with my final score being accurate
03:06at two points, click to play again and the game starts over again.
03:11Now I will lose with a score of zero.
03:17Now I will lose with a score of zero.
03:21So I'm getting Game Over with my accurate score.
03:26I can click the button and play the game again and now we can successfully lose the game.
03:35So that completes our Xylophone game.
03:37Just like with the other games you can publish this file so you can get the proper html to contain the SWF file
03:43and put all the files online, browse to it on your Wii using Internet Channel and play this game on your Wii.
Collapse this transcript
6. Creating Circular Interactivity: Setting the Clock Game
Viewing the finished game
00:00Let's take a look at the game that we are going to be creating in this chapter. The game is called Set the Clock and you can find the file in
00:05the Chapter 06 folder and the file is called 01_Set_the_Clock.fla.
00:11Or you can just watch and just see how the game works.
00:14We will test the movie and here on the right side of the screen is Target time which says 1:25
00:20and the clock is pointing to 1:25. So by using circular, clockwise or counterclockwise motions the goal is to match the time
00:29on the clock.
00:30Once you have matched the time, you can click with your mouse or the Wii remote
00:35and then you get the message that comes and tells you did a good job and tells you how long it took you to match the time on the target clock.
00:42So this game will give you some practice using the circular motion technique that you have learned in Chapter 3.
Collapse this transcript
Exploring the game's FLA file
00:00Let's take a look at how a game FLA file set up.
00:03If you are following along you can go ahead and open up 02_Exploring.fla in the Chapter 06 folder.
00:08If you don't have access to the exercise files, you could just create your own FLA file
00:12and make sure you set it up exactly how I have this file set up.
00:15Let's take a look at our Layers.
00:17First I have the Actions layer with no code in it yet.
00:19Then there is the End layer, if I show the end layer there is a movie clip on that layer so unlock the layer
00:25to reveal the movie clip and it's called end_mc.
00:28If I double click the movie clip you will see that it is instance of mc
00:31and there are three layers text, box and shadow.
00:35The text includes some text field and a button.
00:38At the top, is the static text field, below that is another static text field
00:44and the other text field it's a dynamic text field.
00:46Let's say it's end.txt.
00:47This text field will display information about the players finishing time.
00:52Way again is simply a static text field in form a graphic.
00:56You will notice it's not a button, I actually made this whole movie clip a button.
01:00So we will have all the interactivity placed in this entire movie clip.
01:04Back to scene one.
01:05We are going to lock and hide the end movie clip and reveal the Buttons layer.
01:09Unlock the buttons layer to show the buttons that are on the stage.
01:13Noticed that there are invisible buttons which means they only have a Hit frame.
01:17If you remember from Chapter 03, I have showed this rotation technique using four buttons.
01:22So we have one in each quadrant.
01:25So the top left or tl_btn, tr_btn, br for bottom right_btn and bl for bottom left_btn.
01:36So as the player plays the game, they are going to rollover these buttons in the sequence,
01:39whether it's clockwise or counterclockwise.
01:42If this system of circular motion using four buttons is unfamiliar to you,
01:46I highly recommend watching the movie on circular rotation in Chapter 03.
01:50Going to lock the Buttons layer and hide it and the Small Clock layer,
01:54there is some artwork at the top right of the screen.
01:57Target time is the static text field.
01:59Here is a dynamic text field that's called target_txt
02:02and this will display the target time in numbers for the person to match.
02:08The target clock will display the target time on a clock.
02:13Its instance name is target_mc.
02:15If I double click the movie clip, you will see it's very simple and it has four layers.
02:20Bolt, choose the bolt in the center of the clock, smallHand, longHand and the Clock background.
02:29Note that the smallHand and the longHand are movie clips
02:32with registration toward the bottom, going to Zoom-in to show that.
02:37So if I click on the longHand you will see it's instance name is minute_mc and if I double click
02:42that movie clip you will see that its registration point is toward the bottom.
02:46That's really important because it's going to be rotating around that point.
02:50Back to small clock and if I double click the hour hand or hour_mc,
02:55you will see that its registration point is also toward the bottom.
03:00So make sure if you are developing your own file to give your minute
03:03and hour hands registration points that you want them to rotate around.
03:08Back to scene one.
03:09You can press Cmd+2 on the keyboard, it's on the Mac and it's Ctrl+2 on a PC to Zoom-out.
03:15Now we have the Main Clock layer.
03:18The main clock layer is pretty much exactly the same thing as the target clock.
03:22It's instance of main clock called clock_mc and if I double click it you will see it set
03:26up in the same way as the target clock movie clip.
03:29So we have the Bolt, the smallHand and longHand which have registration points for the bottom and the clock background.
03:36Back to scene one, the Background layer contains a simple background graphic.
03:40So that's how this FLA file setup.
03:43If you look in the Library, you won't see any extra elements that I didn't mentioned already.
03:48That's because we are only going to be using elements that are already on the stage for this game.
03:52So we are not going to be creating any elements dynamically.
03:55Now that we have taken a look at our FLA file, let's start creating our game.
Collapse this transcript
Setting up game variables
00:00Now we are at the variables that we are going to be using in our game.
00:03If you are following along you can open up 03_Variables.fla or you can just use the same file from the last exercise.
00:09Let's go to the first keyframe in the Actions Layer and open up the Actions panel.
00:12I'm going to paste in some code here as with the other games that we have created, the code that pasted in
00:18and the code that I have paste in the rest of this chapter can be found
00:21in the Chapter 06 folder in a file called code.txt.
00:25To find the movie number, you can look at the FLA file that I'm working in.
00:28So right now I'm working in movie three so this code to be found in the movie three section of code.txt.
00:34So first we have rotateAmt.
00:36It has a value of 30 and it corresponds to the amount that the hands move around the clock.
00:42Going to explain this value in more detail once we start creating the interactivity for the clock.
00:46So we will come back to it little bit later.
00:48The buttons array simply holds all the buttons in order from top left, top right, bottom right and bottom left.
00:55This will be very familiar to you if you watch the movie on creating circular motion in Chapter 03.
01:02CurrentButtonNum, lastButtonNum these variables hold the current and the last buttons that we rolled over,
01:08which also should be familiar to you at this point and then these four variables cw1, cw2,
01:14ccw1 and ccw2 are boolean values and they represent whether the person is rotating the mouse
01:20or Wii remote clockwise or counterclockwise.
01:24We will talk more about this in detail a little bit later on but these are essentially going to be the same values
01:29that we used when we did circular motion in Chapter 03 and I'm just holding them in variables here.
01:35Target number of minutes is where the player needs to rotate the minute hand to you to win the game.
01:39TargetHour is the same thing for hours instead of minutes.
01:43TargetMinuteRotation is the rotation amount that corresponds to the target minute that should be rotated to
01:49and targetHourRotation is the same thing but for the target hour.
01:53FullTargetRotation represents the sum of target minute rotation and target hour rotation.
01:58We will talk about that more when we start moving the hands on the clock.
02:01StartTime represents the time that the player started playing the game
02:05and endTime represents the time when the player finishes the game.
02:08So those are the variables that we are going to be using in the game
02:10and you could see here they are pretty straight forward and now that we have our variables set
02:14up we could start writing the code to initialize our game.
Collapse this transcript
Initializing the game
00:00Now we are at the code to initialize our game.
00:02If you are following along, I'm working in 04_Initialize.fla in the Chapter6 folder.
00:07You can also use the same file from the last exercise.
00:10The first thing I'm going to do is run a function called initializeGame.
00:15In between my run immediately code and my variables will define the initializeGame function.
00:20At this point it's pretty simple. Setting startTime = getTimer.
00:24Setting the clock hour rotation equal to zero. Clocks minute rotation equal to zero.
00:30Running a function called enableAll passing in a value of true.
00:33We will talk about the enableAll function in just a minute and I'm hiding end_mc.
00:38The enableAll function is also very pretty simple accepts one parameter isEnabled and it's Boolean
00:44and I have a loop running for all the buttons in the buttons array
00:47and I set enabled equal to the value passed in via the isEnabled parameter and then I set a dynamic property called num.
00:54A dynamic property is a property that you can create on a button or a movie clip in your code.
01:00So num doesn't already exist, I'm just creating it right here. I'm setting the value of it equal to i.
01:06So each button has its own index memorized. Now, before we use an index of function to get the index of each button.
01:14This way it makes it very easy to connect a buttons index to the button.
01:20In that way we don't have to use an extra function to get a button's index.
01:23So now our game is successfully initialized. If we test the movie, we won't see anything too fancy at this point,
01:29we will just see the head in end_mc
01:32and both the clock hands pointing up.
01:34I will close the preview window
01:36and now our game is initialized.
Collapse this transcript
Updating the target clock
00:00e Now we will setup their functionality to add rotation to the clocks.
00:04We are going to start with the rotation of the target clock.
00:06If you are following along, I am working in 05_Target_clock.fla
00:11or you can obviously use the same file from the last exercise.
00:14In your code, find the initializeGame function, right below startTime = getTimer,
00:18we are going to paste in a block of code.
00:20So the pretty large block of code but it's actually fairly simple and I will explain.
00:25Here we have targetHour and targetMinutes being set.
00:29TargetHour is a rounded number, it's a random between 0-11+1.
00:35So random number between one and 12.
00:38So it represents it hour on the clock.
00:41TargetMinutes represents the number of minutes on the clock.
00:45So random numbers that's rounded between 0-11 then that value is multiplied by 5 so then the values are in range
00:53between 0-55 and only in multiples of five.
00:57So if the rounded number would one, the value of targetMinutes
01:00to be five, the value would two, ten and so on.
01:03TargetHourRotation and targetMinuteRotation represent the amount that hour
01:08and minute hand should rotate based on the targetHour value.
01:13TargetHourRotation is targetHour * 360.
01:17Now 360 degrees are in a full circle or essentially saying that the targetHourRotation is going
01:23to be the targetHour is rotated in a full circle that many times.
01:27So if the targetHour is seven, it will be rotated in seven full circles.
01:32TargetMinute rotation is a little bit different.
01:34The value is targetMinutes divided by five times the rotate amount.
01:39Let me explain how this works.
01:42RotateAmt has a value of 30.
01:46Now the way that that number is derived is 360 divided by 12.
01:53So essentially this allows the clock to rotate in five minute increments and here is how it works.
01:58Take targetMinutes, let's say the clock it should rotate to 30 minutes.
02:03So we have targetMinutes as a value of 30, we divide that by five, that corresponds to the point
02:10on the clock where the hand should rotate.
02:13So 30 divided by five is six.
02:15So the clock should rotate towards the six hand.
02:17So that's how that works and then we multiply that value by rotateAmt and the clock will rotate to that position.
02:24So if targetMinutes is 30, divide that by 5 and we get 6, that's where the clock should point to.
02:30We multiply that by the rotate amount which is 30 and we get 180.
02:37So the clock hand would rotate exactly where it wants to go from pointing straight up to pointing straight down to 30
02:44and that's how targetMinuteRotation works.
02:46FullTargetRotation is the sum of targetHourRotation and targetMinuteRotation
02:52which we will talk about more in just a minute.
02:55Here I'm initializing the target hour and minute rotations to zero then running a function called updateClock,
03:02passing in target_mc and fullTargetRotation.
03:05We will talk more about updateClock in just a minute.
03:08The conditional statement that I have here, simply displays the targetMinutes
03:12and targetHour inside of the target text field.
03:15Now there is one reason why we have to use a conditional statement here and that's
03:18because of targetMinutes has a value less than ten, it's going to be a one digit value.
03:23So we will have the value of zero or five.
03:25Now if we just put that value in the text field we might get 10:5 or 10:0 instead of 05 or 00.
03:33So this conditional statement fixes that by setting the value of target text = targetHour+:0+targetMinutes.
03:41So 10:05 or 10:00 put on a clock.
03:44Since that's to the exception to the rule, the rest of the time the value just going to be targetHour+:+targetMinutes.
03:51Let's take a look at the updateClock function.
03:53I will paste that right below initializeGame.
03:57UpdateClock is pretty simple but it's where the lot of the magic happens in this application.
04:02It accepts a clock so either clock_mc or the target clock which is target_mc then it accepts the updateValue
04:09which is the value by which to update a minute and hour hands on the clock and that's a number.
04:15Let's take a look at what's inside of the function.
04:17First it rotates the minute hand by the amount of updateValue.
04:22Now remember that updateValue is the value of targetHourRotation + targetMinuteRotation.
04:28TargetHourRotation is multiplied by 360, so it's going to represent full circle.
04:32So we can basically take that add of equation as far as minute_mc is concerned because as you rotate elements
04:39in flash, after you go pass 360 the value is reset anywhere.
04:43If we subtract that we just have the targetMinuteRotation.
04:47So again, let's say the value is 180 because we want the clock to point down.
04:51Then we are simply adding to the amount of the clocks rotation currently which is going to be zero
04:57because we initialize that in initializeGame function so add on 180 and the clock will face down.
05:03Now here is the more complicated part, rotating the hour hand.
05:07The rotation of the hour hand is added to in the amount of updateValue divided by 12.
05:13The logic behind this is that the hour hand rotates at one-twelfth of the speed
05:19as the minute hand, just like in a normal clock.
05:22So for example, the minute hand in an hour will go through a full rotation once.
05:26In that hour, the hour hand will only rotate one hour, so that's one-twelfth of the speed.
05:33So that's how we make the clock rotate to the correct position.
05:36We have moved the minute hand by the updateValue and hour hand by updateValue divided by 12.
05:42Let's test the movie and see what we get.
05:45Get Target time is 6:50 and if everything is correct it should display 6:50
05:50on the target clock and sure enough it does, nice.
05:55So now we have our target clock rotating and our updateClock function ready to go.
05:59The next step is adding the interactivity for the player to rotate the clock
06:03by moving the viewer mode or cursor in a circular motion.
06:07We will take a look at that in the next movie.
Collapse this transcript
Adding player interactivity
00:00Now, we will take a look at adding the player interactivity so we can capture the clockwise
00:04or counterclockwise rotation from the Wii Remote with mouse.
00:08If you are following along, I'm working in 06_Player_Interactivity.fla in the Chapter6 folder.
00:13Of course, you can use the same file from the last exercise.
00:16In your code, find the enableAll function.
00:18At the bottom of the loop within the enableAll function write the following code.
00:24Set buttons(i) onRollover event.
00:27To trigger a function called buttonOver.
00:30I will define the buttonOver function right below the enableAll function.
00:34Again, the buttonOver function may look a little bit complex, but again, this is the same formula used
00:39in the circular motion movie in chapter three.
00:42First what I'm doing is setting currentButtonNum = this meaning the button rollover.num.
00:48Remember num is a dynamic property that has each buttons index in the buttons array.
00:53Now, here we have is lastButtonNum is undefined then lastButtonNum = this.num.
00:58Now, lastButtonNum is only going to be undefined when the game first starts.
01:02So if you scroll to top of your code, you will see there is no value
01:05for lastButtonNum or currentButtonNum for that matter.
01:10So for the first button rollover that button is going to be lastButtonNum.
01:13Next, I'm setting the value of the clockwise1, clockwise2, counterclockwise1, counterclockwise2 variables.
01:25Remember that these values were Boolean.
01:29These are the same values that we used to calculate circular motion in the movie in chapter three.
01:34One scenario for clockwise is the currentButtonNum is 0 && lastButtonNum == 3.
01:41The other scenario for clockwise is currentButtonNum is == lastButtonNum + 1.
01:48There are also two scenarios for counterclockwise.
01:52The first one is currentButtonNum == 3 && lastButtonNum = 0.
02:00The other scenario is currentButtonNum == lastButtonNum-1.
02:06So our conditional statements simply check if clockwise scenario one is true or clockwise scenario two is true.
02:12If so, updateClock and the clock will be clock_mc and updated in the value of rotateAmt.
02:20So for rotating clockwise, we are going to rotate the clock hand by the rotate amount which is 30.
02:28If the player is not moving clockwise then check to see if the player is moving counterclockwise.
02:33So if condition one for counterclockwise or condition two for counterclockwise is true,
02:40then outrun updateClock passing in the value of clock_mc and then -rotateAmt.
02:46So the clock hand will then rotate back 30.
02:49After all the calculations are made, lastButtonNum is set to = this.num and again,
02:56that's just to capture the current button for the next time the player rose over a button and again,
03:02if this doesn't make any sense, I highly recommend watching the circular motion movie in chapter three.
03:05We will test it out and see in action.
03:06Going to rotate my mouse in a circular motion and watch the clock hands update.
03:08Looks like it's working great clockwise.
03:09So now I will rotate counterclockwise and it looks like the clock is moving exactly as it should.
03:11So now our basic interactivity works and the last thing we have to do
03:13for our game is compare the player's clock rotation against target clock rotation.
03:15We will do that in the next movie.
Collapse this transcript
Determining a win
00:00Last thing we have to do is compare the rotation of the hands on a players clock
00:03versus the rotation of the hands on the target clock.
00:06In this movie, we will take a look at how to do that.
00:08If you are following along you can open up 07_Finishing.fla or just use the same file from the last exercise.
00:13In your code, find the enableAll function and at the bottom of the loop
00:17in the enableAll function set the onRelease event for buttons(i) to run a function called checkWin
00:24or at the checkWin function run under the buttonOver function.
00:33CheckWin is actually pretty simple.
00:34It simply checks to see if the rotation of the clock's hour hand is equal
00:39to the rotation of the target clock's hour hand.
00:42In this case we don't even need to check the rotation of the minute hand
00:46because the hour hand is going to be very precise.
00:49For example, if the target clock is rotated at the 360, the hour hand is going to be halfway between six and seven.
00:56Now, there is no other way to get the hour hand halfway between six and seven then for the player
01:00to rotate the main clock's hour hand to six and seven and be at 6:30 as well.
01:05So we only need to check the hour hand here.
01:07Let's take a look at inside of this conditional statement.
01:09endTime is set to the value of getTimer.
01:11So the current value on the timer minus (-) the time the player started the game divided (/) by 1000 and divided (/)
01:17by a 1000 gives us a value in seconds for the endTime.
01:21End movie clip is shown.
01:23The text inside of the end text field displays endTime + seconds.
01:29enableAll runs here.
01:30Set to false to disable all the buttons and end_mc is onRelease event is connected to initializeGame.
01:38So once end_mc is clicked again, the game will restart and that's really all there is to it.
01:43Let's test the movie and see if we can get to win.
01:46So the target time is 11:30, I'm going to rotate the clock's minute hand down to 30 minutes.
01:52So my clock is 11:30 and I should be able to click on any of the buttons and check to see if I won.
01:58If so, I get this message.
01:59It says Good Job!
02:00and looks like it's working great and my time was 13 seconds.
02:03I'm going to click play again and now I can play again.
02:06You can see that if you click and your player clock is not
02:10in the right position then you are not going to get the winning message.
02:14If you set it just right then you will get it.
02:17So looks like our game is working great and there you have it.
02:20There is another game.
02:21Just like with the other games you can take this game, publish it meaning create the necessary extra files
02:27like the HTML, Javascript and your SWF file and then upload that file,
02:31browse to it on the web using the Internet Channel on your Wii and you can play another game on your Wii.
Collapse this transcript
7. Creating Velocity-Based Interactivity: Fun Run Game
Viewing the finished game
00:00In this chapter, we are going to utilize the velocity technique we learned in Chapter2 by creating a running game.
00:06If you are following along, you could open up 01_Fun_Run.fla in the Chapter7 folder
00:12or you can simply watch.
00:14I'm going to test the movie to show the game in action.
00:17The game has several elements, here is the main screen.
00:19Here is a little information window that has some text
00:23and tells you what time do you need to get what medals.
00:27There is a speedometer at the bottom
00:29and a little indicator of how far the players run at the bottom of the screen as well.
00:33So I'm going to click play
00:34and I move the mouse or Wii Remote up and down to make the player run.
00:39Faster I move the mouse, the faster the player runs.
00:42As I run the amount of miles goes up
00:44and the player advances across the road.
00:47Based on the time when I finished I get a medal.
00:50Unless of course I finish after 9 seconds.
00:53Once you are done playing the game you can simply click the information window to play again,
01:01and that's the Fun Run game.
01:03So let's start making it.
Collapse this transcript
Exploring the game's FLA file
00:00Now, let's take a look at our FLA file is set up?
00:03If you are following along, go ahead and open up 02_Exploring.fla or if you don't have access
00:08to the exercise files, you can simply create your file and set it up in the exact same way that I set this file up.
00:14Let's go through our layers.
00:16First, we have actions layer currently with no code in it.
00:19The next layer is called bottom elements that contains the graphical elements at the bottom of the stage.
00:24There is some text fields and some movie clips.
00:27Speed is a static text field.
00:29There is a Movie Clip.
00:30There's an instance of mc speed called speed_mc.
00:32The sister graphic that will show the player's speed.
00:36Based on the speed of the player, the Movie Clip will scale.
00:38There is a dynamic text field called distance_txt that will display the text value for how far the player has traveled
00:45and then there is another visual queue for how far the player has traveled in a Movie Clip called distance_mc.
00:52That Movie Clip is pretty simple, it's just a Motion-Twin of a mini runner, running across a mini road.
00:57Actions layer simply has a stop action.
01:00Back to scene one, going to unhide the end window layer, unlock it and show that a system Movie Clip called end_mc
01:12and if double-click the Movie Clip or enter its timeline, you can see that it's fairly simple.
01:17The medals layer contains information about how fast the player needs to run to get what medal.
01:21The text layer contains text.
01:24So, there is some Dynamic Text fields, head_txt, sub_txt and time_txt then the play button.
01:35The box layer contains the background graphic and the shadow contains the shadow graphic.
01:39So you can see this is pretty straightforward.
01:41We can go back to scene one, unlock the end window layer and hide it.
01:44Unhide the buttons layer and unlock it.
01:46The buttons layer contains two buttons, one called top_btn, and one called bottom_btn.
01:52These buttons manage the interactivity for this game.
01:54Player moves the mouse or we remote up and down, back and forth to make the player run.
01:59If you double-click one of the buttons, you will see there are both instances
02:02of btn in this and there is only Hit frame.
02:07Lock and hide the buttons layer.
02:09The runner there contains the runner that instance name is runner_mc.
02:13If you double-click the Movie Clip, you'll see there are three keyframes.
02:17On each keyframe is the runner and the runner is a graphic.
02:24There is an instance of the runner on each keyframe.
02:27On the first frame the runner is a graphic.
02:29On the second keyframe the runner is a Movie Clip, instance of mc running with no instance name
02:34and notice the frame label above the runner.
02:37Frame label on the label's layer is run and then there is the finished frame.
02:42The finished frame has a frame label of finished and a Movie Clip, there is an instance of mc finish called moving_mc.
02:50If I double-click the runner, you will see the timeline for mc finished, the first frame the runner is on the ground.
02:59The next keyframe has a label name of gold and simply shows the runner wearing the gold medal.
03:06Now, if I lock the mask in the middle layer and unhide the mask where you could see that it looks
03:10like the runner is wearing the gold medal.
03:13The instance of the runner on that frame is a graphic.
03:19We'll go to the silver frame label to the runner just holding a silver medal,
03:25then on the bronze frame label, the runner is holding a bronze medal.
03:29I will go back to scene one now.
03:31The next layer is called the finish line.
03:34So I will unlock it and select a finish line which is an instance of mc finish line called the finishline_mc
03:41and if I double-click the graphic or enter its timeline and it has got two frames
03:45and it is actually just a simple graphic that semi transparent and it is an Alpha of 35.
03:51Scroll down, then there is BG.
03:54The background there contains all of the main graphical animating elements for this file.
04:00So I select the artwork on the background layer, it's an instance of mcBg called bg_mc.
04:06If I double-click that instance of taking to that timeline and they are a bunch of different movie clips in here
04:12that control the different parts of the timeline.
04:14So we have the sidewalk, buildings, rocks, road, the sidewalk graphic and the sky.
04:24Everything is set up pretty straightforward here.
04:26Each one of these layers contains a movie clip that is repeated twice.
04:31So for example if I alter Option+Click the lock button in the buildings layer,
04:36I can unlock that layer and lock all other layers.
04:38If I select the buildings movie clip, see it's an instance of mc building, or the instance name of buildings1_mc.
04:45So I have my buildings1 here and it has a building and little lake.
04:51If I scroll to the right, I'll see immediately to the right
04:54of that movie clip is another instance of mc buildings called buildings2_mc.
04:58This enables us to have a scrolling background, just like more about how the scrolling background.
05:03I will talk more about how this scrolling going background works once we start writing the code for our game.
05:08But within this movie clip all the arms are set up in pretty much the same way.
05:12So if I were to unlock sidewalk, you see that there are two instances of mc sidewalk, sidewalk1_mc and sidewalk 2_mc.
05:19If I unlock the rocks layers, you will see that there are two instances.
05:22So I have clouds1_mc and clouds2_mc and so on down the chain.
05:29The last animating element is the road which is road1_mc, road2_mc and the sidewalk
05:35in the sky elements don't animate, they are just static graphics.
05:39Returning the main timeline, and that's it for how this file are is setup.
05:42So once a file is setup, ready to start writing the code for the game, and we'll start doing that in next movie.
Collapse this transcript
Setting up game variables
00:00We'll start writing the code for our game by creating the variables that we're going to be using.
00:04If you're following along and working in 03_Varibles.fla,
00:07or you're going to just use the same file from the last exercise.
00:10Then we have got the first key from the actions layer and open up the Actions panel.
00:14The Actions panel will paste some code in.
00:16By the way this code can be found in code.txt in the Chapter7 folder, in the movie 3 section.
00:22Let's take a look what this code is?
00:24Importing gs.TweenLite; which is our animation engine and if you are familiar with that,
00:29I definitely recommend watching the TweenLite movie in chapter 2 and since we are importing TweenLite,
00:34we're going to need to have the gs folder with the TweenLite class copied in the same folder where this fla file is.
00:41So we have some variables here, there is speed that represents the speed of the player.
00:45pixelsPerMiles an arbitrary number that represents how many pixels there are in a mile which of course has
00:50to be arbitrary because we can't really measure pixels to miles.
00:55Here is the totalMiles and it's 26.2, so marathon distance here.
01:01pixelsTraveled represents how many pixels the player has gone.
01:05This is the miles as how far the player has gone in miles based on our pixels to miles formula,
01:11milePercent is the percentage of miles traveled by the player.
01:15Finished is Boolean and represents whether or not the player has finished the game.
01:19startTime represents the time that player started the game, endTime represents the time that player finished the game.
01:25goldTime, silverTime and bronzeTime are the amount of time that the player needs to complete the game
01:30in to get the gold, silver and bronze medals respectively,
01:34and these are based on the totalMiles variable divided by certain numbers.
01:38So totalMiles divided by 5 for goldTime, 4 for silverTime and 3 for bronzeTime.
01:43FlstartX is the starting x position of finishLine_mc.
01:48So I'm capturing it right here.
01:51milesFromPlayer is how many miles the finished line is from the player.
01:55That's determined by subtracting the position of the runner from the flstartX variable and dividing
02:02that by how many pixels are in a mile and those are the variables that we're going to be using in the game.
02:07Next, we'll look at initializing the game.
Collapse this transcript
Initializing the game
00:00Now, look at initializing our game.
00:02If you're following along, I'm working on 04_Initialize.fla in the Chapter7 folder.
00:07Of course you can use the same file from last exercise.
00:10Below our variables, I'm going to paste some code, this code initializes our game.
00:14Set end_mc onRelease event to run the startGame function which I'll define in just a second.
00:21Having the runner gotoAndstop at frame 1, setting some text in the text fields and set up end_mc.
00:27The headline text says Fun Run, the sub text says Have a Blast!
00:31Just take a look at the startGame function.
00:33I'll paste that right above the code I just wrote.
00:37The startGame function is fairly straightforward.
00:40It simply initializes the game.
00:42finishLine_mc is x position is initialized to flstartX.
00:47Finished is set to false.
00:49StartTime equals the current time on the timer.
00:52PixelsTraveled distance in miles.
00:54MilePercent and speed are all initialized to 0 and the enableAll function is called with values of true and true.
01:00We'll create the enableAll function in just a minute.
01:03The runner is sent back to frame 1 and using the TweenLite engine, end_mc fades out
01:12and once it's done fading out, the hideMessage function will run.
01:16We'll define the hideMessage function in a minute as well.
01:18Just take a look at the enableAll function.
01:20We'll paste it right below the startGame function.
01:23EnableAll accepts two parameters.
01:25isEnabled which is a Boolean value and isAnimating which is also a Boolean value.
01:30For now, we're just going to use isEnabled.
01:33The top and bottom buttons enabled property is set to whatever the value of isEnabled is.
01:38So this function is pretty straightforward.
01:40Just take a look at the hideMessage function.
01:42We'll paste hideMessage right below enableAll.
01:45hideMessage simply hides end_mc once it's twined out.
01:50The reason why I'm doing this is so that the interactivity for end_mc is also disabled
01:56and that's all the rest you initialized in our game.
01:58I'll test the movie and see this in action and if you click the Fun Run block
02:05or end_mc it'll fade out and the game starts.
02:10Though nothing happens.
02:12In the next movie, we'll take a look at actually adding some interactivity to the game and making the player run
02:18when you move your mouse or re-remote up and down.
Collapse this transcript
Creating runner speed
00:00Now, add the interactivity to make our player run.
00:02If you are following along, open up 05_Running.fla or you use the same file from the last exercise.
00:08In the enableAll function we're going to paste in some code.
00:12This code is based on the value of isAnimating variable which when we first run it
00:16in the startGame function and it has a value of true.
00:19If it's time to animate, then _root.onEnterFrame is set to run the run function.
00:28If not _root.onEnterFrame is set to null.
00:31So the onEnterFrame event is disabled.
00:33Let's take a look at the run function.
00:35The run function is very straightforward.
00:37I'll paste it right below hideMessage.
00:41It runs two functions - setSpeed and showSpeed.
00:45Let's take a look at setSpeed first.
00:46I'll paste setSpeed right below the run fuction.
00:49SetSpeed modifies the value of speed every frame.
00:54So if speed is greater than zero, then it's going to keep decreasing by 0.2
01:00and the runner is going to go to the run frame.
01:04If speed is less than or equal to zero or else, speed is set to be zero and the runner is set to frame 1.
01:13At frame 1 the runner is stopped.
01:15So this function constantly decreases the speed of the player so that I've
01:19to keep moving the mouse or re-remote to keep running.
01:22Let's take a look at showSpeed function next.
01:24I'll paste that right below the setSpeed.
01:26ShowSpeed is fairly straightforward.
01:31The speed Movie Clip which is the block that displays the player's speed,
01:35as its xscale property set to speed time is 10.
01:39So the speed will have a value between zero and ten at full speed, speed_mc will have an xscale of 100 and just keep it
01:47in balance, we have some conditional statements.
01:49If the speed xscale is greater than 100, then speed xscale equals 100.
01:54If it's less than zero then it equals zero, pretty straightforward.
01:58Now, add the interactivity for the player to move the mouse or remote up and down to make the player run.
02:04I'll paste this code right below showSpeed.
02:06Here I'm setting the value of top_btn onRollOver equal to bottom_btn onRollover which is equal to a function.
02:18The function simply checks to see if speed is less than ten.
02:23If so, then speed goes up one, so as the player is moving to the mouse or re-remote up and down, the speed is increasing
02:30and if they don't move it up and down, the speed is constantly decreasing.
02:34Let's test the movie to see this in action.
02:36I'll click end_mc to start playing the game, move the mouse up and down and you can see the player's speed.
02:42And the faster I move the mouse up and down, the faster the player's speed is.
02:47If I start moving the player's speed decreases.
02:49It eventually stops, stopping the runner.
02:52Nice, so now we get the player running, but it doesn't really look
02:56like he is running because the background is not moving.
02:58In the next movie, we will take a look at scrolling the background
03:00so we can make the players running a little more realistic.
Collapse this transcript
Scrolling the background
00:00Now, we'll make the background of the movie scroll when the player is running so it looks more realistic.
00:05If you are following along, you can open up 06_Scrolling.fla in the Chapter7 folder
00:09or you can simply use the same file from last exercise.
00:12In your code, find the run function and at the bottom of the run function, run a function called moveGraphics.
00:21The moveGraphics function is fairly simple and I'll paste it right below the run function.
00:27First, it adds to pixelsTraveled in the amount of speed times (*) 5, speed times (*) 5 comes from the rate
00:34at which the road moves, which is where the player is running.
00:38So essentially that's what distance the player is traveling.
00:42The scrollMc function controls the movement for all of the background elements.
00:46There are three values that are passed in, the initial movieClip, the copy movieClip or the duplicate
00:52that moves along with it to be act as a buffer and then the rate at which the movieClip should travel.
00:58Let's take a look at the scrollMc function.
01:00I'll paste it right below moveGraphics.
01:03ScrollMc isn't too complicated, you can see it accepts three parameters, mc1, mc2 and the rate
01:10and the function moves mc1 horizontally in the amount of its rate.
01:18So, it's going to move the object to the left.
01:21They may have a conditional statement that's used to loop the movieClips.
01:25If movieClip1's x position is less than or equal to the rate minus (-) the width of mc1.
01:33So basically if mc1 has completely scrolled after left edge of the stage then we'll set mc1's x position to 0.
01:43For mc2 it's x position is simply x position of mc1 plus (+) the width of mc1 minus (-) 10 pixels just to make sure
01:54that the movieClips are overlapping just a little bit so there is no space in between them.
01:58And the way this is all powered is each movieClip scrolls slower based on how far it is supposed to be back.
02:08So the closest movieClip or the road scrolls it speed times (*) 5,
02:12the sidewalk which is a little bit farther is speed times (*) 3.
02:15buildings are farther back at speed times (*) 2
02:18and the clouds are the farthest back and they just go at the rate of speed.
02:22Let's take a look at how this works.
02:24I'll test the movie, start playing the game and move the mouse up
02:28and down to scroll the movieClips and that looks great.
02:36So we have this parallax scrolling effect with each object scrolling in relation to its distance.
02:42So now our movieClip scrolls successfully.
02:44The next step is to have some way to measure the distance that the player has traveled,
02:48so that there can eventually be a way for the player to win the game.
Collapse this transcript
Tracking distance
00:00Now, we use our pixelsTraveled variable to show the distance that the player has traveled in miles.
00:06If you are following along I'm working in 07_Distance.fla in the Chapter 7 folder.
00:11Of course you can use the same file from last exercise. In your code, find the run function, at the bottom of the run function.
00:18I'm going to run a function called showDistance.
00:23I'll define the showDistance function right below the run function.
00:27ShowDistance is what's going to show the distance that the player has traveled on the screen.
00:33First, we grab the distanceInMiles. That value is calculated by taking the number of pixelsTraveled and dividing that by
00:40the number of PixelsPerMile. Again PixelsPerMile is an arbitrary value that I made up for this game so don't go out
00:46and try to measure the actual amount of PixelsPerMile and prove me wrong or anything because I just made up that value.
00:53So, milePercent
00:54is set to be an rounded number.
00:57And what I've done here is I take the distanceInMiles and divided by the number of totalMiles and multiply that
01:04value by 100.
01:05So this is kind of the standard formula for getting the percentage between 1 and 100.
01:09Take a value, divide it by a total value, multiply it by 100 and then round it.
01:14Then I'm having the distance movieClip gotoAndStop
01:17and the milePercent. Where did the distance movieClip is 100 frame motion tween of the runner, running across the road.
01:26In the distance text field
01:28we have the distanceInMiles value rounded down using Math.floor
01:33and then the text miles.
01:35We'll see it an action. We're going to test the movie,
01:39start the application and watch the runner run at the bottom right of the screen.
01:45Nice.
01:47Close the preview window.
01:49Now, we have successfully measure the distance that the runner has traveled.
01:52In the next movie we'll finish the game by making a way for the player to win.
Collapse this transcript
Winning the game
00:00Now, we will finish off our game by making a way for the player to win.
00:03If you are following along, I'm working in 08_Finishing.fla in the chapter 7 folder.
00:08You can also just use the same file from the last exercise.
00:11In your code find the run function and at the bottom of the run function, run a function called moveFinishLine.
00:21I'll paste the moveFinishLine function right below the run function.
00:24The moveFinishLine function is fairly straightforward.
00:27If the player is closing up to the end or if distanceInMiles is greaten than or equal to totalMiles-milesFromPlayer;
00:36MilesFromPlayer is how many miles the finish line is from the player.
00:41If so, then move the finish line at a rate of speed x 5.
00:47The reason why it's moving at that rate is because that's the rate at which the road is moving
00:50and the finish line is of course on the road.
00:52Let's test the movie and see the finish line in action.
00:55We're going to start the application, move the mouse up and down and watch the player run at the bottom right
01:01on the screen and the finish line should come right there, right as the player finishes.
01:05Great. I'll close the preview window and now, let's give the player an award for finishing the game.
01:12We'll put the finishing code inside of the showDistance function.
01:15At the very bottom go in to paste a block simply checks to see if distanceInMiles is greater than
01:20or equal to the totalMiles that the player needs to run.
01:24If so, then run a function called finish.
01:26Let's take a look at the finish function.
01:28I'll write the finish function, right below the showDistance function.
01:31It's a pretty large function but you'll see that it's fairly straightforward.
01:36The first thing we do in the finish function is check to see if the game is not finished.
01:42If so, then finished is set to true and the endTime is calculated using the formula getTimer
01:49which returns the current time for the flash movie minus the time the player started the game 01:54 the startTime
01:55variable divided by 1000 so the time is converted into seconds.
02:00EnableAll has run with the value of false and then true - false to disable the interactive elements
02:07like the buttons and true to keep animating.
02:11And then what's checked here is the speed of the player.
02:17If speed is less than or equal to zero or if the player has finished running, then end movieClip is visible.
02:25It tweens end to an alpha of 100, the time text field inside of the end movieClip displays the endTime plus seconds.
02:35The runner goes to the finished frame which remember contains gold, silver and bronze frames
02:43and so the following conditional statements just check to see the player's time
02:48against the goldTime, silverTime, and bronzeTime.
02:51If the endTime is less than or equal to goldTime then the movieClip inside the runner_mc goes to the gold frame.
02:59If the endTime is less than or equal to the silverTime then I use an else if statement to check to see
03:05if endTime is less than or equal to silver time, if so then have the runner go to the silver frame.
03:11If the runner is not worthy of a gold or silver medal, then we'll check to see if endTime is less than
03:17or equal to bronzeTime, if so the runner goes to the bronze frame.
03:21end_mc is set to start the game over again when clicked.
03:26The header text of the end movieClip says, Nice Job and the sub line says, Your time was.
03:33That's really how others do it.
03:34Let's test the movie and see in action.
03:36I'm going to play the game and run nice and fast and go for the gold, and I got a gold, nice.
03:46So, it's Nice Job.
03:47Your time was and it has my time.
03:49The runner has a gold medal and I can click end_mc to play the game again.
04:01It looks like it's working great and there is another game and just like with the other games,
04:06you can publish the game meaning create the html, JavaScript and swf files that you need.
04:10Upload these to your web server, browse to them on your Wii and you have got another game that you can play on your Wii.
Collapse this transcript
Conclusion
Goodbye
00:00Well, that's it.
00:02You have now learned the techniques that you need to create Flash Wii games.
00:06I hope you had as much fun as I did.
00:08You've learned how to use the techniques like adding, porting, click interactivity, adding up down, or left right interactivity,
00:14adding rotational or circular interactivity and you created velocity based interactivity.
00:20You've learned how to take games that you create in Flash
00:23and play them on the Wii
00:24using the Internet Channel.
00:25So now that you've learned this, go out there and make some great games.
00:30 Be sure to email me when you do.
00:32You can email me at todd@chadandtoddcast.com.
00:35See next time.
Collapse this transcript


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