intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Building Expressions

Chia sẻ: Qweqwdasd Qweqdasda | Ngày: | Loại File: PDF | Số trang:2

53
lượt xem
2
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Để bên phải của dấu bằng, bạn sẽ thấy 6 * 2-đây là một biểu thức. Khi lệnh này được thực hiện, sự biểu hiện 6 * 2 được thay thế bởi kết quả của 6 nhân với 2, hay 12. Như vậy, oneDozen bằng 12. Một biểu thức có thể chứa các biến, mảng, thậm chí chức năng cuộc gọi-bất cứ điều gì đó, khi đánh giá, trả về giá trị. Ví dụ: var tổng số: Số thuế = + Tổng;

Chủ đề:
Lưu

Nội dung Text: Building Expressions

  1. < Day Day Up > Building Expressions As we mentioned earlier in this lesson, an expression is a phrase—or a collection of variables, numbers, text, and operators—that evaluates to a value. To understand this concept, take a look at this example: var oneDozen:Number = 6 * 2; To the right of the equals sign, you see 6 * 2—this is an expression. When this script is executed, the expression 6 * 2 is replaced by the result of 6 multiplied by 2, or 12. Thus, oneDozen equals 12. An expression can contain variables, arrays, even function calls—anything that, when evaluated, returns a value. For example: var total:Number = subTotal + tax; The value of total is based on the result of adding the variable subTotal to the variable tax. The expression is subTotal + tax. var discount:Number = totalPrice * employeeDiscount[2]; The value of discount is based on the result of multiplying the variable totalPrice by the value of the third element in the employeeDiscount array; totalPrice * employeeDiscount[2] is the expression. Here: var usDollars:Number = 10; var japaneseYen:Number = convertToYen(usDollars);
  2. the value of japaneseYen is based on the value returned by a call to the convertToYen() function—making the function call itself the expression. NOTE For more information about functions, see Lesson 5, "Using Functions." Expressions are used to do the following: • Set variable values • Set array element values • Determine whether conditions are being met (using the comparison operators) • Dynamically name movie clips, variables, and objects • Call functions dynamically • And more Expressions enable you to avoid hard-coding values that will remain the same no matter what. By assigning and manipulating values via expressions, you can make the data used by your scripts dynamic—resulting in more interactive projects. Many of the scripts in this book rely on expressions—that's because without them, your project plays back in exactly the same way each time it's viewed. < Day Day Up >
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2