Loading _root
Loading into levels
Loading into movieclips
Loading XML files
Using afterLoad options
Using Streaming options
Using Position options
Using Visuals options
Creating a custom preloader
Adding the uniLoader dynamically through ActionScript
Unloading/interrupting preloader
Controlling the preloaded SWF
In File to load field type _root, set all other options. The uniLoader must be on the first frame of the SWF.

It is recommended to put only uniLoader on frame 1, as Flash player ignores the preloader's processes until everything from frame 1 and frame 0 is loaded.
In the Bandwidth Profiler you can see that it takes around 12kb to load before the preloader shows up. This is normal, as this is the size of the preloader. The size to load before the preloader shows up may vary if you are using other components or if you use "Export in first frame" option in the movieclip linkage properties in the Library panel.
Note:
Preloading _root is working only if you are preloading the SWF which is your main movie. It is not working in case you want to preload SWF in another movie. To load SWF into another SWF please go to Loading into movieclips tutorial.
nocache option is not active when preloading _root. top
In the Load location input field enter the level into which you would like to load the content (e.g: _level2).
In the File to load input field, enter the URL of the content.
To load SWFs or JPEGs into movieclips you can simply drag and drop the uniLoader component onto the stage and fill in the Load Location and File to load.

When loading into movieclips the preloader aligns to the x and y of the target movieclip and takes the width and height of the movieclip for size to align. top
To load XML files you don't need to create XML object, uniLoader will do it for you. In the Load location field type the name of the xml object you want to create.
In the File to Load field type the url of the xml file.
Select from Content type XML button.

The XML object will be created in the movieclip where the uniLoader instance is.
Note: The preloader bar will not appear when testing locally. To see the preloader you need to upload your files on a server.top
Using afterLoad options
To set the action that will be performed after loading is finished you can choose from the group of radio buttons in the Main tab

The actions play, stop, gotoAndStop and gotoAndPlay are for controlling the loaded SWF file. In the input fields for gotoAndPlay and gotoAndStop you can type the number of the frame or the frame's label. Please note that all the actions except the onLoaded handler are applied to the target movie, not to the timeline on which the uniLoader instance appears.
To set more complicated actions you should use the onLoaded handler option. You should type in the input field of the onLoaded handler option the name of the function you wish to call after the finish of the loading process.top
Using Streaming options
You can use the streaming options for loading part of an SWF file and play it before it is loaded fully.

You can use streaming options only while loading SWF files or preloading _root. If you select other option than Load fully, the file will be loaded to the point you've selected and than will perform the action selected by afterLoad options. After this point the SWF file or _root will continue to load in background and the preloader bar will not be visible as the uniLoader is not active than.top

If loading into level or preloading _root the alignment is calculated taking the width and height of the stage. If the uniLoader is placed in another movieclip, the alignment takes the x/y positions and width/height of this movieclip.
To turn on custom positions you should select from the Horizontal/Vertical align drop-down menu custom option. If the uniLoader is in a movieclip it will take movieclip's x and y and set custom positions to them.top
You can set different styles and colors of uniLoader's preloader bar. To do so go to Visuals tab of the uniLoader user interface.
From here you can select colors of the bar, background and text which will appear in your movie. Also you can select a style for your preloader bar with different effects like bounce duration and percentage step.

If you select "custom" effect from the list, the input field on the left will become editable and you will be able to use your own function for preloading, so you will be able to create your own preloader bars. top
The following sample code can be used to create a custom preloader function:
AS1 & AS2:
customLoaderHandler = function (file) {
trace(Math.round(file._getFileBL/1024)+"kb loaded");
if (file._getFilePrcnt==100) {
trace("File was loaded successfully!");
}
};
AS3:
var myLoader:MovieClip = new uniLoader();
addChild(myLoader);
myLoader.loaderStyle = "custom";
myLoader.customPreloader = "handler";
function handler() {
trace(Math.round(myLoader.getFileBL/1024)+"kb loaded");
}
myLoader.loadFile("file.swf", mc, "swf");
This code will display the loading progress in kilobytes in the output window. top
The following sample code can be used to attach the uniLoader with ActioScript:
AS1 & AS2:
_root.attachMovie("uniLoader", "myLoader", 2);
myLoader.loadFile("image.jpg", "mc", "jpg");
AS3:
var myLoader = new uniLoader();
addChild(myLoader);
myLoader.loadFile("myimage.jpg", mc, "jpg");
The properties of the uniLoader will be set to default values. You can see them in the Component Inspector panel. You can set the properties using the properties and methods of the uniLoader. For more info, please check the ActionScript Reference page. top
With the unloadFile() function you can interrupt the running of the preload process. If you want to restart the preload or to start a new preloader using the same instance of uniLoader, you must call unloadFile() first.
The unloadFile() function can also be used to clear the content of a movieclip without removing its instance from the stage.
This example shows a sample function on a button:
AS3:
function loadAction(ev:Event) {
myLoader.unloadFile();
myLoader.loadFile("file.swf", myMovieClip, "swf");
}
loadButton.addEventListener(MouseEvent.CLICK, loadAction);
When using the uniLoader to preload SWFs, they will be inserted at the child0 of the target movieclip removing all other children from it. To control the timeline of your preloaded SWF you must refer to the child0 of the movieclip.
This example will start to play the movie that was preloaded:
var myMovie = target_mc.getChildAt(0); myMovie.content.play();