Design transcript of external image loading

Source: Internet
Author: User
Tags addchild

Private function LoadImage (URL: String, movie: *): void <br/>{< br/> var Loader: loader = new loader (); <br/> If (movie is flash. display. movieclip | movie is flash. display. sprite) <br/>{< br/> movie. addchild (loader); <br/>}< br/> else <br/>{< br/> throw new error ("incorrect type "); <br/>}< br/> loader. load (New URLRequest (URL); <br/> loader. contentloaderinfo. addeventlistener (event. complete, finish); <br/> loader. contentloaderinfo. addeventlistener (progressevent. progress, onprogress); <br/> loader. contentloaderinfo. addeventlistener (ioerrorevent. io_error, ioerror); <br/>}< br/> private function loadimage2 (URL: String, movie :*): void <br/>{</P> <p> If (movie is flash. display. movieclip | movie is flash. display. sprite) <br/>{< br/> movie. addchild (loader2); <br/>}< br/> else <br/>{< br/> throw new error ("incorrect type "); <br/>}< br/> loader2.load (New URLRequest (URL); <br/> loader2.contentloaderinfo. addeventlistener (event. complete, finish); <br/> loader2.contentloaderinfo. addeventlistener (progressevent. progress, onprogress); <br/> loader2.contentloaderinfo. addeventlistener (ioerrorevent. io_error, ioerror); <br/>}< br/> private function finish (Event: Event): void <br/>{< br/> trace ("www "); <br/>}< br/> private function onprogress (Event: progressevent): void <br/>{< br/> // target. percent. TEXT = math. floor (event. bytesloaded/event. bytestotal * 100 ). tostring (); <br/>}< br/> private function ioerror (Event: ioerrorevent): void <br/>{< br/> trace ("error occurred "); <br/>}

Private var loader2: loader = new loader ();

 

Sometimes we want to load images externally and display them in our designed containers. Sometimes, you can combine XML techniques to design images.

When we need to perform external loading, we want to get the image source and load it into the container. At this time, we can design it through the code above.

However, in Flash + XML design applications, it is common to paging the XML content up and down.

If LoadImage () is used in the first method, a new container is created every time the image is switched, which consumes memory.

If loadimage2 () is used, only one image will be loaded each time the image is switched. However, when multiple images are switched, the image will function, the first method will make the difference.

 

//This is a specific design with paths and containers.In this way, the image can be smoothly loaded into the specified container, but the problem is that if LoadImage is used for loading in the first way, a new memory space will be created each time it is loaded, images are still stored in the memory. Not cleared, that is, a new container is created every time. Memory consumption

 

 

The following are some of the latest source file rewrites:

The image is loaded externally. The same is true for text stored in XML.

 

 

Problems:

During the design period, I was not lucky to tell myself to use the unload method. It was not suitable to close the content of the previous image. Every time I wanted to search for the next node, there were some bugs. The original images are still stored in the memory and are not released. This is a problem with the image above.

 

 

 

 

 

 

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.