When creating a document class, you can also extend the Sprite class, which is essentially a movie clip without a timeline. However, using the MovieClip class for this purpose offers more flexibility.
Line 5, along with its closing brace on line 11, is the class definition. You must add public to line 5 when declaring the class, so that other parts of your program can access it. For example, if you make something private, it will be accessible only from within the class. Doing so can protect portions of your class from outside manipulation and reduce conflicts with similar functionality that may exist elsewhere in your project.
The class, itself, however, must be public so that it can be instantiated. Line 7, along with its closing brace on line 9, define what is called the class constructor. This is the main function that automatically runs when creating an instance of this class.
It, too, must be public and must have the same name as the class. Other functions if any can, and must, have unique names, but using the same name as the class identifies this function as the class constructor, so it is executed upon instantiation.
All that remains to complete this document class is to add the lone instruction required to replicate the timeline example discussed previously. When creating a class, you must give the class, constructor, and file the same name—the notable exception being that the file must bear the. Because this simple example included no custom path instructions in the package declaration in line 1 of your class, save your file in the same directory as your class file.
The name of the FLA is unimportant, so you may as well call it main. Finally, open the Properties panel in the FLA and add the name of your class to the document class field. Use the name of the class, not the name of the file. In this case, type Main instead of Main. Hereafter, you can try any of our timeline code in a document class of your own.
However, all the sample code will come with an accompanying class file for testing. You can use those files whenever you wish until you get used to the document class format. If you ever have the need to run a discrete mixture of ActionScript 3. An ActionScript 3. In Chapter 13 , we will discuss how to communicate between these two discrete SWFs using a special process. For now, however, just remind yourself again that you cannot combine ActionScript 3. That exercise, however, displayed text only within an authoring application like Flash Professional—a technique used for testing and debugging, but not for displaying text in your finished files.
Our main goal is to give you a big-picture view of the script-writing process and to give you some experience coding. Create a new ActionScript 3. Because you use variables to store information for later retrieval, naming them in a clear and meaningful way is important. Ideally, the name you choose should convey the purpose of the variable whenever practical.
You have a lot of freedom when determining what to call your variables, but there are a few simple guidelines to follow. Line 1 of the script creates a new text field using the TextField class and places a reference to that field into the variable txtFld. Note the colon and reference to the TextField class immediately following the variable name. This is called a data type and makes sure that only a compatible type of data can be put into that variable—in this case, a TextField instance.
If you try to put something else into this variable, an error is displayed, which can help you spot problems with your code.
Line 2 adds the text field to the display list so it can be seen at runtime. Chapter 4 will explore this further, but put simply, the display list contains everything you can see in your file.
For example, a text field is a visual asset, but a sound is not. For the user to see the text field, you must add it to the display list, but this does not apply to the sound. Default values for font, size, and color are used to display the text in the field. There are no import statements in this script, however, because Flash Professional does not require that you import any class that is built into Flash player when coding in the timeline.
In short, when referencing a class in the timeline, if that class appears in a flash package—such as the flash. On the other hand, classes in packages not starting with flash —such as class you write or a class used with a component like fl.
Button —must still be imported, even in the timeline. For brevity, we will follow this guideline, but importing classes does no harm. In fact, as an interface improvement, Flash Professional CS5 will often automatically add import statements to your scripts when you use a class in the timeline—including those from the flash package. If you are using CS5, consider these automatic imports when comparing line numbers between your code and the book. To recreate this example using a document class, place the same code inside the constructor of the class—the only function included in this example.
Take the following steps to create the files required:. First, create a new ActionScript 3. Save the file as HelloWorld. Next, create a new ActionScript 3. The name of the FLA is not critical. Finally, test your movie. The class syntax here conforms to the syntax described in The Document Class section of this chapter, with two small exceptions.
The main difference is that the code in the class constructor differs because its purpose differs. Like the timeline code used to create the first Hello World example, this code uses a text field to display text, instead of the Output panel. The second difference results from this change. Adobe Flash is an excellent technology that allows developers to add interactivity and smooth animations to web pages. There are plenty of well-written, detailed tutorials and articles pertaining to Flash sectioned into seven categories including Basic Drawing , Special Effects , Server-side Flash , and Game Development.
Some people learn best by visualization and following along with the instructor step-by-step in real-time. It also has tutorials and articles about Flash game development that can be filtered by topic, expertise, and type.
Flash Kit is one of the biggest and oldest community dedicated to Flash development. They have a fairly active Forums section as well as an ActionScript Library that currently has over objects you can download. Flash and Math has a great collection of tutorials on AS3. They cover basic to advanced topics so that Flash developers of any level can find something they can read and learn from.
Many of the tutorials include the source files for download. Flash Perfection is a website with a large collection of Flash tutorials, tips, and tricks from various websites. You will learn important techniques through hands-on exercises, and then build on those skills as chapters progress.
ActionScript 3. This book will help guide you through a variety of scripting scenarios. Rather than relying heavily on prior knowledge of object-oriented programming OOP , topics are explained in focused examples that originate in the timeline, with optional companion classes for those already comfortable with their use.
As chapters progress, the book introduces more and more OOP techniques, allowing you to choose which scripting approach you prefer. Head First Agile is a complete guide to learning real-world agile ideas, practices, principles. Stefa Stefa 3 3 silver badges 10 10 bronze badges.
Florian Salihovic Florian Salihovic 3, 2 2 gold badges 15 15 silver badges 24 24 bronze badges. Kyle Thompson Kyle Thompson 11 11 bronze badges. Learning something new is never a waste of time.
Xandzilla Xandzilla 9 3 3 bronze badges. Flash Animate CC has some webgl exporter though, no idea how well those work on mobiles.. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete? Podcast Do polyglots have an edge when it comes to mastering programming Featured on Meta. Now live: A fully responsive profile. Related Hot Network Questions.
0コメント