tailieunhanh - Removing Dynamically Created Content

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 | Removing Dynamically Created Content You can easily remove dynamically drawn lines from a timeline using the clear method. Here s the syntax Movie clip instances that are created using duplicateMovieClip or attachMovie such as icons that are dragged and dropped onto canvas_mc can be removed using a method of the Movie Clip class called removeMovieClip . NOTE You can t use this method to remove movie clip instances that were not created using ActionScript that is instances that you ve actually dragged from the library and placed on the stage. Removing movie clip instances can be useful for dynamically clearing the stage content freeing system resources reinitializing applications or adding functionality to some applications. The syntax is simple In this exercise you ll create a function that will clear the canvas of all dynamically drawn lines as well as instances of the icon_mc movie clip instance that might be dragged and dropped onto canvas_mc. 1. Open . This is the file as you left it at the end of the preceding exercise. In this exercise you ll add a function to Frame 1 in the Actions layer of the main timeline that will clear the canvas of any content and you ll 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. 7. 8. for var i 0 i iconDepth i 9. 10. var name String object i _mc 11. 12. _root name .removeMovieClip 13. 14. 15. 16. iconDepth 0 17. 18. 19. The first action in this function clears all dynamically drawn lines from the holder_mc movie clip instance using the clear method. A simple for loop is then used to remove any instances of the icon_mc movie clip instance that have been dragged and dropped onto the canvas. Because the value of iconDepth is incremented with