Loading an External swf or jpg File into a Movie Symbol

Loading an External swf or jpg File into a Movie Symbol

Flash CS4 ActionScript 3.0 Tutorial

 

How to Bring External Files to the Main Stage in Flash

 

 

External files can be imported multiple ways in Flash. You can use a Loader object, UILoader Component or import an external file into a Movie Symbol that is located on the main stage. In this example, we will import an external file into a Movie Symbol.

During the loading process you may wish to use a preloader to let the user know that something is being downloaded. For information on importing images with preloaders, see topics, Loading External File with UILoader and Preloader and Preloader for External swf or Image File.

Tutorial Elements

External swf file with instance name External.swf. For still images you could substitute this file with a jpg file.

 

Step One

Open a new Flash document and name the default layer Content.

Step Two

Add a new layer and name it Actions.

Step Three

Save your file in a Project folder and name the file Main.fla.

Step Four

Open a new Flash document and name it External.fla. Save it in the same Project folder.

Step Five

Add an animation or series of images to the External.fla file and publish the file (Cmd/Return (PC - Ctrl/Enter).

Step Six

Return to the Main.fla file and click the first keyframe of the Content layer.

Step Seven

Using the Rectangle tool, draw a box that matches your stage size. The box fill should match the Content.fla file stage background and have no stroke.

Step Eight

Click the new box and convert it to a Movie Symbol (F8) named Holder.

Step Nine

Select the Holder symbol on the stage and name it holder_mc in the Properties panel

Step Ten

Option double-click (PC - Alt double-click) frame one of the Actions layer.

Step Eleven

Copy/Paste the following code to the ActionScript panel.

var loader01:Loader = new Loader();

loader01.load(new URLRequest("External.swf"));

holder_mc.addChild(loader01);

Step Twelve

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The external file appears on the main stage.

Dissecting the Code

The first line of the code at Step Eleven establishes a new Loader variable called loader01. Line two makes a URLRequest to import the external file. If the external file were inside a folder (named SwfFiles) next to the host file the code in parentheses would read, "SwfFiles/External.swf".

Line three adds loader01 to the holder_mc Movie Symbol.

Positioning the Holder on the Stage

To set the position of the movie clip, add the following code:

holder_mc.x=0;

holder_mc.y=0;

In this case the Holder Symbol's registration point would be shifted to the upper left corner of the stage.

Does the Holder Movie Need a Rectangle?

In this example, we created a holder movie with a white rectangle. You could accomplish the same thing by creating an empty symbol (Edit > Insert Symbol) and dragging the symbol from the Library to the stage. Once it is on the stage, click the small circle and assign it an instance name as we described in Step Nine.

How About the Background of an External File?

Whenever you load an external file, the external file's background becomes transparent. In other words, if it has two objects and a blue background, the two objects import but not the blue background.

The external file aligns to the host file's upper left corner.

 

Contribute Ad