Load Image File into Flash Movie with URLRequest
This image file can be a GIF, PNG, JPEG or progressive JPEG. By default, the top left corner of the image will be aligned with the 0,0 X and Y coordinates on the Stage. However, this can be changed with ActionScript. Also be default, the image will be placed above, ie on top of, the current contents on the Stage.
- Our first step is to create a variable for a new URLRequest and set the URL property to the location of the image file. In the example below, the image is in the same place as the swf file. If it were not, you would include the path along with the name of the image file in the URL property.
var myrequest: URLRequest = new URLRequest("name_of_image.jpg");
- The second variable we will create is for a new loader object, which acts as a container for the image.
var myloader: Loader = new Loader();
- Now we are ready to use the load method to load our myrequest URLRequest into our myloader loader object.
- Of course, we don't want to do any positioning of the image until it is completely loaded into the main swf. So we will attach an event listener to our loader object which will watch the contentLoaderInfo and tell us the when the load is complete. The event listener will then call a function, which we have yet to write, to finish the placement of the image into the movie.
- The imgPlacement function will add the loader object to the Stage via the addChild method. The image will not be visible unless we do this step to add the object to the display list. We will also use this function to set the X and Y coordinates for the image in a location other than 0,0.
myloader.x = 20;
myloader.y = 20;
Copyright 2018 Adobe Systems Incorporated. All rights reserved. Adobe product screen shot(s) reprinted with permission from Adobe Systems Incorporated. Adobe, Photoshop, Photoshop Album, Photoshop Elements, Illustrator, InDesign, GoLive, Acrobat, Cue, Premiere Pro, Premiere Elements, Bridge, After Effects, InCopy, Dreamweaver, Flash, ActionScript, Fireworks, Contribute, Captivate, Flash Catalyst and Flash Paper is/are either [a] registered trademark[s] or a trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.
Editor's Picks Articles
Top Ten Articles
Content copyright © 2019 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact Diane Cipollo for details.