TAILIEUCHUNG - Học Actionscript 3.0 - p 12

Managing Object Names, Positions, and Data Types However, the ActionScript compiler doesn’t know if gotoAndStop() is a legal method of mc’s parent because it doesn’t know the parent’s data type. For example, the parent might be a sprite and a sprite doesn’t have a timeline. As such, you can’t very well go to frame 20 of a sprite. If the data type of the parent is unknown to the ActionScript compiler, you will get an error similar to: Call to a possibly undefined method gotoAndStop through a reference with static type . You can avoid this error by casting the object. Previously discussed in Chapter 2, casting is particularly important when manipulating the display list. | Managing Object Names Positions and Data Types However the ActionScript compiler doesn t know if gotoAndStop is a legal method of mcs parent because it doesn t know the parent s data type. For example the parent might be a sprite and a sprite doesn t have a timeline. As such you can t very well go to frame 20 of a sprite. If the data type of the parent is unknown to the ActionScript compiler you will get an error similar to Call to a possibly undefined method gotoAndStop through a reference with static type DisplayObjectContainer. You can avoid this error by casting the object. Previously discussed in Chapter 2 casting is particularly important when manipulating the display list and warrants another mention. Casting means you are explicitly telling the ActionScript compiler the data type of the object changing the compiler s understanding of the data from one type to another. Casting does not actually change data. In our example to make sure the compiler doesn t object to the gotoAndStop method you must cast the parent from DisplayObjectContainer to MovieClip. You can do this by surrounding the object of unknown type with the desired class name. The following syntax tells the compiler that mc s parent is of data type MovieClip MovieClip .gotoAndStop 20 NOTE Another way to cast an object is by using the as operator. Continuing the example on this page this syntax will also cast mc s parent as a movie clip var mc2 MovieClip as MovieClip 20 Although this is more verbose it has advantages. For example the ClassName syntax may be confusing because it looks like you are calling a function or instantiating a class. Also some conversion or creation functions takes precedence over casting and prevents casting from working. For example Array will not cast to an array because that syntax is equivalent to new Array which creates an array. This means it s possible to cast an object to Array only using the as operator. One reason

TÀI LIỆU MỚI ĐĂNG
11    168    2    28-12-2024
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.