Loading an SWF from another SWF

Screenshot of action scripting in Flash MX 2004 actions panelAt times, I am called to dabble in Flash. If like me, you only dabble in Flash, then words like ‘action scripting’ probably make you think more about writing a screenplay for Bruce Willis’ next movie than web design.

A recent issue I had to tackle was how to get a series of messages/images onto a website, using Flash, without creating a huge file requiring a pre-loader. I hunted about the net for some time, but could only find advice like ‘no one uses scenes anymore’ and ‘don’t ever use scenes, unless you have to’. Lots of DON’T DO advice, but not much in the way of DO THIS INSTEAD advice. So, I had to ponder the matter on my own, which I did for several days.

Suddenly dawned on me: There must be a way to call one SWF from another or to load a particular SWF after the current SWF has run its timeline. And there is!

Here’s how you do it:

1) Create a new Flash file (filename01.flv, for example). Also create a second Flash file (called filename02.flv, in keeping with the first example.)

2) Add the artwork on a series of layers (or however you normally construct your files).

3) Add a new layer (which I always keep as the top layer, mostly so I know where it is) and re-name it ‘actions’. (Ok, this particular tip was something I picked up in a class taught by Ray Barker at Central St Martins.)


4) On the ‘actions’ layer, insert a key frame in the last frame on the timeline.

5) With that new key frame selected, open the Actions palette. To do that, hit the F9 key on a PC. Or you can go Window > Development Panels > Actions.

6) Add the following code to the Actions palette:

loadMovieNum("/assets/flash/filename02.swf", 0);

wherein “/assets/flash/filename02.swf” is the name and directory where the subsequent SWF file that you want to load. The ‘0‘ is the frame number, indicating that the movie will load from the start.

The coding should look like this:

Screenshot of action scripting in Flash MX 2004 actions panel

7) Publish the FLV as an SWF.

8) Repeat Steps 2 – 6, using filename02.flv. Note that on step six, you will need to change the code to:

loadMovieNum(“/assets/flash/filename01.swf”, 0);

The slight change in the code will ensure that the second SWF links loads the first file, creating an ongoing loop.

It’s possible to use this same process with any number of SWF files, not just two as I have described above.

This work was done using Flash MX Pro 2004.

8 thoughts on “Loading an SWF from another SWF”

  1. Thanks a lot. I dabble in flash. I asked this question from so called very experienced professionals and they did not have any idea about it.

    I know there should be a way, and here you are. Thanks a lot for saving me a lot of time

  2. Hi Balraj,

    Thanks for the kind words. I am glad that I was able to help you out … no point in everyone having to learn everything on their own.

  3. Hi. What i wanna do is that on pressing a button a new swf file should open. it does but just for a brief moment the main movie also shows up.. please suggest something.
    the code is:
    loadMovie (“movie.swf”, 1);

  4. Hi Namrata,

    Thanks for your question. As it turns out, I have more or less stopped using Flash, turning instead to javascript to to achieve many similar effects. As such, I haven’t really coded in Flash since I posted this article.

    I wish I had a better answer for you, but alas, I don’t. Sorry not to be able to help out.

  5. hi, i’m eka from Bali-Indonesia
    i’ve tried to load swf to another swf using loader and blank movieclip, both worked..
    to be known that i used attachSound to load sound from library and i used 2 sound. but when i load it, the 2nd sound didn’t loaded. i’ve tried to find another script even used a complete work from internet..
    can you help, please?

  6. Hi there. Thanks for visiting and for the note. I’ve not worked with Flash since shortly after I wrote this post. I’m afraid I don’t use it any more, so I don’t have any ideas or tips for you. I wish I had a better answer.

Comments are closed.