logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture


dailyclick
All times in EST

Full Schedule
g
g Flash and Animation Site

BellaOnline's Flash and Animation Editor

g

ActionScript to Load External SWF


Let's add the ActionScript that will load the external ecard swf into our FlashR intro swf. We already have an Actions layer at the top of the Timeline. We created this Actions layer when we built the "Click on Stamp" button on Frame 80.

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();
myloader.load(myrequest);

function swfLoad(myevent:Event):void
{
stage.addChild(myloader);
var myswf:MovieClip = myevent.target.content;
myswf.x = 0;
myswf.y = 0;
}

myloader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoad);

  1. 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.

  2. Next, we create a variable (named myrequest) and a variable (named myloader) for the URLRequest.

  3. 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.

  4. 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.

  5. Open your HTML file into a text editor.

  6. Look for the AC_FL_RunContent JavaScript. It should be about line 300 or so.

  7. Now, we will add the name of the external swf (ecard.swf) to this script. We will add it to the scr and movie parameters in the JavaScript. In the example, the name of my intro swf is "dCipolloDesigns_Ecard18.swf". Therefore, I will add the "ecard=ecard.swf" to the end of this. Remember that I said we would see the parameter "ecard" again from above. Notice that we have removed the ".swf" extension from the end of the intro swf (dCipolloDesigns_Ecard18). We must do this for the JavaScript.

    dCipolloDesigns_Ecard18?ecard=ecard.swf

    We need to add this to the src and movie parameters for this script.

  8. 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.

    dCipolloDesigns_Ecard18.swf?ecard=ecard.swf

  9. The last place that we need to add this code is for the embed tag and the src parameter. Again we keep the ".swf".

    dCipolloDesigns_Ecard18.swf?ecard=ecard.swf

  10. 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.

← Back

Join us in the Flash forum.




Add ActionScript+to+Load+External+SWF to Twitter Add ActionScript+to+Load+External+SWF to Facebook Add ActionScript+to+Load+External+SWF to MySpace Add ActionScript+to+Load+External+SWF to Del.icio.us Digg ActionScript+to+Load+External+SWF Add ActionScript+to+Load+External+SWF to Yahoo My Web Add ActionScript+to+Load+External+SWF to Google Bookmarks Add ActionScript+to+Load+External+SWF to Stumbleupon Add ActionScript+to+Load+External+SWF to Reddit



 



RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the Flash and Animation Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 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.

g


g features
Animate Lower Third in Motion 5

Drop Zone and Lower Third in Motion 5

Add Static Text To Craft Product Trailer Template

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor