Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

 
« Return

ActionScript 2

loadMovie to import an SWF with sound

When using loadMovie to import one or more SWF files that contain sound, if this sound was set up in the loaded movie with ActionScript, you need to have the "this" keyword when declaring the sound object. See below and in the attached FLA files for the full code, but here is the line of code:
var mySound:Sound = new Sound(this); // "this" keyword is required

The loaded SWF file needed a mask, because until I added the mask, the off-stage content was appearing on the stage of the loader movie:

Download the FLA file of the loader/container file (contains gray background).

Download the FLA file of the loaded/imported file (contains music, the walking man, and text which is moving horizontally).

ActionScript for the loader movie (the one with the gray background):

// A note to those who want to use this:

// If you want to use this, you'll need to update the file path to
// match your configuration.  My html is one level higher than the 
// SWF, hence the "movies/" in the path of the loadMovie command:

loadMovie("movies/as2_sound_this_in_target_path_loaded.swf", placeholder_mc);

// I assume you'll want to change it to this:
// loadMovie("as2_sound_this_in_target_path_loaded.swf", placeholder_mc);
// so that you can run everything from the same folder.

ActionScript for the loaded movie (the one with music and the walking man):

/* "this" keyword is required, since this SWF file gets loaded by another SWF
and Flash needs to know to obtain the sound file from THIS movie's library: */

var mySound:Sound = new Sound(this); 
 
 
/* In the library, I gave the .wav file a 'Linkage Name' of "myGuitar", so that I could reference it in this ActionScript */

mySound.attachSound("myGuitar"); 


/* The first parm of "12.5" starts playing the clip at 12.5 seconds into it, since the clip starts with silence. The second parm says to loop it just once. Both parms are optional: */
																 
mySound.start(12.5,1); 
                       

/* Move the text on horizontally from right to left.
Once the man has no text below him, make him fall: */
											 
onEnterFrame = function() {

if (marqueeText_mc._x < -3000)
{ marqueeText_mc._x = 330; }
else
{ marqueeText_mc._x -= 3; }	

if (marqueeText_mc._x < -2900)
{ walker_mc._y += 7; }
else
{ walker_mc._y = 116; }	
	
} // end of onEnterFrame function


 
« Return


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