Deep understanding of Flash Player re-painting

Source: Internet
Author: User

Flash Player refreshes the content to be changed at the Frame Rate of the SWF Content. This refresh process is usually called redraw )", I believe that even the novice cainiao knows that as long as the debug Flash Player is used, the "show redraw regions (display redraw area)" option will be available in the right-click menu, when this option is enabled, we can clearly see the re-painted area in the current scene.

So under what circumstances will the re-painting happen? Bytes
1. The most common scenario is the shape, position, and status (alpha, scale…) of the visual components on the stage ...) The Flash Player re-painting is triggered when a change occurs.
2. When the level of a displayobject (childindex) changes, it will also cause re-painting.
3. When you set the buttonmode of a Sprite/movieclip to true, even if it is a single-Frame Animation, the re-painting will be triggered during mouseevent. mouse_down. Or when you set the displayobject level, even if the displayobject level does not change, flash player will re-paint the Display object.
Since the re-painting is to update the display content, a flash application will inevitably trigger re-painting. Repainting is the main source of performance consumption. For a flash application written by experienced Flash developers, its performance may be 70%-90% (or higher, therefore, there is a great relationship between improving the running efficiency of flash applications and reducing re-painting.
To reduce the number of redraws, first we need to quantify the concept of the size of each frame re-painting: the size of the re-painting should depend on the quantity and area. The quantity depends (but not entirely) on the number of display objects to be updated within the visible range. Suppose there are two blinking dots in the scenario and the width and height are both 20, so the number of redraws is 3, and the total area of the re-painting is: 20*20*3 = 1200 (square pixel ).
Bytes
Simply look at the formula above, do you think it is easy to calculate the re-painted area? Continue to estimate the area of the re-painting in the following situation:


If your calculation result is: 20*20*6 = 2400 (square pixel), congratulations, wrong...
According to the above introduction, the size of the repainting should be the number of repainting * the area of a single area. Why is this wrong? Let's see what the problem is:


The strange thing is that the number of repainted areas is still 3, but the area is increased a lot. According to the coordinate information given on the figure, it is not difficult to calculate, the size of the total re-painted area is:
20*(70-20 + 20) * 3 = 4200 (square pixel), which is 2400 larger than the estimated 75% (square pixel!
From this point on, you may feel confused. Indeed, the re-drawing area of Flash Player is not calculated as we previously imagined, but we can still find some rules. Take a closer look at the following situations:


If you are careful enough, it is not difficult to see that there will be no more than three areas for each Flash Player re-painting, even if there are more than three display objects on the stage to be re-painted, flash Player will combine two or more sets (determined by location) and redraw them in a large area. At this point, we can name the above two redrawing rulesThree-region ruleAndNearby merge ruleBy summarizing these two rules, we can more easily understand the Flash Player re-painting mechanism and explain some of the re-painting phenomena encountered in daily debugging. For example, some small animals in the QQ Farm are repainted in a single area, while some animals are not repainted separately.
After learning about the re-painting mechanism, we should further understand how to avoid unnecessary re-painting. Most of the methods listed below may be familiar to everyone.
1. When a displayobject with an animation effect is not displayed, it is not only set to false because the re-painting will continue, but you can choose to pause the animation here, alternatively, you can use removechild (displayobject) to directly remove the object from the display list.
2. The display objects that do not change within the visible range will not actually be re-painted. I believe Flash itself has been optimized, that is, my stage. stagewidth and stage. when the stageheight is 200, the coordinates of an object that is changed on the stage are (200,200) and the width and height are all 10. In this case, the Flash Player repainting content does not include this object, the new version of Flash Player Even closes all re-painting when the browser window is minimized. At this time, you will often find that the CPU usage drops sharply, but the application is still running.
3. When setting the displayobject level, make a judgment first:

if (myContainer.getChildIndex(myChild) != 0){    myContainer.setChildIndex(myChild, 0);}

If you are lucky, this judgment can increase the efficiency by more than 200%.
4. When the attribute cacheasbitmap = true is set for your sprite/movieclip, when a small area (or even a hidden object) in the object changes, this will cause the entire sprite/movieclip to be repainted.
5. Make sure that the display content of the activity is suspended in the invisible area or the display list is removed directly. The invisible area mentioned here is not only invisible outside the stage, it also includes display objects that are covered by other objects on the stage.

As mentioned earlier, repainting is a major contributor to flash player performance consumption. Therefore, we need to optimize and reduce the area of the re-painting area and unnecessary re-painting operations, it often brings about a relatively large performance optimization return.

 

From: http://rss.9ria.com /? P = 1793

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.