ActionScript Elements
Số trang: 8
Loại file: pdf
Dung lượng: 31.13 KB
Lượt xem: 16
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
ActionScript là một ngôn ngữ mà các cầu khoảng cách giữa những gì bạn hiểu và hiểu những gì Flash. Như vậy, nó cho phép bạn cung cấp cho cả hai hướng dẫn hành động theo định hướng (làm điều này) và hướng dẫn theo định hướng logic (phân tích này trước khi làm điều đó) trong dự án Flash của bạn. Giống như tất cả ngôn ngữ, ActionScript chứa nhiều yếu tố khác nhau, như từ ngữ, dấu chấm câu, và cơ cấu-tất cả trong đó bạn phải sử dụng đúng cách để có được dự án Flash của...
Nội dung trích xuất từ tài liệu:
ActionScript Elements < Day Day Up >ActionScript ElementsActionScript is a language that bridges the gap between what you understand and whatFlash understands. As such, it allows you to provide both action-oriented instructions (dothis) and logic-oriented instructions (analyze this before doing that) in your Flash project.Like all languages, ActionScript contains many different elements, such as words,punctuation, and structure—all of which you must employ properly to get your Flashproject to behave the way you want it to. If you dont employ ActionScript correctly,youll find that interactivity either wont occur or wont work the way you intended. Manyof these elements, as well as several other elements such as logical statements andexpressions, will be covered in more detail throughout the book.To begin to understand how ActionScript works, look at this sample script, whichcontains many of the essential elements that make up a typical script. After the script is adiscussion of these elements and their role in the scripts execution.We can assume that this script is attached to a button:on (release) { //set the cost of the mug var mugCost:Number = 5.00; //set the local sales tax percentage var taxPercent:Number = .06; //determine the dollar amount of tax var totalTax:Number = mugCost * taxPercent; //determine the total amount of the transaction var totalCost:Number = mugCost + totalTax; //display a custom message myTextBox_txt.text = The total cost of your transaction is + totalCost; //send the cashRegister_mc movie clip instance to frame 50 cashRegister_mc.gotoAndPlay (50);}Although at first glance this may look like Latin, once you become acquainted with someof its elements, youll understand.NOTEOther script elements (for example, objects, functions, loops, properties, and methods)are discussed in detail throughout the book.EventsEvents occur during the playback of a movie and trigger the execution of a particularscript. In our sample script, the event that triggers the script is on (release). This eventsignifies that when the button to which this script is attached is released, the script willexecute. Every script is triggered by an event, and your movie can react to numerousevents—everything from a button being pressed to text changing in a text field to a soundcompleting its playback, and more. We will discuss events in depth in Lesson 2, UsingEvent Handlers.ActionsThese form the heart of your script. An action is usually considered to be any line thatinstructs Flash to do, set, create, change, load, or delete something.Here are some examples of actions from the sample script:var mugCost:Number = 5.00;cashRegister_mc.gotoAndPlay (50);The first line creates a variable named mugCost, sets its data type as Number (indicatingthe variable will hold a numeric value), and sets the value of the variable to 5.00. Thesecond line tells the cashRegister_mc movie clip instance to begin playing at Frame 50 ofits timeline.Generally speaking, most of the lines in a script that are within curly braces ({ } ) areactions. These lines are usually separated by semicolons (well discuss punctuationshortly).OperatorsThese include a number of symbols (=, , +, –, *, &&, etc.) and are used to connecttwo elements in a script in various ways. Take a look at these examples: • var taxPercent:Number = .06; assigns a numeric value of .06 to the variable named taxPercent • amountA < amountB asks if amountA is less than amountB • value1 * 500 multiplies value1 times 500KeywordsThese are words reserved for specific purposes within ActionScript syntax. As such, theycannot be used as variable, function, or label names. For example, the word on is akeyword and can only be used in a script to denote an event that triggers a script, such ason (press), on (rollOver), on (rollOut), and so on. Attempting to use keywords in yourscripts for anything other than their intended purpose will result in errors. Otherkeywords include break, case, class, continue, default, delete, do, dynamic, else, extends,finally, for, function, get, if, implements, import, interface, in, instanceof, new, null,private, public, return, set, static, switch, this, throw, try, typeof, undefined, var, void,while, and with.DataA dynamic script almost always creates, uses, or updates various pieces of data during itsexecution. Variables are the most common pieces of dynamic data found in scripts andrepresent pieces of data that have been given unique names. Once a variable has beencreated and assigned a value, that value can be accessed anywhere in the script simply byinserting the variables name.NOTEVariable names are case sensitive: myVariable and MyVariable are not the same.In our sample script, we created a variable named mugCost ...
Nội dung trích xuất từ tài liệu:
ActionScript Elements < Day Day Up >ActionScript ElementsActionScript is a language that bridges the gap between what you understand and whatFlash understands. As such, it allows you to provide both action-oriented instructions (dothis) and logic-oriented instructions (analyze this before doing that) in your Flash project.Like all languages, ActionScript contains many different elements, such as words,punctuation, and structure—all of which you must employ properly to get your Flashproject to behave the way you want it to. If you dont employ ActionScript correctly,youll find that interactivity either wont occur or wont work the way you intended. Manyof these elements, as well as several other elements such as logical statements andexpressions, will be covered in more detail throughout the book.To begin to understand how ActionScript works, look at this sample script, whichcontains many of the essential elements that make up a typical script. After the script is adiscussion of these elements and their role in the scripts execution.We can assume that this script is attached to a button:on (release) { //set the cost of the mug var mugCost:Number = 5.00; //set the local sales tax percentage var taxPercent:Number = .06; //determine the dollar amount of tax var totalTax:Number = mugCost * taxPercent; //determine the total amount of the transaction var totalCost:Number = mugCost + totalTax; //display a custom message myTextBox_txt.text = The total cost of your transaction is + totalCost; //send the cashRegister_mc movie clip instance to frame 50 cashRegister_mc.gotoAndPlay (50);}Although at first glance this may look like Latin, once you become acquainted with someof its elements, youll understand.NOTEOther script elements (for example, objects, functions, loops, properties, and methods)are discussed in detail throughout the book.EventsEvents occur during the playback of a movie and trigger the execution of a particularscript. In our sample script, the event that triggers the script is on (release). This eventsignifies that when the button to which this script is attached is released, the script willexecute. Every script is triggered by an event, and your movie can react to numerousevents—everything from a button being pressed to text changing in a text field to a soundcompleting its playback, and more. We will discuss events in depth in Lesson 2, UsingEvent Handlers.ActionsThese form the heart of your script. An action is usually considered to be any line thatinstructs Flash to do, set, create, change, load, or delete something.Here are some examples of actions from the sample script:var mugCost:Number = 5.00;cashRegister_mc.gotoAndPlay (50);The first line creates a variable named mugCost, sets its data type as Number (indicatingthe variable will hold a numeric value), and sets the value of the variable to 5.00. Thesecond line tells the cashRegister_mc movie clip instance to begin playing at Frame 50 ofits timeline.Generally speaking, most of the lines in a script that are within curly braces ({ } ) areactions. These lines are usually separated by semicolons (well discuss punctuationshortly).OperatorsThese include a number of symbols (=, , +, –, *, &&, etc.) and are used to connecttwo elements in a script in various ways. Take a look at these examples: • var taxPercent:Number = .06; assigns a numeric value of .06 to the variable named taxPercent • amountA < amountB asks if amountA is less than amountB • value1 * 500 multiplies value1 times 500KeywordsThese are words reserved for specific purposes within ActionScript syntax. As such, theycannot be used as variable, function, or label names. For example, the word on is akeyword and can only be used in a script to denote an event that triggers a script, such ason (press), on (rollOver), on (rollOut), and so on. Attempting to use keywords in yourscripts for anything other than their intended purpose will result in errors. Otherkeywords include break, case, class, continue, default, delete, do, dynamic, else, extends,finally, for, function, get, if, implements, import, interface, in, instanceof, new, null,private, public, return, set, static, switch, this, throw, try, typeof, undefined, var, void,while, and with.DataA dynamic script almost always creates, uses, or updates various pieces of data during itsexecution. Variables are the most common pieces of dynamic data found in scripts andrepresent pieces of data that have been given unique names. Once a variable has beencreated and assigned a value, that value can be accessed anywhere in the script simply byinserting the variables name.NOTEVariable names are case sensitive: myVariable and MyVariable are not the same.In our sample script, we created a variable named mugCost ...
Tìm kiếm theo từ khóa liên quan:
máy tính mạng máy tính internet phần mềm ứng dụng lập trình SQL HTML sever web XMLGợi ý tài liệu liên quan:
-
Giáo án Tin học lớp 9 (Trọn bộ cả năm)
149 trang 254 0 0 -
Ngân hàng câu hỏi trắc nghiệm môn mạng máy tính
99 trang 242 1 0 -
Bài giảng: Lịch sử phát triển hệ thống mạng
118 trang 236 0 0 -
47 trang 235 3 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 2
102 trang 233 0 0 -
Đề cương chi tiết học phần Thiết kế và cài đặt mạng
3 trang 233 0 0 -
80 trang 203 0 0
-
Giáo trình Hệ thống mạng máy tính CCNA (Tập 4): Phần 1
122 trang 200 0 0 -
122 trang 200 0 0
-
Giáo trình môn học/mô đun: Mạng máy tính (Ngành/nghề: Quản trị mạng máy tính) - Phần 1
68 trang 190 0 0