ActionScript to Load External SWF
1. Right-click on Frame 136 and Insert a Keyframe. This will tell Flash to read our ActionScript on this frame. Open the Actions panel (Window – Actions) and copy/paste the following code.
var ecard:String = LoaderInfo(this.root.loaderInfo).parameters.ecard;
var myrequest:URLRequest = new URLRequest(ecard);
var myloader:Loader = new Loader();
var myswf:MovieClip = myevent.target.content;
myswf.x = 0;
myswf.y = 0;
- The first line of code creates a string variable to hold the name of the external swf. Notice that we have given the name of "ecard" to the parameter. We will be using this again later.
- Next, we create a variable (named myrequest) and a variable (named myloader) for the URLRequest.
- Then we write the function (swfLoad) that will load our external swf. This function uses the addChild to add the external swf to the display list for our intro swf and sets the X and Y positions to 0.0.
- Finally, we use an EventListenser to tell us when the external swf has been completely loaded. When this is so, we call the swfLoad function.
Remember that we published our intro fla to tell Flash to generate the swf and HTML files for this project? Now, we will add a little code to the HTML file. This will tell Flash the name of the external file we wish to load into the intro swf. In the example, I decided to call the external swf "ecard.swf" and the name of my intro swf is "dCipolloDesigns_Ecard18.swf". You may wish to use different names. If so, make the appropriate changes to the following HTML code.
- Open your HTML file into a text editor.
We need to add this to the src and movie parameters for this script.
- Next we will work on the movie param and the object tag. For the movie parameter, we will add the same code. Notice that this time we do not remove the ".swf" at the end of the name for our intro swf.
- The last place that we need to add this code is for the embed tag and the src parameter. Again we keep the ".swf".
- The last thing we need to do is add a stop(); code on Frame 150. Right-click on Frame 150 and Insert a Keyframe. Open the Actions panel and type "stop();". Now you can test your movie.
Note. If you test your project within the Flash work environment, you will get an error. So we need to test our finished project by using the HTML file.
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 © 2018 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.