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 = 100;
mainImage_1.y = 25;
addChild (mainImage_1);
mainImage_2 = new MovieClip();
mainImage_2.name = "mainImage_2";
mainImage_2.x = 100;
mainImage_2.y = 25;
addChild (mainImage_2);
lcs.initLoader (null,null,mainImage_1,mainImage_2);
var but1:Button = new Button();
but1.move(100,0)
but1.label = "image 1";
addChild(but1);
var but2:Button = new Button();
but2.move(250,0)
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.01;
mainImage_2.alpha -=0.01;
if(mainImage_1.alpha >= 1)
{
myTimer.stop();
}
}
else
{
mainImage_1.alpha -=0.01;
mainImage_2.alpha +=0.01;
if(mainImage_2.alpha >= 1)
{
myTimer.stop();
}
}
}
}
}
|