ProgrammingADOBE ACTIONSCRIPT 3.0     ®                   ®               Updated 11 February 2009
© 2008 Adobe Systems Incorporated. All rights reserved.CopyrightProgramming Adobe® ActionScript® 3.0 for Adobe® Flash®If t...
iiiContentsChapter 1: About this manualUsing this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH iv                                                                                 ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH v                                                                                  ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH vi                                                                                 ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH vii                                                                                ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH viii                                                                               ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH ix                                                                                 ...
1Chapter 1: About this manualThis manual provides a foundation for developing applications in Adobe® ActionScript® 3.0. To...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 2                                                                                  ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 3                                                                                  ...
4Chapter 2: Introduction to ActionScript3.0This chapter provides an overview of Adobe® ActionScript® 3.0, the newest and m...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 5                                                                                  ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 6                                                                                  ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 7                                                                                  ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 8                                                                                  ...
9Chapter 3: Getting started withActionScriptThis chapter is designed to get you started with ActionScript programming and ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 10                                                                                 ...
PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 11                                                                                 ...
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Flash as3 programming
Upcoming SlideShare
Loading in...5
×

Flash as3 programming

6,226

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,226
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Flash as3 programming

  1. 1. ProgrammingADOBE ACTIONSCRIPT 3.0 ® ® Updated 11 February 2009
  2. 2. © 2008 Adobe Systems Incorporated. All rights reserved.CopyrightProgramming Adobe® ActionScript® 3.0 for Adobe® Flash®If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is furnished under license andmay be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, storedin a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of AdobeSystems Incorporated. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end-user license agreement.The content of this guide is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by AdobeSystems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in the informationalcontent contained in this guide.Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorizedincorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission requiredfrom the copyright owner.Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any actual organization.Adobe, the Adobe logo, Adobe AIR, ActionScript, Flash, Flash Lite, Flex, Flex Builder, MXML, and Pixel Bender are either registered trademarks or trademarksof Adobe Systems Incorporated in the United States and/or other countries.ActiveX and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and other countries. Macintosh is atrademark of Apple Inc., registered in the United States and other countries. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the UnitedStates and other countries. All other trademarks are the property of their respective owners.This product includes software developed by the Apache Software Foundation (http://www.apache.org/).MPEG Layer-3 audio compression technology licensed by Fraunhofer IIS and Thomson Multimedia (http://www.mp3licensing.com)Speech compression and decompression technology licensed from Nellymoser, Inc. (www.nellymoser.com).Video compression and decompression is powered by On2 TrueMotion video technology. © 1992-2005 On2 Technologies, Inc. All Rights Reserved.http://www.on2.com.This product includes software developed by the OpenSymphony Group (http://www.opensymphony.com/).This product contains either BSAFE and/or TIPEM software by RSA Security, Inc. Sorenson Spark™ video compression and decompression technology licensed from Sorenson Media, Inc.Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USANotice to U.S. government end users. The software and documentation are “Commercial Items,” as that term is defined at 48 C.F.R. §2.101, consisting of“Commercial Computer Software” and “Commercial Computer Software Documentation,” as such terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202,as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R. §§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software andCommercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial items and (b) with only those rightsas are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States.Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S. Government End Users, Adobe agrees to comply with all applicableequal opportunity laws including, if appropriate, the provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans ReadjustmentAssistance Act of 1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1 through 60-60,60-250 ,and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be incorporated by reference. Updated 11 February 2009
  3. 3. iiiContentsChapter 1: About this manualUsing this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Accessing ActionScript documentation ................................................................................ 2ActionScript learning resources ........................................................................................ 3Chapter 2: Introduction to ActionScript 3.0About ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Advantages of ActionScript 3.0 ........................................................................................ 4What’s new in ActionScript 3.0 ......................................................................................... 5Compatibility with previous versions ................................................................................... 7Chapter 3: Getting started with ActionScriptProgramming fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Working with objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Common program elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Example: Animation portfolio piece . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Building applications with ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Creating your own classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Example: Creating a basic application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Running subsequent examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34Chapter 4: ActionScript language and syntaxLanguage overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Objects and classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Packages and namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Chapter 5: Object-oriented programming in ActionScriptBasics of object-oriented programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Advanced topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Example: GeometricShapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122Chapter 6: Working with dates and timesBasics of dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Managing calendar dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Updated 11 February 2009
  4. 4. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH iv ContentsControlling time intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Example: Simple analog clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Chapter 7: Working with stringsBasics of strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139Creating strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140The length property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Working with characters in strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Comparing strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Obtaining string representations of other objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Concatenating strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Finding substrings and patterns in strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Converting strings between uppercase and lowercase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Example: ASCII art . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Chapter 8: Working with arraysBasics of arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Indexed arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155Associative arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Multidimensional arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Cloning arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169Advanced topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170Example: PlayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Chapter 9: Handling errorsBasics of error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179Types of errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Error handling in ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183Working with the debugger versions of Flash Player and AIR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Handling synchronous errors in an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185Creating custom error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189Responding to error events and status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190Comparing the Error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193Example: CustomErrors application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Chapter 10: Using regular expressionsBasics of regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203Regular expression syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205Methods for using regular expressions with strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Example: A Wiki parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Chapter 11: Working with XMLBasics of XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223The E4X approach to XML processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226XML objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228XMLList objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Initializing XML variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Assembling and transforming XML objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Updated 11 February 2009
  5. 5. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH v ContentsTraversing XML structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Using XML namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238XML type conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239Reading external XML documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240Example: Loading RSS data from the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Chapter 12: Handling eventsBasics of handling events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244How ActionScript 3.0 event handling differs from earlier versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246The event flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248Event objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Event listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254Example: Alarm Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260Chapter 13: Display programmingBasics of display programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266Core display classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270Advantages of the display list approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271Working with display objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273Manipulating display objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285Animating objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303Loading display content dynamically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304Example: SpriteArranger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307Chapter 14: Using the drawing APIBasics of using the drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314Understanding the Graphics class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316Drawing lines and curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316Drawing shapes using built-in methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318Creating gradient lines and fills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319Using the Math class with drawing methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323Animating with the drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324Example: Algorithmic Visual Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324Advanced use of the drawing API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326Drawing Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Defining winding rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329Using graphics data classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331About using drawTriangles() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333Chapter 15: Working with geometryBasics of geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334Using Point objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336Using Rectangle objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337Using Matrix objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340Example: Applying a matrix transformation to a display object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 Updated 11 February 2009
  6. 6. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH vi ContentsChapter 16: Filtering display objectsBasics of filtering display objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346Creating and applying filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347Available display filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353Example: Filter Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369Chapter 17: Working with Pixel Bender shadersBasics of Pixel Bender shaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376Loading or embedding a shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378Accessing shader metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379Specifying shader input and parameter values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380Using a shader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386Chapter 18: Working with movie clipsBasics of movie clips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398Working with MovieClip objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400Controlling movie clip playback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400Creating MovieClip objects with ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402Loading an external SWF file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405Example: RuntimeAssetsExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406Chapter 19: Working with motion tweensBasics of Motion Tweens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410Copying motion tween scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411Incorporating motion tween scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412Describing the animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412Adding filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415Associating a motion tween with its display objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416Chapter 20: Working with inverse kinematicsBasics of Inverse Kinematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418Animating IK Armatures Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419Getting information about an IK armature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421Instantiating an IK Mover and Limiting Its Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421Moving an IK Armature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422Using IK Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422Chapter 21: Working with textBasics of working with text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424Using the TextField class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426Using the Flash Text Engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447Chapter 22: Working with bitmapsBasics of working with bitmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474The Bitmap and BitmapData classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476Manipulating pixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478Copying bitmap data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480Making textures with noise functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 Updated 11 February 2009
  7. 7. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH vii ContentsScrolling bitmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483Taking advantage of mipmapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484Example: Animated spinning moon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484Chapter 23: Working in three dimensions (3D)Basics of 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495Understanding the 3D features of Flash Player and the AIR runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496Creating and moving 3D objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498Projecting 3D objects onto a 2D view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500Example: Perspective projection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502Performing complex 3D transformations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504Using triangles for 3D effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507Chapter 24: Working with videoBasics of video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515Understanding video formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517Understanding the Video class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519Loading video files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520Controlling video playback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520Playing video in full-screen mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522Streaming video files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526Understanding cue points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526Writing callback methods for metadata and cue points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527Using cue points and metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531Capturing camera input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541Sending video to a server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547Advanced topics for FLV files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547Example: Video Jukebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548Chapter 25: Working with soundBasics of working with sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554Understanding the sound architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556Loading external sound files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557Working with embedded sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559Working with streaming sound files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560Working with dynamically generated audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561Playing sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563Security considerations when loading and playing sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566Controlling sound volume and panning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566Working with sound metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568Accessing raw sound data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569Capturing sound input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573Example: Podcast Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576Chapter 26: Capturing user inputBasics of user input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584Capturing keyboard input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 Updated 11 February 2009
  8. 8. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH viii ContentsCapturing mouse input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587Example: WordSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591Chapter 27: Networking and communicationBasics of networking and communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595Working with external data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598Connecting to other Flash Player and AIR instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603Socket connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608Storing local data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612Working with data files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614Example: Building a Telnet client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628Example: Uploading and downloading files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631Chapter 28: Client system environmentBasics of the client system environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637Using the System class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639Using the Capabilities class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640Using the ApplicationDomain class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640Using the IME class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643Example: Detecting system capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648Chapter 29: Copy and pasteCopy-and-paste basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652Reading from and writing to the system clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652Clipboard data formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653Chapter 30: PrintingBasics of printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657Printing a page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658Flash Player and AIR tasks and system printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659Setting size, scale, and orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661Example: Multiple-page printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663Example: Scaling, cropping, and responding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665Chapter 31: Using the external APIBasics of using the external API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667External API requirements and advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669Using the ExternalInterface class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670Example: Using the external API with a web page container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674Example: Using the external API with an ActiveX container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679Chapter 32: Flash Player securityFlash Player security overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685Security sandboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686Permission controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688Restricting networking APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695Full-screen mode security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697Loading content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698 Updated 11 February 2009
  9. 9. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH ix ContentsCross-scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701Accessing loaded media as data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703Loading data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705Loading embedded content from SWF files imported into a security domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708Working with legacy content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708Setting LocalConnection permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709Controlling outbound URL access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709Shared objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711Camera, microphone, clipboard, mouse, and keyboard access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713 Updated 11 February 2009
  10. 10. 1Chapter 1: About this manualThis manual provides a foundation for developing applications in Adobe® ActionScript® 3.0. To best understand theideas and techniques described, you should already be familiar with general programming concepts such as data types,variables, loops, and functions. You should also understand basic object-oriented programming concepts such asclasses and inheritance. Prior knowledge of ActionScript 1.0 or ActionScript 2.0 is helpful but not necessary.Using this manualThe chapters in this manual are organized into the following logical groups to help you better find related areas ofActionScript documentation:Chapters DescriptionChapters 2 through 5, overview of ActionScript Discusses core ActionScript 3.0 concepts, including language syntax, statementsprogramming and operators, and object-oriented ActionScript programming.Chapters 6 through 11, core ActionScript 3.0 data types Describes top-level data types in ActionScript 3.0.and classesChapters 12 through 32, Flash Player and Adobe AIR Describes important features that are implemented in packages and classes specificAPIs to Adobe Flash Player and Adobe AIR, including event handling, working with display objects and the display list, networking and communications, file input and output, the external interface, the application security model, and more.This manual also contains numerous sample files that demonstrate application programming concepts for importantor commonly used classes. Sample files are packaged in ways to make them easier to load and use with Adobe® Flash®CS4 Professional and may include wrapper files. However, the core sample code is pure ActionScript 3.0 that you canuse in whichever development environment you prefer.ActionScript 3.0 can be written and compiled a number of ways, including:• Using the Adobe Flex Builder 3 development environment• Using any text editor and a command-line compiler, such as the one provided with Flex Builder 3• Using the Adobe® Flash® CS4 Professional authoring toolFor more information about ActionScript development environments, see “Introduction to ActionScript 3.0” onpage 4To understand the code samples in this manual, you don’t need to have prior experience using integrated developmentenvironments for ActionScript, such as Flex Builder or the Flash authoring tool. You will, however, want to refer tothe documentation for those tools to learn how to use them to write and compile ActionScript 3.0 code. For moreinformation, see “Accessing ActionScript documentation” on page 2. Updated 11 February 2009
  11. 11. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 2 About this manualAccessing ActionScript documentationBecause this manual focuses on describing ActionScript 3.0, which is a rich and powerful object-orientedprogramming language, it does not extensively cover the application development process or workflow within aparticular tool or server architecture. So in addition to Programming ActionScript 3.0, you’ll want to consult othersources of documentation as you design, develop, test, and deploy ActionScript 3.0 applications.ActionScript 3.0 documentationThis manual familiarizes you with the concepts behind the ActionScript 3.0 programming language and gives youimplementation details and samples illustrating important language features. However, this manual is not a completelanguage reference. For that, see the ActionScript 3.0 Language and Components Reference, which describes everyclass, method, property, and event in the language. The ActionScript 3.0 Language and Components Referenceprovides detailed reference information about the core language, Flash authoring tool components (in the fl packages),and Flash Player and Adobe AIR APIs (in the flash packages).Flash documentationIf you use the Flash authoring tool, you may want to consult these manuals:Book DescriptionUsing Flash Describes how to develop your dynamic web applications in the Flash authoring toolProgramming ActionScript 3.0 Describes specific usage of the ActionScript 3.0 language and core Flash Player and Adobe AIR APIActionScript 3.0 Language and Components Reference Provides syntax, usage, and code examples for the Flash authoring tool components and ActionScript 3.0 APIUsing ActionScript 3.0 Components Explains the details of using components to develop applications created by FlashDeveloping Adobe AIR Applications with Flash CS4 Describes how to develop and deploy Adobe AIR applications using ActionScriptProfessional 3.0 and the Adobe AIR API in Flash.Learning ActionScript 2.0 in Adobe Flash Provides an overview of ActionScript 2.0 syntax and explains how to use ActionScript 2.0 when working with different types of objectsActionScript 2.0 Language Reference Provides syntax, usage, and code examples for the Flash authoring tool components and ActionScript 2.0 APIUsing ActionScript 2.0 Components Explains in detail how to use ActionScript 2.0 components to develop applications created by FlashActionScript 2.0 Components Language Reference Describes each component available in the Version 2 Adobe Component Architecture, along with its APIExtending Flash Describes the objects, methods, and properties available in the JavaScript APIGetting Started with Flash Lite 2.x Explains how to use Adobe® Flash® Lite™ 2.x to develop applications and provides syntax, usage, and code examples for the ActionScript features that are available with Flash Lite 2.xDeveloping Flash Lite 2.x Applications Explains how to develop Flash Lite 2.x applicationsIntroduction to Flash Lite 2.x ActionScript Introduces how to develop applications with Flash Lite 2.x and describes all the ActionScript features available to Flash Lite 2.x developers Updated 11 February 2009
  12. 12. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 3 About this manualBook DescriptionFlash Lite 2.x ActionScript Language Reference Provides syntax, usage, and code examples for the ActionScript 2.0 API that is available in Flash Lite 2.xGetting Started with Flash Lite 1.x Provides an introduction to Flash Lite 1.x and describes how to test your content using the Adobe® Device Central CS4 emulatorDeveloping Flash Lite 1.x Applications Describes how to develop applications for mobile devices using Flash Lite 1.xLearning Flash Lite 1.x ActionScript Explains how to use ActionScript in Flash Lite 1.x applications and describes all the ActionScript features available with Flash Lite 1.xFlash Lite 1.x ActionScript Language Reference Provides the syntax and usage of ActionScript elements that are available with Flash Lite 1.xActionScript learning resourcesIn addition to the content in these manuals, Adobe provides regularly updated articles, design ideas, and examples atthe Adobe Developer Center and the Adobe Design Center.Adobe Developer CenterThe Adobe Developer Center is your resource for up-to-the-minute information on ActionScript, articles about real-world application development, and information about important emerging issues. View the Developer Center atwww.adobe.com/devnet/.Adobe Design CenterLearn the latest in digital design and motion graphics. Browse work by leading artists, discover new design trends, andhone your skills with tutorials, key workflows, and advanced techniques. Check back twice a month for fresh tutorialsand articles, and inspirational gallery pieces. View the Design Center at www.adobe.com/designcenter/. Updated 11 February 2009
  13. 13. 4Chapter 2: Introduction to ActionScript3.0This chapter provides an overview of Adobe® ActionScript® 3.0, the newest and most revolutionary version ofActionScript.About ActionScriptActionScript is the programming language for the Adobe® Flash® Player and Adobe® AIR™ run-time environments. Itenables interactivity, data handling, and much more in Flash, Flex, and AIR content and applications.ActionScript is executed by the ActionScript Virtual Machine (AVM), which is part of Flash Player and AIR.ActionScript code is typically compiled into bytecode format (a sort of programming language that’s written andunderstood by computers) by a compiler, such as the one built into Adobe® Flash® CS4 Professional or Adobe® Flex™Builder™, or that is available in the Adobe® Flex™ SDK. The bytecode is embedded in SWF files, which are executed byFlash Player and AIR.ActionScript 3.0 offers a robust programming model that will be familiar to developers with a basic knowledge ofobject-oriented programming. Some of the key features of ActionScript 3.0 that improve over previous ActionScriptversions include the following:• A new ActionScript Virtual Machine, called AVM2, that uses a new bytecode instruction set and provides significant performance improvements• A more modern compiler code base that performs deeper optimizations than previous versions of the compiler• An expanded and improved application programming interface (API), with low-level control of objects and a true object-oriented model• An XML API based on the ECMAScript for XML (E4X) specification (ECMA-357 edition 2). E4X is a language extension to ECMAScript that adds XML as a native data type of the language.• An event model based on the Document Object Model (DOM) Level 3 Events SpecificationAdvantages of ActionScript 3.0ActionScript 3.0 goes beyond the scripting capabilities of previous versions of ActionScript. It is designed to facilitatethe creation of highly complex applications with large data sets and object-oriented, reusable code bases. WhileActionScript 3.0 is not required for content that runs in Adobe Flash Player, it opens the door to performanceimprovements that are only available with the AVM2, the new virtual machine. ActionScript 3.0 code can execute upto ten times faster than legacy ActionScript code.The older version of ActionScript Virtual Machine, AVM1, executes ActionScript 1.0 and ActionScript 2.0 code.AVM1 is supported by Flash Player 9 and 10 for backward compatibility with existing and legacy content. For moreinformation, see “Compatibility with previous versions” on page 7. Updated 11 February 2009
  14. 14. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 5 Introduction to ActionScript 3.0What’s new in ActionScript 3.0Although ActionScript 3.0 contains many classes and features that will be familiar to ActionScript programmers,ActionScript 3.0 is architecturally and conceptually different from previous versions of ActionScript. Theenhancements in ActionScript 3.0 include new features of the core language and an improved Flash Player API thatprovides increased control of low-level objects.Note: Adobe® AIR™ applications can also use the Flash Player APIs.Core language featuresThe core language defines the basic building blocks of the programming language, such as statements, expressions,conditions, loops, and types. ActionScript 3.0 contains many new features that speed up the development process.Run-time exceptionsActionScript 3.0 reports more error conditions than previous versions of ActionScript. Run-time exceptions are usedfor common error conditions, improving the debugging experience and enabling you to develop applications thathandle errors robustly. Run-time errors can provide stack traces annotated with source file and line numberinformation, helping you quickly pinpoint errors.Run-time typesIn ActionScript 2.0, type annotations were primarily a developer aid; at run time, all values were dynamically typed.In ActionScript 3.0, type information is preserved at run time, and used for a number of purposes. Flash Player andAdobe AIR perform run-time type checking, improving the system’s type safety. Type information is also used torepresent variables in native machine representations, improving performance and reducing memory usage.Sealed classesActionScript 3.0 introduces the concept of sealed classes. A sealed class possesses only the fixed set of properties andmethods that were defined at compile time; additional properties and methods cannot be added. This enables strictercompile-time checking, resulting in more robust programs. It also improves memory usage by not requiring aninternal hash table for each object instance. Dynamic classes are also possible using the dynamic keyword. All classesin ActionScript 3.0 are sealed by default, but can be declared to be dynamic with the dynamic keyword.Method closuresActionScript 3.0 enables a method closure to automatically remember its original object instance. This feature is usefulfor event handling. In ActionScript 2.0, method closures would not remember what object instance they were extractedfrom, leading to unexpected behavior when the method closure was invoked. The mx.utils.Delegate class was a popularworkaround, but it is no longer needed.ECMAScript for XML (E4X)ActionScript 3.0 implements ECMAScript for XML (E4X), recently standardized as ECMA-357. E4X offers a natural,fluent set of language constructs for manipulating XML. In contrast to traditional XML-parsing APIs, XML with E4Xperforms like a native data type of the language. E4X streamlines the development of applications that manipulateXML by drastically reducing the amount of code needed. For more information about the ActionScript 3.0implementation of E4X, see “Working with XML” on page 223.To view ECMA’s E4X specification, go to www.ecma-international.org. Updated 11 February 2009
  15. 15. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 6 Introduction to ActionScript 3.0Regular expressionsActionScript 3.0 includes native support for regular expressions so that you can quickly search for and manipulatestrings. ActionScript 3.0 implements support for regular expressions as they are defined in the ECMAScript (ECMA-262) edition 3 language specification.NamespacesNamespaces are similar to the traditional access specifiers used to control visibility of declarations (public, private,protected). They work as custom access specifiers, which can have names of your choice. Namespaces are outfittedwith a Universal Resource Identifier (URI) to avoid collisions, and are also used to represent XML namespaces whenyou work with E4X.New primitive typesActionScript 2.0 has a single numeric type, Number, a double-precision, floating-point number. ActionScript 3.0contains the int and uint types. The int type is a 32-bit signed integer that lets ActionScript code take advantage of thefast integer math capabilities of the CPU. The int type is useful for loop counters and variables where integers are used.The uint type is an unsigned, 32-bit integer type that is useful for RGB color values, byte counts, and more.Flash Player API featuresThe Flash Player APIs in ActionScript 3.0 contain many classes that allow you to control objects at a low level. Thearchitecture of the language is designed to be more intuitive than previous versions. While there are too many newclasses to cover in detail here, the following sections highlight some significant changes.Note: Adobe® AIR™ applications can also use the Flash Player APIs.DOM3 event modelDocument Object Model Level 3 event model (DOM3) provides a standard way of generating and handling eventmessages so that objects within applications can interact and communicate, maintaining their state and responding tochange. Patterned after the World Wide Web Consortium DOM Level 3 Events Specification, this model provides aclearer and more efficient mechanism than the event systems available in previous versions of ActionScript.Events and error events are located in the flash.events package. The Flash components framework uses the same eventmodel as the Flash Player API, so the event system is unified across the Flash platform.Display list APIThe API for accessing the Flash Player and Adobe AIR display list—the tree that contains any visual elements in theapplication—consists of classes for working with visual primitives.The new Sprite class is a lightweight building block, similar to the MovieClip class but more appropriate as a base classfor UI components. The new Shape class represents raw vector shapes. These classes can be instantiated naturally withthe new operator and can be dynamically re-parented at any time.Depth management is now automatic and built into Flash Player and Adobe AIR, rendering assignment of depthnumbers unnecessary. New methods are provided for specifying and managing the z-order of objects.Handling dynamic data and contentActionScript 3.0 contains mechanisms for loading and handling assets and data in your application that are intuitiveand consistent across the API. The new Loader class provides a single mechanism for loading SWF files and imageassets and provides a way to access detailed information about loaded content. The URLLoaderclass provides aseparate mechanism for loading text and binary data in data-driven applications. The Socket class provides a means toread and write binary data to server sockets in any format. Updated 11 February 2009
  16. 16. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 7 Introduction to ActionScript 3.0Low-level data accessVarious APIs provide low-level access to data that was never before available in ActionScript. For data that is beingdownloaded, the URLStream class, which is implemented by URLLoader, provides access to data as raw binary datawhile it is being downloaded. The ByteArray class lets you optimize reading, writing, and working with binary data.The new Sound API provides detailed control of sound through the SoundChannel and SoundMixer classes. New APIsdealing with security provide information about the security privileges of a SWF file or loaded content, enabling youto better handle security errors.Working with textActionScript 3.0 contains a flash.text package for all text-related APIs. The TextLineMetrics class provides detailedmetrics for a line of text within a text field; it replaces the TextFormat.getTextExtent() method in ActionScript 2.0.The TextField class contains a number of interesting new low-level methods that can provide specific informationabout a line of text or a single character in a text field. These methods include getCharBoundaries(), which returnsa rectangle representing the bounding box of a character, getCharIndexAtPoint(), which returns the index of thecharacter at a specified point, and getFirstCharInParagraph(), which returns the index of the first character in aparagraph. Line-level methods include getLineLength(), which returns the number of characters in a specified lineof text, and getLineText(), which returns the text of the specified line. A new Font class provides a means to manageembedded fonts in SWF files.Compatibility with previous versionsAs always, Flash Player provides full backward compatibility with previously published content. Any content that ranin previous versions of Flash Player runs in Flash Player 9 and later. The introduction of ActionScript 3.0 in FlashPlayer 9, however, does present some challenges for interoperability between old and new content running in FlashPlayer 9 or later. The compatibility issues include the following:• A single SWF file cannot combine ActionScript 1.0 or 2.0 code with ActionScript 3.0 code.• ActionScript 3.0 code can load a SWF file written in ActionScript 1.0 or 2.0, but it cannot access the SWF file’s variables and functions.• SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0. This means that SWF files authored in Flash 8 or Flex Builder 1.5 or earlier versions cannot load ActionScript 3.0 SWF files. The only exception to this rule is that an ActionScript 2.0 SWF file can replace itself with an ActionScript 3.0 SWF file, as long as the ActionScript 2.0 SWF file hasnt previously loaded anything into any of its levels. An ActionScript 2.0 SWF file can do this through a call to loadMovieNum(), passing a value of 0 to the level parameter.• In general, SWF files written in ActionScript 1.0 or 2.0 must be migrated if they are to work together with SWF files written in ActionScript 3.0. For example, say you created a media player using ActionScript 2.0. The media player loads various content that was also created using ActionScript 2.0. You cannot create new content in ActionScript 3.0 and load it in the media player. You must migrate the video player to ActionScript 3.0. If, however, you create a media player in ActionScript 3.0, that media player can perform simple loads of your ActionScript 2.0 content.The following tables summarize the limitations of previous versions of Flash Player in relation to loading new contentand executing code, as well as the limitations for cross-scripting between SWF files written in different versions ofActionScript. Updated 11 February 2009
  17. 17. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 8 Introduction to ActionScript 3.0Supported functionality Flash Player 7 Flash Player 8 Flash Player 9 and 10Can load SWFs published for 7 and earlier 8 and earlier 9 (or 10) and earlierContains this AVM AVM1 AVM1 AVM1 and AVM2Runs SWFs written in ActionScript 1.0 and 2.0 1.0 and 2.0 1.0 and 2.0, and 3.0In the following table, “Supported functionality” refers to content running in Flash Player 9 or later. Content runningin Flash Player 8 or earlier can load, display, execute, and cross-script only ActionScript 1.0 and 2.0.Supported functionality Content created in ActionScript 1.0 and 2.0 Content created in ActionScript 3.0Can load content and execute code in ActionScript 1.0 and 2.0 only ActionScript 1.0 and 2.0, and ActionScript 3.0content created inCan cross script content created in ActionScript 1.0 and 2.0 only (ActionScript 3.0 ActionScript 1.0 and 2.0 through through Local Connection) LocalConnection. ActionScript 3.0 Updated 11 February 2009
  18. 18. 9Chapter 3: Getting started withActionScriptThis chapter is designed to get you started with ActionScript programming and give you the background you’ll needto understand the concepts and examples in the rest of this manual. We’ll begin with a discussion of basicprogramming concepts, described in the context of how to apply them in ActionScript. We’ll also cover the essentialsof how to organize and build an ActionScript application.Programming fundamentalsSince ActionScript is a programming language, it will help you learn ActionScript if you first understand a few generalcomputer programming concepts.What computer programs doFirst of all, it’s useful to have a conceptual idea of what a computer program is and what it does. There are two mainaspects to a computer program:• A program is a series of instructions or steps for the computer to carry out.• Each step ultimately involves manipulating some piece of information or data.In a general sense, a computer program is just a list of step-by-step instructions that you give to the computer, whichit performs one by one. Each individual instruction is known as a statement. As you’ll see throughout this manual, inActionScript, each statement is written with a semicolon at the end.In essence, all that a given instruction in a program does is manipulate some bit of data that’s stored in the computer’smemory. In a simple case, you might instruct the computer to add two numbers and store the result in its memory. Ina more complex case, imagine there is a rectangle drawn on the screen, and you want to write a program to move itsomewhere else on the screen. The computer is keeping track of certain information about the rectangle—the x, ycoordinates where it’s located, how wide and tall it is, what color it is, and so forth. Each of those bits of informationis stored somewhere in the computer’s memory. A program to move the rectangle to a different location would havesteps like “change the x coordinate to 200; change the y coordinate to 150” (in other words, specifying new values tobe used for the x and y coordinates). Of course, the computer does something with this data to actually turn thosenumbers into the image that appears on the computer screen; but for the level of detail we’re interested in, it’s enoughto know that the process of “moving a rectangle on the screen” really just involves changing bits of data in thecomputer’s memory.Variables and constantsSince programming mainly involves changing pieces of information in the computer’s memory, there needs to be away to represent a single piece of information in the program. A variable is a name that represents a value in thecomputer’s memory. As you write statements to manipulate values, you write the variable’s name in place of the value;any time the computer sees the variable name in your program, it looks in its memory and uses the value it finds there.For example, if you have two variables named value1 and value2, each containing a number, to add those twonumbers you could write the statement:value1 + value2 Updated 11 February 2009
  19. 19. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 10 Getting started with ActionScriptWhen it’s actually carrying out the steps, the computer will look to see the values in each variable, and add themtogether.In ActionScript 3.0, a variable actually consists of three different parts:• The variable’s name• The type of data that can be stored in the variable• The actual value stored in the computer’s memoryWe’ve just discussed how the computer uses the name as a placeholder for the value. The data type is also important.When you create a variable in ActionScript, you specify the specific type of data that it will hold; from that point on,your program’s instructions can store only that type of data in the variable, and you can manipulate the value usingthe particular characteristics associated with its data type. In ActionScript, to create a variable (known as declaring thevariable), you use the var statement:var value1:Number;In this case, we’ve told the computer to create a variable named value1, which will hold only Number data (“Number”is a specific data type defined in ActionScript). You can also store a value in the variable right away:var value2:Number = 17;In Adobe Flash CS4 Professional, there is another way to declare a variable. When you place a movie clip symbol,button symbol, or text field on the Stage, you can give it an instance name in the Property inspector. Behind the scenes,Flash creates a variable with the same name as the instance name, which you can use in your ActionScript code to referto that Stage item. So, for example, if you have a movie clip symbol on the Stage and you give it the instance namerocketShip, whenever you use the variable rocketShip in your ActionScript code, you will in fact be manipulatingthat movie clip.A constant is very similar to a variable in the sense that it is a name that represents a value in the computer’s memory,with a specified data type. The difference is that a constant can only be assigned a value one time in the course of anActionScript application. Once a constant’s value is assigned, it is the same throughout the application. The syntax fordeclaring a constant is the same as that for declaring a variable, except that you use the const keyword instead of thevar keyword:const SALES_TAX_RATE:Number = 0.07;A constant is useful for defining a value that is used in multiple places throughout a project, which won’t change undernormal circumstances. Using a constant rather than a literal value makes your code more readable. For example, it’seasier to understand the purpose of a line of code that multiplies a price by SALES_TAX_RATE, compared to a line ofcode that muliplies the price by 0.07. In addition, if the value defined by a constant ever does need to change, if youuse a constant to represent that value throughout your project you only need to change the value in one place (theconstant declaration), instead of needing to change it in various places as you would if you use hard-coded literalvalues.Data typesIn ActionScript, there are many data types that you can use as the data type of the variables you create. Some of thesecan be thought of as “simple” or “fundamental” data types:• String: a textual value, like a name or the text of a book chapter• Numeric: ActionScript 3.0 includes three specific data types for numeric data: • Number: any numeric value, including values with or without a fraction • int: an integer (a whole number without a fraction) Updated 11 February 2009
  20. 20. PROGRAMMING ACTIONSCRIPT 3.0 FOR FLASH 11 Getting started with ActionScript • uint: an “unsigned” integer, meaning a whole number that can’t be negative• Boolean: a true-or-false value, such as whether a switch is on or whether two values are equalThe simple data types represent a single piece of information: for example, a single number or a single sequence of text.However, the majority of the data types defined in ActionScript could be described as complex data types, because theyrepresent a set of values grouped together. For example, a variable with the data type Date represents a single value—a moment in time. Nevertheless, that date value is actually represented as several values: the day, month, year, hours,minutes, seconds, and so on, all of which are individual numbers. So while we think of a date as a single value (and wecan treat it as a single value by creating a Date variable), internally the computer thinks of it as a group of several valuesthat, put together, define a single date.Most of the built-in data types, as well as data types defined by programmers, are complex data types. Some of thecomplex data types you might recognize are:• MovieClip: a movie clip symbol• TextField: a dynamic or input text field• SimpleButton: a button symbol• Date: information about a single moment in time (a date and time)Two words that are often used as synonyms for data type are class and object. A class is simply the definition of a datatype—it’s like a template for all objects of the data type, like saying “all variables of the Example data type have thesecharacteristics: A, B, and C.” An object, on the other hand, is just an actual instance of a class; a variable whose datatype is MovieClip could be described as a MovieClip object. The following are different ways of saying the same thing:• The data type of the variable myVariable is Number.• The variable myVariable is a Number instance.• The variable myVariable is a Number object.• The variable myVariable is an instance of the Number class.Working with objectsActionScript is what’s known as an object-oriented programming language. Object-oriented programming is simplyan approach to programming—really nothing more than a way to organize the code in a program, using objects.Earlier we defined a computer program as a series of steps or instructions that the computer performs. Conceptually,then, we might imagine a computer program as just a single long list of instructions. However, in object-orientedprogramming, the program instructions are divided among different objects—the code is grouped into chunks offunctionality, so related types of functionality or related pieces of information are grouped together in one container.In fact, if you’ve worked with symbols in Flash, you’re already used to working with objects. Imagine you’ve defined amovie clip symbol—let’s say it’s a drawing of a rectangle—and you’ve placed a copy of it on the Stage. That movie clipsymbol is also (literally) an object in ActionScript; it’s an instance of the MovieClip class.There are various characteristics of the movie clip that you can modify. For example, when it’s selected there are valuesyou can change in the Property inspector, like its x coordinate, or its width, or various color adjustments like changingits alpha (transparency), or applying a drop-shadow filter to it. Other Flash tools let you make more changes, like usingthe Free Transform tool to rotate the rectangle. All of these things that you can do to modify a movie clip symbol inthe Flash authoring environment are also things you can do in ActionScript by changing the pieces of data that are allput together into a single bundle called a MovieClip object. Updated 11 February 2009

×