ActionScript 2 (AS2) SuperLoader – taterboy
August 13th, 2008 | Filed under: ActionScript 2, Flash, Free Components/Classes, Tutorials

Here is an AS2 version of the SuperLoader. It works just like the AS3 version found in the Custom HTML Templates post.

Quick Use:
1. Add loaderbar.swf and mainLoader.swf to your current project directory.

2. In the html file for your current project, replace the src and movie parameters to mainLoader.

3. Then add [,'flashVars','swfURL=FlashProjectToLoad.swf'] to the load script.

Example for AC_RunActiveContent:

AC_FL_RunContent(
	'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
	'width', '472',
	'height', '280',
	'src', 'mainLoader',
	'quality', 'high',
	'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
	'align', 'middle',
	'play', 'true',
	'loop', 'true',
	'scale', 'showall',
	'wmode', 'window',
	'devicefont', 'false',
	'id', 'mainLoader',
	'bgcolor', '#000000',
	'name', 'mainLoader',
	'menu', 'true',
	'allowFullScreen', 'false',
	'allowScriptAccess','sameDomain',
	'movie', 'mainLoader',
	'salign', '',
	'flashVars','swfURL=imgViewer.swf'
	); //end AC code

Example for HTML Object/Embed:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="472" height="280" id="mainLoader" align="middle">
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="mainLoader.swf?swfURL=imgViewer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="mainLoader.swf?swfURL=imgViewer.swf" quality="high" bgcolor="#ffffff" width="472" height="280" name="mainLoader" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

4. If your frame rate is different then 30, you will need to update the frame rate in the mainLoader.fla file.

5. If you are using this loader inside of your Flash movie, you may also need to comment out the line that sets _root to the loading file [mainMC._lockroot = true;].

Demo:

Source Here

UPDATE: 1.1

1. Added usage information, the class could be used as a simple loader monitor if needed.
2. Moved class path from com.hdi.util.HDLoader to com.hdi.as2.HDLoader.

See just the loader class below.

?View Code ACTIONSCRIPT
/**********************************************************
HDLoader is a simple loader monitor that can attach to your custom loading bar
version 1.1
date: 1-9-10
 
How To Use:
1. Have something that needs loading
 
2. Create a function to handle the loading monitor updates. Should look something like this.
function loaderUpdate(perc:Number){
	// perc is the percent loaded in non decimal form. 0 - 100.
	// you can make a loading bar move or scale like so
	loaderBar._xscale = perc/100;
 
	// you can display text of the loading status.
	loaderText.text = "LOADING: " + perc + "%";
}
 
3. Create a funciton to handle when loading is complete
function loadComplete(){
	// hiding the loader after loading is always a good thing.
	loaderBar._visible = false;
 
	// do what ever you want here, your crap is now loaded.
}
 
4. import HDLoader.
import com.hdi.as2.HDLoader;
 
5. Start the loader, placing the correct target references in the correct argument positions.
arg 1: the MovieClip doing the laoding.
arg 2: the loader update function created in step 2.
arg 3: the loader complete function created in step 3.
 
// we are assuming you have just started loading something (mc.loadMovie("someSWF.swf");
var loaderMon:HDLoader = new HDLoader(mc,loaderUpdate,loadComplete);
 
Author: Todd Williams
website: www.taterboy.com
website: hdinteractive.com
***********************************************************/
 
class com.hdi.as2.HDLoader{
	var targMC:Object;
	var monFunc:Function;
	var finFunc:Function;
	public function HDLoader(targ,mfunc,func){
		init(targ,mfunc,func);
	}
	private function init(targ,mfunc,func){
		var lbytes,tbytes,perc;
		var frameParent:Object = targ._parent;
		var cnt:Number = 3;
		var frameObj:MovieClip = frameParent.createEmptyMovieClip("frameLdr",frameParent.getNextHighestDepth());
		frameObj.onEnterFrame = function(){
			lbytes = targ.getBytesLoaded();
			tbytes = targ.getBytesTotal();
			perc = Math.round((lbytes/tbytes)*100);
			if (lbytes < tbytes) {
				if(mfunc != null){
					mfunc(perc);
				}
			}
			else if(tbytes > 200){
				if(cnt == 0){
					if(func != undefined){
						func();
					}
					delete frameObj.onEnterFrame;
				}
				cnt --;
				if(mfunc != null){
					mfunc(100);
				}
			}
		}
	}
}

Technorati Tags: , , , , ,

Other Related Articles:

|

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment