Let’s learn how to dynamically load a SWF in another SFW. First let’s create a new document. Create a movieClip but don’t draw anything in it. Name it “container”. Drag that movieClip from the library on the stage. Place it where you want the other SWF to be loaded. Select the container and ad an instance name to it. We can ad anything we want, for example let’s name it loader. Now make a button that will load another SWF in the container on the stage. Place the button on the stage and ad the following AS to it. on(release){ _root.loader.loadMovie("loaded.swf"); } The loadMovie() function will load an external SWF in the place that we specify. In this case it will load the file loaded.swf in the movie clip container. Create another flash file and export it as loaded.swf. Place it in the same directory as this SWF. Run t;ll.klo,he application and press the button. You will se that the loaded.swf file will be loaded in our original file. To unload a file use the code: on(release){ _root.loader.unloadMovie("loaded.swf"); } Now that you know how to load an external SWF let’s load a movieClip/button/graphic that is in the library of our main SWF. For this create another movieClip and draw anything you like in it. Name it loaded. Now right click on it in the library and go to Linkage. This window will appear: 
Click on Export for ActionScript to ad the identifier and you should have something exactly like the image above. Drag the button we created previously on the stage and ad the following AS: on(release){ _root.loader.attachMovie("loaded", "load", 0); } Now when we click the 2nd button the movieClip that we create will load in our container. Now I will explain the code. The attachMovie function has 3 parameters. The firs one (loaded) is the linkage identifier of the item we want to load. This item must be in the library and have and identifier, otherwise it will not load. The 2nd parameter (load) is the Instance Name that the movieClip will have on the stage. And the 3rd parameter is the depth on witch it will be loaded. I must mention that 2 items can’t be on the same depth. If you already have an item on that depth, it will be replaced with this one. To make sure that you always load it on an empty depth use the getNextHigestDepth() function. In this case your AS should look like n. In this case your AS should look like this one: on(release){ _root.loader.attachMovie("loaded", "load", this.getNextHighestDepth()); } Here are some nice things about these to functions: - They are very easy to use. You can load your content dynamically so you don’t have to make a separate keyframe for every page of your website. Just load the corresponding SWF. This way the pages can be edited separately and easily without any modifications to the main file.
- You can load not only SWF files and movieClips, but also images like JPG and PNG (with transparency)
|