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.
Connecting a symbol to a class is a simple process, but some parts of that process can be confusing. Before we look at how to do that, I want to point out that I have the file Boarder.as that's in the same folder as my FLA file. Note that it's the same name as the movie clip I want to connect that to. That's not necessary, but it's very helpful, as you'll see in just a second. Let's go to the FLA file, right-click the Boarder movie clip and choose Properties.
In the Symbol Properties window, make sure the Advanced area is expanded. In the Linkage area, check the Export for ActionScript box. You may be familiar with this process already, because we could have used it earlier in this course. In the Class field, you can specify the class that you want to connect to this movie clip. So the class name is Boarder. If the class doesn't exist already, Flash will create a class for you, which is why you may see a warning when you export a movie clip for ActionScript and haven't created a custom class.
The warning simply says Flash can't find the class, so it's creating one for you. When you set the class like this, you can only use one custom class per library, so I can't do that with any other class. If I wanted to take the Boarder functionality and apply it to another object, I could set it as the Base Class, and then put whatever class I want as the Main Class.
What Flash would do is it would take the functionality from the Base Class and apply it to that created class. We'll see how that works in just a minute. So right now I have Boarder for my Class, and then I'll click OK. You shouldn't see any kind of warning message when you click OK. If you do, double-check the location of your Boarder.as file, the name of the file, the name of the class, and the name of the constructor. Once everything works, you should see Boarder under the Linkage area.
Test the movie at this point, and your Boarder has keyboard control. Let's say we wanted to apply a keyboard control to the little cat over there. Simple! We've already written the keyboard control code in the Boarder class, so if we connect the Boarder class to the Cat, everything should work, right? Let's see. Right-click Cat in the library and choose Properties. Check Export for ActionScript, change Class to Boarder, and click OK.
Flash then gives you an error message that says "Please enter a unique class name that is not associated with other library symbols." If you think about it for a second, this message actually makes sense. Remember, early in the course, we exported a symbol for ActionScript, and we created new instances of that symbol by calling its class name. We can't have multiple symbols with the same exported class name, or else which one is Flash going to use, when you write the code to create one? So it makes sense that each of those should be unique.
So for this situation, I'm going to cut the word Boarder, and paste it in Base Class. Then for Class, I'm going to type "Cat." When I do this, I should get a warning message. I'll click OK. The warning message says A definition for this class, which is Cat, could not be found in the class path. So one will be automatically generated in the SWF file upon export. So Flash is going to make a Cat class for me that I'm never going to see, and it's going to extend the Boarder class.
So it's going to have all the functionality of the Boarder class, but I don't have to create a new class just to say that. So I'll click OK, and now you can see the Cat is exported as Cat, and when I test the movie, the Boarder and the Cat both move together. It's like the Boarder is chasing the Cat right now. So using this technique, I can apply keyboard functionality to any object I want, simply by modifying its Base Class.
The ability to reuse code by connecting a class to a MovieClip symbol is a very powerful thing in Flash. The more you use it, the more you'll understand how much easier it is than writing code time after time in the Timeline. And again, all you have to do to connect a symbol to a class is put your custom class name in the Class or Base Class field in the Symbol Properties window.
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.