Wednesday, December 9, 2009

simple slideshow using flex




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;

public var mycollection:ArrayCollection = new ArrayCollection([
{id: 1, filename: 'Car Abonded', width:400, height:400,duration:3000,path:"abandoned car.jpg"},
{id: 2, filename: 'first.flv', width:500, height:400,duration:10000,path:"first.flv"},
{id: 3, filename: 'amalfi.jpg', width:600, height:400,duration:3000,path:"amalfi.jpg"},
{id: 4, filename: 'amalfi-bw.jpg', width:700, height:400,duration:3000,path:"amalfi-bw.jpg"},
{id: 5, filename: 'EiffelTower.jpg', width:800, height:400,duration:3000,path:"EiffelTower.jpg"},
{id: 6, filename: 'Fountain and Edinburgh Castle.jpg', width:900, height:400,duration:3000,path:"Fountain and Edinburgh Castle.jpg"},
{id: 7, filename: 'Hippo.jpg', width:1000, height:400,duration:3000,path:"Hippo.jpg"},
{id: 8, filename: 'bubbles Animation', width:1000, height:400,duration:3000,path:"bubbles.swf"},
{id: 9, filename: 'Falling Stars', width:1000, height:400,duration:6000,path:"falling-stars.swf"},
{id: 10, filename: 'Falling Stars', width:1000, height:400,duration:10000,path:"falling-stars.swf"}]);

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

}

[Bindable] public var timer:Timer;
private var _automate:Boolean;

/**
* Automatic is Called When we want the slideShow to be Done Automatically.
* */

private function Automatic():void
{
timer= new Timer(1000,mycollection.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= mycollection.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;
myvideoloader.visible=true;
myvideoloader.source = "http://www.helpexamples.com/flash/video/caption_video.flv";
super.invalidateProperties();
myvideoloader.autoPlay=true;
}
//myvideoloader.stop();
myvideoloader.visible=false;
myloader.visible= 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;
animateEffect(count);
count++;
if(count == mycollection.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();
}
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)
{
timer.start();

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

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

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

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

private function set automate(automate:Boolean)
{
if(automate == true)
{
_automate = true;
Automatic();
}
}

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

/**
* Define custom Effects as per the Choice.
* */
private function animateEffect(count:Number)
{
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;


}
}

]]>




















































































































No comments:

Post a Comment