Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

loadMovie for importing external SWF files at run time

Download the FLA file


You can use the loadMovie method to run other flash movies (other SWF files) within the currently running "container" SWF file. The first parameter of loadMovie is the file path of the SWF file that you want to load. Depending on your version of the Flash player, you can also load various kinds of image files such as JPG instead of SWF's. Note the comments in the Action Script below regarding the path of the SWF files.

//--------------------------------------------
// When button1 is clicked, load Flash file swf1.swf into the place
// currently occupied by movie clip placeholder_mc.  Note that the path of
// movies/swf/swf1.swf is the path of swf1.swf relative to the html of this web page.
// It is NOT the path of the swf1.swf relative to the main swf of loadmovie_example1.swf.
// loadmovie_example1.swf and swf1.swf are in the same folder, but since I'm running the html
// of this web page from two levels higher in the published web site folder structure, I had to
// modify the path in these loadMovie commands accordingly. So, if you downloaded this .FLA file,
// and you want all html and swf's to run from the same folder, you'll need to change 
// this:
//   loadMovie("movies/swf/swf1.swf", placeholder_mc);
// to this:
//   loadMovie("swf1.swf", placeholder_mc);
// and change the other loadMovie commands similarly.

   button1_btn.onRelease = function()
   {
	   loadMovie("movies/swf/swf1.swf", placeholder_mc);
   }


//--------------------------------------------
// When button2 is clicked, load Flash file swf2.swf into the place
// currently occupied by movie clip placeholder_mc.  Note that in this example,
// placeholder_mc is in quotes.  Putting the second parameter in quotes is optional,
// but putting the first parameter in quotes is required, even if the swf is in the
// same folder and has no file path information in front of it:

   button2_btn.onRelease = function()
   {
	   loadMovie("movies/swf/swf2.swf", "placeholder_mc");
   }


//--------------------------------------------
// When button3 is clicked, load Flash file swf3.swf into the place
// currently occupied by movie clip placeholder_mc.  Here's an alternative syntax, putting
// the target movie clip first, instead of as a parameter within the loadMovie function call: 

   button3_btn.onRelease = function()
   {
	   placeholder_mc.loadMovie("movies/swf/swf3.swf");
   }


 
« Return


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