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

Removing Dynamically Created Content

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

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

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

Chủ đề:
Lưu

Nội dung Text: Removing Dynamically Created Content

  1. < Day Day Up > Removing Dynamically Created Content You can easily remove dynamically drawn lines from a timeline using the clear() method. Here's the syntax: path.clear(); 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: someMovieClip.removeMovieClip() 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 draw4.fla. 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. 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. 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.
  4. 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. You'll 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 >
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

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