Wednesday, December 16, 2009

Slide Show with Transitions Using Flex..





[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();
[Bindable] public var timer:Timer;
[Bindable] public var _automate:Boolean=false;
var evencount:int=0;
var oddcount:int=0;
public var _dataprovider:ArrayCollection = new ArrayCollection();
public var evencollection:ArrayCollection = new ArrayCollection();
public var oddcollection:ArrayCollection = new ArrayCollection();
public var mycollection:ArrayCollection = new ArrayCollection([
{id: 10, filename: 'Falling Stars', width:1000, height:400,duration:10000,path:"falling-stars.swf"},
{id: 2, filename: 'Hippo.jpg', width:600, height:400,duration:3000,path:"http://lsst.astro.washington.edu/images/ImageSimColorLarge.jpg"},
{id: 4, filename: 'amalfi-bw.jpg', width:700, height:400,duration:3000,path:"http://bioinformatics.icmb.utexas.edu/lgl/PHN/phn.large.png"},
{id: 3, filename: 'amalfi.jpg', width:600, height:400,duration:3000,path:"http://helpexamples.com/flash/images/image1.jpg"},
{id: 5, filename: 'EiffelTower.jpg', width:800, height:400,duration:3000,path:"hi1.jpg"},
{id: 6, filename: 'Fountain and Edinburgh Castle.jpg', width:900, height:400,duration:3000,path:"hi2.jpg"},
{id: 7, filename: 'ravello.jpg', width:1000, height:400,duration:7000,path:"ravello.jpg"},
{id: 8, filename: 'nepal1.jpg', width:1000, height:400,duration:7000,path:"nepal1.jpg"},
{id: 9, filename: 'nepal.jpg', width:1000, height:400,duration:1000,path:"nepal2.jpg"},
{id: 10, filename: 'Falling Stars', width:1000, height:400,duration:10000,path:"falling-stars.swf"}]);


private function loadimages():void
{



}


// 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
{ _dataprovider=mycollection;


for(var i:Number=0;i<_dataprovider.length;i++)
{
if(i%2==0)
{
evencollection.addItem(_dataprovider.getItemAt(i));

} else if( i%2 !=0){
oddcollection.addItem(_dataprovider.getItemAt(i));
}

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


/**
* Timer Handler is for Triggering all the Elements in the Array.
*
**/
private function timerhandler(evt:TimerEvent):void
{
var x:Loader = new Loader();

if(count < _dataprovider.length){
if(count %2 ==0){

myobj= evencollection.getItemAt(evencount);
var req:URLRequest = new URLRequest(myobj.path);
x.load(req);
if(x.contentLoaderInfo.bytesLoaded == x.contentLoaderInfo.bytesTotal)
{
Alert.show("All Loaded");
}else{
Alert.show("Not Loaded");
}
var extension:String = myobj.path;
var filetype:int = extension.lastIndexOf(".");
var extens:String=extension.substr(filetype,extension.length);
if(extens == ".flv")
{
currentState="One";
panel1video.includeInLayout=true;
panel1video.visible=true;
animateEffect(count);
panel1video.source = myobj.path;
if(panel1image.percentLoaded == 100){

panel1video.play();
p1.visible=true;
p1.includeInLayout=true;
if(myobj.duration>0)
{
timer.stop();
calculateDuration(myobj.duration);
animateEffect(count);
}
}
//panel2video.stop();
} else{

if(panel1image.percentLoaded==100)
{
Alert.show("Loaded");
}
panel1image.source=myobj.path;
panel1image.visible= true;
panel1image.includeInLayout=true;

p1.visible=true;
p1.includeInLayout=true;
currentState="One";
if(myobj.duration>0)
{
timer.stop();
calculateDuration(myobj.duration);
animateEffect(count);
}
}
evencount++;
count++;
}
else if(count %2!=0){

myobj= oddcollection.getItemAt(oddcount);
if(extens == ".flv")
{
currentState="Two";
panel2video.includeInLayout=true;
panel2video.visible=true;
panel2video.source = myobj.path;
panel2video.play();
animateEffect(count);
p2.visible=true;
p2.includeInLayout=true;
if(myobj.duration>0)
{
timer.stop();
calculateDuration(myobj.duration);
animateEffect(count);
}
}
else{

panel2image.source=myobj.path;
if(panel2image.percentLoaded==100)
{
Alert.show("Loaded");
}else{
Alert.show("Not Loaded");
}
panel2image.visible=true;
panel2image.includeInLayout=true;
p2.visible="true";
p2.includeInLayout=true;
currentState="Two";
if(myobj.duration>0)
{
timer.stop();
calculateDuration(myobj.duration);
}
}
oddcount++;
count++;
}
}
}


/**
* 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;


}
}



]]>












































































































































x="0" y="0" width="5" height="5"
click="currentState='One'" visible="false" >







x="0" y="110" width="5" height="5"
click="currentState='Two'" visible="false">




























1 comment: