Wednesday, December 16, 2009

Slide show with Effects..





[Event(name="beforeeffect", type="event.SlideshowEvent")]
[Event(name="aftereffect", type="event.SlideshowEvent")]




import mx.events.IndexChangedEvent;
import mx.controls.Alert;
import flash.utils.Timer;
import mx.collections.ArrayCollection;
import event.SlideshowEvent;
import mx.effects.easing.*;
public var count :int=0;



[Bindable] public var myobj:Object = new Object();
private function loadData():void
{

}

[Bindable] public var timer:Timer;
[Bindable] public var _automate:Boolean=false;
public var _dataprovider:ArrayCollection = new ArrayCollection();

// Specified as public since the users can perform any sort of operations as they wish before during the loading of the Component..
public function loaddata():void
{

}

public function set datainput(value:ArrayCollection):void
{
this._dataprovider= value;
}
public function dataprovider():ArrayCollection
{
return _dataprovider;
}

/**
* Automatic is Called When we want the slideShow to be Done Automatically.
* */
private function Automatic():void
{
timer= new Timer(1000,_dataprovider.length);
timer.start();
timer.addEventListener(TimerEvent.TIMER,timerhandler);
}


/**
* Timer Handler is for Triggering all the Elements in the Array.
*
**/
private function timerhandler(evt:TimerEvent):void
{
myobj= _dataprovider.getItemAt(count);
var extension:String = myobj.path;
var filetype:int = extension.lastIndexOf(".");
var extens:String=extension.substr(filetype,extension.length);
if(extens == ".flv")
{
myloader.visible=false;
myloader.includeInLayout=false;
myvideoloader.includeInLayout=true;
myvideoloader.visible=true;
myvideoloader.source = myobj.path;

//Dynamic Setting of Heigh and width of the Image from the Array collection....
//myvideoloader.width=myobj.width;
//myvideoloader.height=myobj.height;
myvideoloader.play();
} else{

//Wasted lot of time without keeping this code in else block.. Since after playing video imeediately swfloader is expecting image and its overlapping video..
// Sice the video is taking abit amount of time to load due to which the delay problem cant be identified immediately..
myvideoloader.stop();
myvideoloader.visible=false;
myvideoloader.includeInLayout=false;
myloader.visible= true;
myloader.includeInLayout=true;

//Dynamic Setting of Heigh and width of the Image from the Array collection....

//myloader.width=myobj.width;
//myloader.height=myobj.height;
myloader.source=myobj.path;
}
if(myobj.duration>0)
{
timer.stop();
calculateDuration(myobj.duration);
}
myimage.text=myobj.filename;
dispatchEvent(new SlideshowEvent(SlideshowEvent.BEFOREPLAY,myobj));
animateEffect(count);
dispatchEvent(new SlideshowEvent(SlideshowEvent.AFTERPLAY,myobj));
count++;
if(count == _dataprovider.length){
count=0;
Automatic();
}

}


/**
* Following Method is for executing the images/swfs/ until its interval specified in the Arraycollection.
* */

private function calculateDuration(duration:int):void
{

var calctimer:Timer = new Timer(duration,1);
calctimer.addEventListener(TimerEvent.TIMER_COMPLETE,completeduration);
calctimer.start();
if(calctimer.running == true){
timer.stop();
}
if(calctimer.running == false){
timer.start();
Alert.show("TimerCount"+timer.currentCount);
}
timer.stop();
}

/**
* Following method is Dispatched when the execution of images/swf/ is done sucessfully and to call the next image from the stack.
* */

private function completeduration(event:TimerEvent):void
{
timer.start();

}
/**
* Switch to Any Slide of your Choice..
* */
private function gotoSlide():void
{
var num:Number = new Number(go.text);
var myobj:Object = _dataprovider.getItemAt(num) as Object;
myloader.source=myobj.path;
}
/**
* To Switch to First Slide.
* */
private function firstScreen():void
{
var myobj:Object = _dataprovider.getItemAt(0) as Object;
myloader.source=myobj.path;

}
/**
* To Switch to Next Slide.
* */
private function nextSlide():void
{
var myobj:Object = _dataprovider.getItemAt(count+1) as Object;
myloader.source=myobj.path;
}

/**
* To Switch to Previous Slide
* */
private function previousSlide():void
{
var myobj:Object = _dataprovider.getItemAt(count-1) as Object;
myloader.source=myobj.path;
}
/**
* Switch to Last Slide..
* */

private function lastSlide():void
{
var myobj:Object = _dataprovider.getItemAt(_dataprovider.length-1) as Object;
myloader.source=myobj.path;
}

public function set automateslide(automate:Boolean):void
{
if(automate == true){
this._automate = true;
Automatic();
}
}

public function get automateslide():Boolean{
return _automate;
}

/**
* Define custom Effects as per the Choice.
* */
private function animateEffect(count:Number):void
{
switch(count)
{
case 0: blur.end(); blur.play(); break;
case 1: fade.end(); fade.play(); break;
case 2: elastic.end(); elastic.play(); break;
case 3: iris.end(); iris.play(); break;
case 4: wipeup.end(); wipeup.play(); break;
case 5: wipedown.end(); wipedown.play(); break;
case 6: wipeleft.end(); wipeleft.play(); break;
case 7: wiperight.end();wiperight.play(); break;
case 8: pulse.end(); pulse.play(); break;
case 9: shake.end(); shake.play(); break;
case 10: spin.end(); spin.play(); break;
case 11: bounce.end(); bounce.play(); break;
case 12: glow.end(); glow.play(); break;


}
}
private function entryAnimation()
{
entranceanimate.stop();
entranceanimate.play();
}
]]>

























































































































































No comments:

Post a Comment