Make sure to change the name of the image file, one to load. Once you do this, press Ctrl + Enter
In this line, I announce a new object, its so-called imageLoader loader. First-class loaders allow you to load image-based content, such as images, Papua New Guinea, and GIF, and provide many convenient methods so that you can easily achieve this. You will see some people in our code very quickly.
// Set properties on my Loader object
ImageLoader = new Loader ();
ImageLoader. load (new URLRequest (url ));
ImageLoader. contentLoaderInfo. addEventListener (ProgressEvent. PROGRESS, imageLoading );
ImageLoader. contentLoaderInfo. addEventListener (Event. COMPLETE, imageLoaded );
}
In the next line, I start our loadImage method. This method requires the value of a URL to be encoded as a string, and its return type is invalid. In other words, it does not return a value.
Function loadImage (url: http://www.111cn.net/flash_a/112/String): void {
// Set properties on my Loader object
ImageLoader = new Loader ();
ImageLoader. load (new URLRequest (url ));
ImageLoader. contentLoaderInfo. addEventListener (ProgressEvent. PROGRESS, imageLoading );
ImageLoader. contentLoaderInfo. addEventListener (Event. COMPLETE, imageLoaded );
}
The next two lines are interesting! I have created two event listeners that require proper event handler when launching. These two events are ProgressEvent. PROGRESS and Event. COMPLETE.
Because your image is downloaded, you can download more images each time. This allows you to have an accurate snapshot of how much your data has been downloaded and how much is left. Once all your data has been downloaded, your complete event will let you know this.
When an event is initiated, an event handler is notified. An event handler is a fantasy name method. The requirement for this event handler is improved by the imageLoading event, and the requirement for the event handler to get the complete event is imageLoaded. The bundled activity and event handler are taken care of by the addEventListener.
Note that I did not require the addEventListener method to register the relationship between your activities and event handlers in your imageLoader object itself. Instead, I add a property named contentLoaderInfo. The reason is that contentLoaderInfo returns the LoaderInfo object, providing you with everything you need to register events. This is your default loader object, imageLoader. Do not do this.
In this way, we are working with our loadImage method. We can start with this application in the most important code line-a practical start.
--------------------------------------------------------------------------------
LoadImage ("pixelHouses.jpg ");
In this line, I call it the loadImage method and use the file that it looks like to our image. Since the image is in the same directory as my FLA and SWF files, I just reference the file, but it is actually a relative path image. If your image is stored in an image folder, your argument loadImage will be:
LoadImage ("image/pixelHouses.jpg ");
In addition to the details, this call sets out that you need to attach your image to everything in the motion. This requires loadImage to create two events for your loader object and listener to handle the progress and completion events.
--------------------------------------------------------------------------------
Function imageLoaded (event): Invalid (
// Load the image
ImageArea. addChild (imageLoader );
)
This method is the complete event handled by our event you once. Please note that it arguments for object type events. You don't have to worry about passing event objects. However, in China, this value is the complete event you live in.
In any case, the important line of code is to participate in where I call the addChild method on our video clip, imageArea. Please note that the addChild method passed to us is our loader object imageLoader. This is the source code of this line. It is responsible for displaying the video clips loaded into your imageArea and processing the complete events in it, we must ensure that our images are completely downloaded only after they are displayed.
--------------------------------------------------------------------------------
Function imageLoading (English: ProgressEvent): Invalid (
// Use it to get the current download progress
// Tip: preloader for values that you can work :)
)
Earlier on, we covered the imageLoaded method, which is a complete event for Event Processing. What you see now is the event processing program for our progressive activities. This method is required by imageLoading for every Progress event. If you want to create a preloader, you will specify it here. Since this is a big question, I will save the discussion later.
All actions surrounding it
It indicates that it is not fast! This is a massive workload of about 10 lines of code. In general, as you can see, this is very simple to load external images to your Flash application. The main thing is to create your own loader object and fill its load method with the path image of the URLRequest to load.
Your loader object is only responsible for downloading images to the memory. You can register an event in its contentLoaderInfo property to find out how many images have been loaded, or when the image has been downloaded. Once your image has been downloaded, you just need to call the addChild method of your video clip and it is passed to your loader object.