Jump to content
xisto Community
lairz

Loading Movies Technique In Flash

Recommended Posts

What is loading movies technique? Well for example if you are buildin a 7 section website fully flash animated, the whole site is flash, one option is to make the 7 sections in the same movie, but the result will be a huge movie, that will take a lot of time to load, and probably the user wont stay that long to wait. The other option is to make one main movie and 7 other movies one for every section and then load does movies dinamically into the main movie, in that case the user its gonna load the main movie and then just load the section hes gonna navigate.

Now lets get down to business .

 

Asumming you have your main movie and you have your menu buttons. you have to attach this script in to the button

 

on(press){

unloadMovieNum(10);

}

on(release){

loadMovieNum("sectionname.swf",10);

} _linenums:0'>on(press){ unloadMovieNum(10);}on(release){ loadMovieNum("sectionname.swf",10);}

Now let me explain you the code.

 

The on statement its pretty simple it means the state of the button,on(press) means that when you press the button in the movie, the code between the cuirls its gonna be executed, the same with the on(release) the code will be executed when you realesed the button.

 

First lets talk about the "loadMovieNum" code, this code load the movie ("whatever.swf") into the main movie.

we need to tell the code 2 things first the name of the movie we are about to load :

loadMovieNum("whatever.swf",);

secondly we need to tell the code in wich level we want the movie to be loaded:

loadMovieNum("whatever.swf",10); // This means that the movie called whatever.swf will be loaded in level 10.

 

Now let me explain to you the level thing:

the main movie is level 0 by default, you can think of level as leyers, something in level 10 will be on top of level 0, for a example if your movie is 300x300 size (level0), and then you load a movie with a 300X300 filled square on level 5 you wont see a thing cause level 5 is on top on level 0 and since you have a square filling the hole movie it wont let us see anything that is the lower levels. (you can use whatever level you want i choose 10 for no reason) also you can load things on different levels an the same time, for example i can load a logo animation on level 50 and then load other things in the lower level in that case the logo will be always on top, no matter what.

 

Now let me explain the unloadMovieNum code:

 

its pretty simple it just unload whatever movie is loaded into the level that we specify

for this code we only need to tell one thing and that is the level where the movie we want to unload is.

 

for example if i want to unload the movie in level 10 i will say

 

unloadMovieNum(10); and thats it.

 

 

Now let take a look again at the code

 

on(press){

unloadMovieNum(10);

}

on(release){

loadMovieNum("sectionname.swf",10);

} _linenums:0'>on(press){ unloadMovieNum(10);}on(release){ loadMovieNum("sectionname.swf",10);}


This tell me that when i hit the button first it will unload everything that is on level 10 and then load the movie called sectioname.swf into level 10. Remeber that you can change the movie name and the level number.

 

Why do we need to unload everything in level 10.

 

For example if we have the section 1 loaded in level 10 and the we load section 2 into the same level without unloading, both sections will be seen at the same time, causing a huge mess, so first you have to unload things.

 

i hope you like the tutorial, this load thing is one of the huge things in order to build full flash sites.

Edited by electriic ink (see edit history)

Share this post


Link to post
Share on other sites

well as you said, it's very importanat to handle the sections or media with loaders, and if it's not only to reduce the waiting time for a user, it also brings a number of features very useful to mantain the user informated with all the load status, such as loadprogress, errors, and also, you can interact with the loaded movie before it is displayed, maybe it could be useful to size the movie, add an effect, filter, etc... before it is displayed.

i have a code like this to do all that, i will explain the code below:

var target:MovieClip = this.createEmptyMovieClip("target", this.getNextHighestDepth());var clipLoader:MovieClipLoader = new MovieClipLoader();var listener:Object = new Object();listener.onLoadStart = function(target:MovieClip){	//this fires up when the download begin	trace("the load has begun!");}listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number){	//do whatever what you want with the progress of the loading information	trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " + bytesTotal);}listener.onLoadInit = function(target:MovieClip){	//here you can interact with the loaded clip before it is pisplayed	target._x = 100;}listener.onLoadError = function(target:MovieClip, errorCode:String, httpStatus:Number) {	//man, sorry but your connection goes down, look for other host company	trace(target+":"+errorCode+","+httpStatus);}listener.onLoadComplete = function(target:MovieClip, httpStatus:Number){	//touchdown!, at last, now you can fire the animation	target.start();}clipLoader.addListener(listener);clipLoader.loadClip("here goes your path to your file", target);


well i hope it doesn't look ugly or huge, but it's quite simple.

var target:MovieClip = this.createEmptyMovieClip("target", this.getNextHighestDepth());var clipLoader:MovieClipLoader = new MovieClipLoader();var listener:Object = new Object();

defines the needed objects:
-target: here is the movieclip where you are going to display your external movie.
-clipLoader: is a nice object that enables to load data in a useful way.
-listener: is the object that listens activity of your clipLoader, and keeps you in touch.

listener.onLoadStart = function(target:MovieClip)

this function tells you your download has begun, just wait!

listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number)

this is important, here you will mantain your user with her eyes on the download progress, there are so much ways to display the progress, the prebuilt progress bar of flash, text labels, messages, use whatever what you want, stay fresh.

listener.onLoadInit = function(target:MovieClip)
your download is done, what i do with it?, here you set propierties, resize, move, add filters, change blend mode, make a transition, or whatever you want

listener.onLoadError = function(target:MovieClip, errorCode:String, httpStatus:Number) 

and what if the information never arrives?, maybe there is an error and here is ower good friend onLoadError, and when it ocurs here you can tell to the fella waiting one hour ago.

listener.onLoadComplete = function(target:MovieClip, httpStatus:Number)

ready, you are done!

clipLoader.addListener(listener);
ok you have defined all the events for your listener, so send him to do its work

clipLoader.loadClip("here goes your path to your file", target);
finally load the clip, it's quite simple, put your file path into the quotes

i hope this can be useful!

Share this post


Link to post
Share on other sites

Yeah dude thanks for completing the tutorial that was gonna be my next par of the tutorial lol, cause i did the first one oriented to user whos really beggining to learn flash and actionscript.Thanks bye dude

Share this post


Link to post
Share on other sites

Formerly, I used to use a simple mathematical trick to get the loading done with the progress, but this appears to be a whole heck of alot simpler. :angry:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.