Danh mục

Removing Dynamically Created Content

Số trang: 4      Loại file: pdf      Dung lượng: 16.33 KB      Lượt xem: 10      Lượt tải: 0    
Jamona

Phí tải xuống: 1,000 VND Tải xuống file đầy đủ (4 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Movie clip trường hợp đó được tạo ra bằng cách sử dụng duplicateMovieClip () hoặc attachMovie (), chẳng hạn như các biểu tượng được kéo hay thả vào canvas_mc, có thể được gỡ bỏ bằng cách sử dụng một phương pháp của lớp Movie Clip được gọi là removeMovieClip (). Chú ý Bạn không thể sử dụng phương pháp này để loại bỏ các trường hợp clip bộ phim mà không tạo ra sử dụng ActionScript
Nội dung trích xuất từ tài liệu:
Removing Dynamically Created Content < Day Day Up >Removing Dynamically Created ContentYou can easily remove dynamically drawn lines from a timeline using the clear() method.Heres the syntax:path.clear();Movie clip instances that are created using duplicateMovieClip() or attachMovie(), suchas icons that are dragged and dropped onto canvas_mc, can be removed using a methodof the Movie Clip class called removeMovieClip().NOTEYou cant use this method to remove movie clip instances that were not created usingActionScript—that is, instances that youve actually dragged from the library and placedon the stage.Removing movie clip instances can be useful for dynamically clearing the stage content,freeing system resources, reinitializing applications, or adding functionality to someapplications. The syntax is simple:someMovieClip.removeMovieClip()In this exercise, youll create a function that will clear the canvas of all dynamicallydrawn lines as well as instances of the icon_mc movie clip instance that might be draggedand dropped onto canvas_mc. 1. Open draw4.fla. This is the file as you left it at the end of the preceding exercise. In this exercise, youll add a function to Frame 1 in the Actions layer of the main timeline that will clear the canvas of any content, and youll add a script to the Clear button in the window2_mc movie clip instance that calls this function.2. With the Actions panel open, select Frame 1 of the Actions layer and add the following function definition at the end of the current script:3.4. function clearContent() {5.6. _root.holder_mc.clear();7.8. for (var i = 0; i 3. Double-click the window2_mc instance to edit it in place. Move the playhead to the admin frame label. Select the frame on the Actions layer and add the following script:4.5. clear_btn.onRelease = function() {6.7. _root.clearContent();8.9. };10. This frame contains two buttons: clear_btn and print_btn. The script added in this step defines an onRelease event handler for the clear_btn button instance. When clicked, the clearContent() function on the main timeline is called, clearing the canvas of content.4. On the same frame, add the following script for the print_btn button instance:5.6. print_btn.onRelease = function() {7.8. printAsBitmap(_root, bmovie);9.10. };11. When the print_btn button is released, the graphical content of the _root timeline, as well as of any of its child movies (essentially, everything you see, including dynamically created instances), will be printed as a bitmap graphic at actual size. NOTE This script demonstrates how dynamically created instances can be printed as easily as anything else. Had we wanted to get a bit more sophisticated, we might have opted to print only what was drawn on the canvas itself; however, this would require some different syntax in our various functions, and printing options are not the focus of this exercise. Youll see more on printing in Lesson 21, Printing and Context Menus.5. Choose Control > Test Movie to test the movie. Draw a few lines and then click the Clear button. When you click the Clear button, the clearContent() function is executed and the for loop iterates through and deletes every created movie clip instance.6. Close this movie and save your work as draw5.fla. This completes the exercise and the lesson. As you have learned, the dynamic removal of content is even easier than its creation; however, knowing how to do both allows your projects to scale and change in many ways based on user input and interaction. < Day Day Up >

Tài liệu được xem nhiều: