Lesson 5. Using Functions
When programming, you may find yourself using the same chunks of code repeatedlyeither by copying and pasting them or by rewriting the same lines of ActionScript. There is a way to write ActionScript just once and reuse it anytime with a single action. You do this with functions and the action by which you execute a function is a call or a function call. Functions are real time-saversduring both development and code maintenancebecause they reduce the amount of code you need to write or modify.
You will create several functions that allow you to turn a Flash-TV on and off and change its channels. A Flash-TV is a simple Flash app that acts like a TV and remote control.
Think of a function as a mini-program that serves a specific purpose within another application. You can use it to perform a set of specific actions, or you can feed it information and output a resultor you can do both. Functions provide a powerful and versatile way to script your project.In this lesson, you'll learn how to create and use functions while developing a remote control for a Flash-made television set.WHAT YOU WILL LEARNIn this lesson, you will:Create a functionCall a functionAdd parameters to a functionCreate a function that returns a resultUse local variablesAPPROXIMATE TIMEThis lesson takes approximately one and one half hours to complete.LESSON filesStarting File:Lesson05/Assets/television1.flaCompleted Project:television4.fla
• Table of ContentsMacromedia® Flash MX 2004 ActionScript: Training from the SourceBy
Derek Franklin, Jobe Makar Publisher: Peachpit PressPub Date: November 19, 2003ISBN: 0-321-21343-2Pages: 636
Sure, you can use Flash MX 2004 without being a master programmer, but as any Flash developer worth his or her salt will tell you, you''''re not tapping all of its power unless you''''re taking advantage of its scripting language "ActionScript 2.0" which offers a more robust programming model and better object-oriented programming support than ever before. Here to take the fear factor out of learning it are Flash veterans and best-selling authors Derek Franklin and Jobe Makar, who demonstrate that scripting is an instinctual process you already know by translating real-life activities into ActionScript scripts. In these pages, you''''ll find methodologies and techniques for building over 40 real-life Flash ActionScript projects, including sample games, applications, Web sites, and more. New in this edition are coverage of ActionScript 2.0, Web services, Components, Printing, Video, and more. On the companion CD, you''''ll find all the project files and images you need to complete each project.