Viewers: in countries Watching now:
In ActionScript 3.0 in Flash Professional CS5 Essential Training, Todd Perkins shows Flash designers how to incorporate ActionScript code into their projects and create interactive presentations and applications. The course includes a review of ActionScript language basics and the object-oriented programming (OOP) methodology, a tour of those Flash Professional CS5 features designed for developers, such as code hinting and the Code Snippets panel, and instructions on interacting with objects in the Library and placing code on the Timeline. Exercise files are included with the course.
Many types of apps, especially games, need to be able to re-spawn or clone different assets. In order to do this in Flash, you have to create new instances from library symbols at run time. So let's imagine a scenario - go ahead, and test the movie here - and we have this skateboarding game. Let's say as a skateboarder is going through the town, the whole background is scrolling to the left, and as the boarder goes to the town, there are going to be little obstacles that come up, like trashcans. One way to create the obstacles is to build them in Flash and have them be part of your FLA file from the beginning.
However, that creates more objects in memory that you don't need because they won't always be on the Stage. The most effective way to create a game is to have objects on the Stage appear immediately when you need them, and delete them as soon as you don't need them anymore. The experience is the same to the user, but as you program the game, you get much better performance. So the thing we want to do is add trashcans to the game from the library, while the Flash movie is playing. That way we don't have to have them taking up more memory than is necessary.
The first step to do that is to create a MovieClip symbol. So I already have one called TrashCan. If I right-click TrashCan, and then choose Properties, I can tell Flash that I'm going to want to create new instances of this symbol using ActionScript. To do that, make sure you're in Advanced mode. You may have to click the Advanced button at the bottom-left of the Symbol Properties window. So you should see this Expanded View here. Simply click the Export for ActionScript box in the Linkage area.
In the Class field, you'll see the name of the MovieClip symbol. This is the name that you're going to refer to this object by when you create it with ActionScript. The Base class says that this is essentially a movie clip. Now, we're going to get into a lot more detail about what Class and Base Class mean later on, but for now just know, you just need to remember TrashCan. So click OK. Flash will give you messages that says, A definition to for this class could not be found in the classpath. It's not an error message; it's just a warning message, so I'll just click OK.
Again, we'll talk more about how that works and why you got that warning message later on. And then look into library and see that there is something under Linkage for your TrashCan MovieClip. So Flash is telling me this is exported for ActionScript as TrashCan. So it's nice and easy to remember because it's the same name as my MovieClip symbol. Let's go over to the first keyframe of the actions layer, and go ahead and open up the Actions panel. Create a variable called can and datatype it to TrashCan. You can also datatype it to a movie clip since it's basically a descendent of a movie clip, but for this purpose I want to datatype it as a TrashCan.
So click OK and then type new, space, TrashCan, capital T, capital C; and parentheses and a semicolon. At this point, if you want, you can test the movie to make sure you don't have any errors. It looks like everything is fine here. And now what I'm going to do is place the object on the Stage. To do that, use a method called Add Child. Type add, and then Child, with a capital C, and in the parentheses, type can.
This adds an object to the Stage, so it's going to put the can on the main Timeline. We'll talk more about the Add Child method later. See the can at the top-left of the Stage? That's the can that we pulled out of the Library using ActionScript. Now let's just place it in a normal spot, so it's not floating in the air. The reason why it's floating in the air is because it goes to 0,0 coordinate automatically when you put addChild. So let's set its x and y position: can.x equals 577 and can.y equals 493.
In case you're wondering where I got these numbers, I put the can where I wanted it, and then I just jotted the numbers down in the Properties panel. So, test the movie, and there is the trashcan right there. If you remember, the trashcan is not on the Stage in that position, so it's been placed there using ActionScript code. So using this technique, you can draw objects out of the library as you need them.
Find answers to the most frequently asked questions about ActionScript 3.0 in Flash Professional CS5 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.