What do I need to load an external file using the MovieClipLoader Class?
Two things only:
- a MovieClipLoader Object
- the loadClip() method
We'll always use the same image:
-
var url:String;
-
url = "http://www.nunomira.com/tutorials/files_mcl/image1.jpg";
Here's the most basic example you can get - loading an image on a level:
-
// create the MovieClipLoader Object
-
var mcl:MovieClipLoader = new MovieClipLoader();
-
// load the external file on _level1:
-
mcl.loadClip(url , 1);
A similar example loading the file inside an empty movie clip:
-
// create an empty movie clip to load the image into
-
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
-
// create the MovieClipLoader Object
-
var mcl:MovieClipLoader = new MovieClipLoader();
-
// load the external file:
-
mcl.loadClip(url, my_mc);
If you've used loadMovie() before, here's the equivalent:
-
// create an empty movie clip
-
this.createEmptyMovieClip("my_mc", this.getNextHighestDepth());
-
// load the external file:
-
my_mc.loadMovie(url);
And here's the equivalent to the first piece of code, using loadMovieNum():
-
// load the external file on _level1
-
loadMovieNum(url, 1);
You may have noticed that using MovieClipLoader.loadClip() requires a greater amount of code compared to using MovieClip.loadMovie() or loadMovieNum(). That's true. In this pieces of code, besides being considered "a best practice", there is no benefit. The true benefit comes when you use this Class to preload external files.
And this is it. Extremely easy!
You're already using the MovieClipLoader Class!