Download presentation
Presentation is loading. Please wait.
Published byIrma Little Modified over 9 years ago
1
Tutorial 8 Programming with ActionScript 3.0
2
XP Objectives Review the basics of ActionScript programming Compare ActionScript 2.0 and ActionScript 3.0 Learn ActionScript 3.0 syntax Write ActionScript 3.0 code to create functions and handle events New Perspectives on Adobe Flash CS32
3
XP Objectives Create links to external Web sites Create and test a Flash preloader Create input and dynamic text fields Create an input form New Perspectives on Adobe Flash CS33
4
XP Programming with ActionScript ActionScript: programming language in Flash ActionScript is used to make a document interactive – Examples: make buttons operational, process user input ActionScript may also be used to write applications Tutorial tasks involving the use of ActionScript – Control multimedia elements to access Web pages – Process data entered into input forms New Perspectives on Adobe Flash CS34
5
XP Working with Objects and Properties ActionScript is used to control and modify objects Object: Flash element with modifiable properties – Examples: buttons, movie clips, and text blocks Properties are identified by underscore; e.g., _alpha ActionScript examines and modifies many properties – Objects to be manipulated often require a name assignment Dot notation: links object to properties and methods – Example: circle_mc._alpha = 30 // mc stands for movie clip New Perspectives on Adobe Flash CS35
6
XP Using Actions, Methods, and Functions Action: statement passing instruction to SWF file Functions – Statement blocks that process data when called – Return a value or perform some action – Parameters or arguments: values passed to a function Methods are functions specific to a particular object – Use dot notation to bind a method to an object – Example: circle_mc.gotoAndPlay(10) New Perspectives on Adobe Flash CS36
7
XP Writing ActionScript Code Syntax: set of rules specifying valid code constructs ActionScript statements follow a specific syntax – Example: parentheses are required to group arguments Use Actions toolbox to limit syntax errors Some places where scripts are added: – Frame: script triggered when playhead reaches frame – Button: script activated when button clicked and released – Movie clip: script performed as part of a movie clip New Perspectives on Adobe Flash CS37
8
XP Writing ActionScript Code Syntax: rules you must follow Variable: container that holds data while SWF plays Keyword: word or phrase reserved for ActionScript – Examples: else, if, while, this Event object: represents an actual event Operators manipulate values in expressions New Perspectives on Adobe Flash CS38
9
XP ActionScript Syntax New Perspectives on Adobe Flash CS39
10
XP Adding Events and Event Handling Event source: object to which the event will happen Response: steps that are performed when the event occurs Event listener: method that the Flash Player executes in response to specific events New Perspectives on Adobe Flash CS310
11
XP Adding Comments Comments are notes within the ActionScript code that explain what is happening – Do not cause any actions to be performed New Perspectives on Adobe Flash CS311
12
XP Creating Links to Web Sites Objective: add links to a Resources page URLRequest(): loads a document into a browser window Format: URLRequest(url) – URL (uniform resource locator): address of the Web site Button clicks cause URLRequest () to load document New Perspectives on Adobe Flash CS312
13
XP URLRequest() Class New Perspectives on Adobe Flash CS313
14
XP Using a Flash Preloader SWF files are often downloaded to a client computer Factors affecting the download time of SWF files – Size of the file measured in kilobytes – Type of Internet connection; e.g., broadband or dial-up Large SWF file may require a long time to download Ways to overcome excessive download wait time: – Stream the content: play frames as content arrives – Add a preloader animation to advise user of status New Perspectives on Adobe Flash CS314
15
XP Examples of Preloaders New Perspectives on Adobe Flash CS315
16
XP Creating the Preloader Adding a preloader requires ActionScript code Pseudocode for the preloader logic – Get the total number of bytes – Get the number of bytes loaded – If the number of bytes loaded equals the total number of bytes: Play the rest of the SWF file – Otherwise: Continue playing the preloader animation New Perspectives on Adobe Flash CS316
17
XP Rectangle for Preloader Animation New Perspectives on Adobe Flash CS317
18
XP Creating a Preloader for the Jackson’s Youth Sports Web Site Objective: create a preloader on main page Specifications for preloader – Add preloader to revised version of Main.fla file – Preloader will start Frame 1 of its own layer – ActionScript is added to second frame of Actions layer New Perspectives on Adobe Flash CS318
19
XP ActionScript for Preloader New Perspectives on Adobe Flash CS319
20
XP Creating an Input Form How an input form works – User enters data into input fields – Input data processed by current page or Web server – Results of process are displayed One scenario involving an input form: – Visitor enters number and type of items to be purchased – Other fields display total price based on entry Input forms must include dynamic text and input text New Perspectives on Adobe Flash CS320
21
XP Using Dynamic and Input Text Static text: cannot be changed after document plays Dynamic text: defined to display variable contents – Variable can be manipulated to change value displayed Use the Text tool to create a dynamic text block – Select Dynamic Text type in the Property inspector Input text: allows user to enter text into text block Use Text tool to create an input text box – Select Input Text type in the Property inspector New Perspectives on Adobe Flash CS321
22
XP Input Text Block Properties New Perspectives on Adobe Flash CS322
23
XP Using Dynamic and Input Text Expression: statement assigning a value to a variable Two types of data: – String data: series of characters within quotation marks – Numeric data: numbers not enclosed with quotation marks Types of operators: – Assignment operator (=): assigns value to variable – Arithmetic operators: +, -, *, and / New Perspectives on Adobe Flash CS323
24
XP Creating the Team Jersey Calculator Page Objective: calculate costs for team jerseys Calculator requirements: – Four input text boxes to gather type, quantity, add- ons – Calculate button with ActionScript to process input data – Dynamic text block to display the total cost – Explanatory text for input text and calculate button Pseudocode: programming logic in English syntax Use pseudocode to design the script New Perspectives on Adobe Flash CS324
25
XP Complete ActionScript Code New Perspectives on Adobe Flash CS325
26
XP Creating the Team Jersey Calculator Page New Perspectives on Adobe Flash CS326
27
XP Adding Numeric Feedback to the Preloader Value in scaleX property of the rectangle can be displayed as a percentage in a dynamic text block New Perspectives on Adobe Flash CS327
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.