LoaderClassAlternate

Package:
Class:
Inheritance:
biz.flashscript.utils
public class LoaderClassAlternate
Sprite
The LoaderClassAlternate class allows loading movies and bitmaps, all objects usually loaded with the Loader class. The difference to other loader classes is that two Loader objects are created, which allow overlapping animations. Use the constructor new LoaderClassAlternate() to create a new LoaderClassAlternate object and add parameters as desired.

See also

   biz.flashscript.utils.LoaderClass

   biz.flashscript.utils.LoaderClassStatic

Public Properties
Property Defined By
All inherited properties of the Sprite class. N/A
Public Methods
Method Defined By
LoaderClassAlternate()
Creates a new instance of the LoaderClassAlternate class.
LoaderClassAlternate
initLoader(myURL:String, loadFinished:Function, myTarget1:Object, myTarget2:Object)
Function to initialize the loader objects and place them in MovieClips for example.
LoaderClassAlternate
progressLoader(myURL:String, loadFinished:Function, myTarget:Object)
Function to target one of the Loader objects.
LoaderClassAlternate
Events
Event Defined By
All inherited events for the Sprite class. N/A
Constructor Detail
LoaderClassAlternate ()  Constructor
public function LoaderClassAlternate()
Intializes a new LoaderClassAlternate instance with the specified parameters.
Method Detail
initLoader ():void  method
public function initLoader(myURL:String, loadFinished:Function, myTarget1:Object, myTarget2:Object)

Parameters

  • myURL:String ____ The url for the object to load.
  • loadFinished:Function ____ The name of the function for the completed event.
  • myTarget1:Object ____ One of the Loader objects ("urlLoader1").
  • myTarget2:Object ____ The second of the Loader objects ("urlLoader2").
progressLoader ():void  method
public function initLoader(myURL:String, loadFinished:Function, myTarget:Object)

Parameters

  • myURL:String ____ The url for the object to load.
  • loadFinished:Function ____ The name of the function for the completed event.
  • myTarget:Object ____ The Loader object to do something with.
Examples
Create a new fla file and name it LoaderClassAlternExample.fla. Place the fla in the same folder as the biz folder. Put a Button component on the stage and delete it. Have two images of your choice ready. Then create an Actionscript file, name it LoaderClassAlternExample.as and place this script.

package 
{
	import flash.display.Sprite;
	import flash.events.*;
	import biz.flashscript.utils.LoaderClassAlternate;
	import flash.display.MovieClip;
	import fl.controls.Button;
	import flash.utils.Timer;

	public class LoaderClassAlternExample extends Sprite
	{
		private static var lcs:LoaderClassAlternate=new LoaderClassAlternate();
		private var mainImage_1:MovieClip;
		private var mainImage_2:MovieClip;
		private static var loaderName:String;
		private var myTimer:Timer;
		public function LoaderClassAlternExample ():void
		{
			mainImage_1 = new MovieClip();
			mainImage_1.name = "mainImage_1";
			mainImage_1.x = 150;
			mainImage_1.y = 0;
			addChild (mainImage_1);
			mainImage_2 = new MovieClip();
			mainImage_2.name = "mainImage_2";
			mainImage_2.x = 150;
			mainImage_2.y = 0;
			addChild (mainImage_2);
			lcs.initLoader (null,null,mainImage_1,mainImage_2);
			var but1:Button = new Button();
			but1.move(10,100)
			but1.label = "image 1";
			addChild(but1);
			var but2:Button = new Button();
			but2.move(10,200)
			but2.label = "image 2";
			addChild(but2);
			but1.addEventListener(MouseEvent.CLICK, cHandler);
			but2.addEventListener(MouseEvent.CLICK, cHandler);
		}
		private function cHandler(event:Event):void
		{
			var myLabel:String = event.currentTarget.label as String;
			if(myLabel == "image 1")
			{
				playSlide ("images/A6.jpg", myLabel);
			}
			if(myLabel == "image 2")
			{
				playSlide ("images/A7.jpg", myLabel);
			}
		}
		private function playSlide (myUrl:String, myLabel:String):void
		{
			if(myLabel == "image 1")
			{
				lcs.progressLoader (myUrl,imageDisplay,mainImage_1);
			}
			else if(myLabel == "image 2")
			{
				lcs.progressLoader (myUrl,imageDisplay,mainImage_2);
			}
		}
		private function imageDisplay (ev:Event):void
		{
			loaderName = ev.currentTarget.content.parent.parent.name as String
			if(loaderName == "mainImage_1")
			{
				mainImage_1.alpha = 0;
				mainImage_2.alpha = 1;
			}
			else
			{
				mainImage_1.alpha = 1;
				mainImage_2.alpha = 0;
			}
			myTimer = new Timer(5);
			myTimer.addEventListener(TimerEvent.TIMER, alphaHandler);
			myTimer.start();
		}
		private function alphaHandler(event:Event):void
		{
			if(loaderName == "mainImage_1")
			{
				mainImage_1.alpha +=0.05;
				mainImage_2.alpha -=0.05;
				if(mainImage_1.alpha >= 1)
				{
					myTimer.stop();
				}
			}
			else
			{
				mainImage_1.alpha -=0.05;
				mainImage_2.alpha +=0.05;
				if(mainImage_2.alpha >= 1)
				{
					myTimer.stop();
				}
			}
		}
	}
}