Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 3

Loading in external content

You can load external images, .swfs, and text into your Flash movie at run time. One advantage of this technique is that you don't have to edit the .FLA file as often. This example loads in three .JPGs from the 'movies/external content' subfolder.

Download the FLA file

var myXPosition:int      = 150;
var myYPosition:int      = 20;
var myLoader:Loader      = new Loader();
var myPhotoNum:int       = 1;
var myNumberOfPhotos:int = 3;
// retrieve (load) the first image from the folder
var myCurrentFilePath:URLRequest =
  new URLRequest("http://www.krolldesign.net/tech/flash/movies/external_content/sample_photo" + myPhotoNum + ".jpg");
myLoader.load(myCurrentFilePath);
myLoader.x = myXPosition;
myLoader.y = myYPosition;
addChild(myLoader);
// If the user clicks the button, display the next photo:
myButton_btn.addEventListener(MouseEvent.CLICK, nextPhoto);
function nextPhoto(myEvent:MouseEvent)
{
	removeChild(myLoader); // remove the photo that's already on the stage
  if (myPhotoNum == myNumberOfPhotos)
	{ myPhotoNum = 1; }
  else
	{ myPhotoNum++;   }
  var myCurrentFilePath:URLRequest =
    new URLRequest("http://www.krolldesign.net/tech/flash/movies/external_content/sample_photo" + myPhotoNum + ".jpg");
  myLoader.load(myCurrentFilePath); // retrieve (load) the image from the folder
  myLoader.x = myXPosition;
  myLoader.y = myYPosition;
  addChild(myLoader); // add the loaded image to the display list (the stage)	
}


 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM