Using_ActionScript_3.0_Components.pdf

(1958 KB) Pobierz
Using ActoinScript 3.0 Components
USING ACTIONSCRIPT
3.0
COMPONENTS
114123666.001.png
© 2007 Adobe Systems Incorporated. All rights reserved.
Using ActionScript™ 3.0 Components
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 and may 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, stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems 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 Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability
for any errors or inaccuracies that may appear in the informational content 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 unauthorized incorporation 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 required from 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, ActionScript, Flash, Flash Player, and Flash Video are either registered trademarks or trademarks of
Adobe Systems Incorporated in the United States and/or other countries.
Macintosh is a trademark of Apple Inc., registered in the United States and other countries. Windows is either a registered
trademark or a trademark of Microsoft Corporation in the United States and/or 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.iis.fhg.de/amm/). You cannot use the
MP3 compressed audio within the Software for real time or live broadcasts. If you require an MP3 decoder for real time or live
broadcasts, you are responsible for obtaining this MP3 technology license. Speech compression and decompression technology
licensed from Nellymoser, Inc. (www.nellymoser.com). Flash CS3 video 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/).
Sorenson Spark™ video compression and decompression technology licensed from
Sorenson Media, Inc.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA.
Notice 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 and Commercial Computer Software
Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as
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 applicable equal opportunity laws including, if appropriate, the
provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance 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.
114123666.002.png 114123666.003.png
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
System requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
About the documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Terms used in this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Additional resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Chapter 1: About ActionScript 3.0 Components. . . . . . . . . . . . . . 15
Benefits of using components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Component types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Adding to and deleting from a document . . . . . . . . . . . . . . . . . . . . . . . . 20
Deleting a component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Finding the version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ActionScript 3.0 event handling model . . . . . . . . . . . . . . . . . . . . . . . . . . 24
A simple application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Design of the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Creating the Greetings application. . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Running subsequent examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Chapter 2: Working with Components . . . . . . . . . . . . . . . . . . . . . .33
Component architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
ActionScript 3.0 FLA-based components . . . . . . . . . . . . . . . . . . . . 34
SWC-based Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The ActionScript 3.0 Components API . . . . . . . . . . . . . . . . . . . . . . . 36
Working with component files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Where component files are stored. . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Where component source files are stored . . . . . . . . . . . . . . . . . . . . . .37
Component source files and Classpath . . . . . . . . . . . . . . . . . . . . . . . 38
Modifying the component files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Debugging component applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Setting parameters and properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Setting component properties in ActionScript . . . . . . . . . . . . . . . . . 42
The library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3
Sizing components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Live Preview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Handling events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
About event listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
About the event object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Working with the display list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Adding a component to the display list . . . . . . . . . . . . . . . . . . . . . . . . 49
Moving a component in the display list . . . . . . . . . . . . . . . . . . . . . . . . 49
Removing a component from the display list . . . . . . . . . . . . . . . . . . . 50
Working with FocusManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Working with List-based components . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Working with a DataProvider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Creating a DataProvider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Using the dataProvider parameter . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Using ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Manipulating a DataProvider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Working with a CellRenderer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Formatting cells. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Defining a custom CellRenderer class . . . . . . . . . . . . . . . . . . . . . . . . . 64
CellRenderer properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Applying a CellRenderer for a column of a DataGrid object . . . . . . 70
Defining a CellRenderer for an editable cell . . . . . . . . . . . . . . . . . . . . 70
Using an image, SWF file, or movie clip as a CellRenderer. . . . . . . .71
Making components accessible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71
Chapter 3: Using the UI Components. . . . . . . . . . . . . . . . . . . . . . . 73
Using the Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
User interaction with the Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Button parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Creating an application with the Button . . . . . . . . . . . . . . . . . . . . . . . . 75
Using the CheckBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
User interaction with the CheckBox . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
CheckBox parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Creating an application with the CheckBox . . . . . . . . . . . . . . . . . . . . 78
Using the ColorPicker. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
User interaction with the ColorPicker . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ColorPicker parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Creating an application with the ColorPicker . . . . . . . . . . . . . . . . . . . 82
Using the ComboBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
User interaction with the ComboBox . . . . . . . . . . . . . . . . . . . . . . . . . . 84
ComboBox parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Creating an application with the ComboBox . . . . . . . . . . . . . . . . . . . 85
Using the DataGrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
User interaction with the DataGrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4tts
DataGrid parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Creating an application with the DataGrid . . . . . . . . . . . . . . . . . . . . . 90
Using the Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
User interaction with the Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Label parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Creating an application with the Label . . . . . . . . . . . . . . . . . . . . . . . . 94
Using the List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
User interaction with the List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
List parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Creating an application with the List . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Using the NumericStepper. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
User interaction with the NumericStepper . . . . . . . . . . . . . . . . . . . . . 101
NumericStepper parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .102
Creating an application with the NumericStepper . . . . . . . . . . . . . .102
Using the ProgressBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
User interaction with the ProgressBar . . . . . . . . . . . . . . . . . . . . . . . .105
ProgressBar parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Creating an application with the ProgressBar . . . . . . . . . . . . . . . . . .106
Using the RadioButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
User interaction with the RadioButton . . . . . . . . . . . . . . . . . . . . . . . . . 111
RadioButton parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Creating an application with the RadioButton. . . . . . . . . . . . . . . . . . 112
Using the ScrollPane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
User interaction with the ScrollPane . . . . . . . . . . . . . . . . . . . . . . . . . . 115
ScrollPane parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Creating an application with the ScrollPane . . . . . . . . . . . . . . . . . . . 116
Using the Slider. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
User interaction with the Slider component. . . . . . . . . . . . . . . . . . . . 118
Slider parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Creating an application with the Slider . . . . . . . . . . . . . . . . . . . . . . . . 118
Using the TextArea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
User interaction with the TextArea. . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
TextArea parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122
Creating an application with the TextArea . . . . . . . . . . . . . . . . . . . . .122
Using TextInput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124
User interaction with TextInput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
TextInput parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .125
Creating an application with TextInput . . . . . . . . . . . . . . . . . . . . . . . .125
Using the TileList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
User interaction with the TileList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
TileList parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129
Creating an application with the TileList . . . . . . . . . . . . . . . . . . . . . . .130
Using the UILoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
User interaction with the UILoader . . . . . . . . . . . . . . . . . . . . . . . . . . .132
UILoader parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .132
Contents
5
Zgłoś jeśli naruszono regulamin