tailieunhanh - adobe press ActionScript 3.0 for ADOBE FLASH PROFESSIONAL CS5 Classroom in a Book phần 4
Dòng 16 và 17 ở đây (con số của bạn dòng có thể khác nhau) cả hai thành phần ProgressBar và lĩnh vực văn bản mà bạn đã tạo để có thể nhìn thấy khi sự kiện ProgressEvent diễn ra. Dòng 18 tạo ra% địa phương mới biến được gọi là lưu trữ tài sản percentLoaded của các thành phần UILoader. Tài sản này nên thay đổi mỗi thời điểm sự kiện ProgressEvent diễn ra. | In the Actions panel below the existing code add the following function 14 function progreỉtHaodler e Pro0rtỉỉtvant void 15 16 true 17 true 18 var percent tnt 19 . String of String Bytes n c percent loaded 2 bor setProgress Looded 21 Notice that the parameter for the progressHandler function has the data type of ProgressEvent. The ProgressEvent event works very similarly to the events you have already used. Lines 16 and 17 here your line numbers may vary set both the ProgressBar component and the text field you created to visible when the ProgressEvent event takes place. Line 18 creates a new local variable called percent and stores the percentLoaded property of the UILoader component. This property should change every time the ProgressEvent event takes place. The percent variable keeps track of the percentage of the requested file that has been loaded. Notice that the data type of the percent variable is set to int. Previously when you have stored a numeric value in a variable you have set the data type to Number. The reason that int was chosen in this case is that unlike the Number data type which can return any number including fractions int will always return an integer in this case an integer between 0 and 100. Now your users will read that say 49 percent of the file has loaded rather than percent. Line 19 is where the text feedback is created for the user. First two additional very useful properties of the UILoader class are used. The bytesLoaded property not surprisingly returns the number of bytes of the file loaded equally intuitively the bytesTotal property returns the total number of bytes for the entire file. These two properties are converted to strings so they can be added to a sentence that tells the user how many bytes of the total have loaded. The characters n force a new line in the text field and then
đang nạp các trang xem trước