1){
var sizes:ArrayCollection = new ArrayCollection();
for(var i:Number=0; i0){
dynResolution=true;
var sort:Sort = new Sort();
sort.fields=[new SortField("size",true,true)];
sizes.sort=sort;// ^--descending order
sizes.refresh();
urlIdx=sizes.getItemAt(0).index;
for(i=0; i= this.width ||
sizes.getItemAt(i).y >= this.height
) urlIdx=sizes.getItemAt(i).index;
}
}
}
curFile=slideshowXML.Img[idx].URL[urlIdx].toString();
var pattern:RegExp;
if(slideshowXML.Img[idx].URL[urlIdx].attribute('height').length() > 0){
pattern = new RegExp(
slideshowXML.Img[idx].URL[urlIdx].attribute('height'), "g");
if(curFile.search(pattern)>-1){
dynResolution=true;
curFile=curFile.replace(pattern, this.height.toString());
}
}
if(slideshowXML.Img[idx].URL[urlIdx].attribute('width').length() > 0){
pattern = new RegExp(
slideshowXML.Img[idx].URL[urlIdx].attribute('width'), "g");
if(curFile.search(pattern)>-1){
dynResolution=true;
curFile=curFile.replace(pattern, this.width.toString());
}
}
if(Img1.visible) {
src2=null; src2=curFile;
} else {
src1=null; src1=curFile;
}
}
if(slideshowXML.Img[idx].attribute('live')>0){
reloadTimer=new Timer(slideshowXML.Img[idx].attribute('live')*1000,1);
reloadTimer.addEventListener(TimerEvent.TIMER, reloadImg);
reloadTimer.start();
}
}
private var isReload:Boolean;
private function reloadImg(e:TimerEvent):void {
isReload=true; setImgSrc();
}
private var isPlaying:Boolean=false;
private function playPause():void {
if(isPlaying) pause(); else play();
}
private function play():void {
if(!isPlaying && slideshowXML.Img.length()>1) {
if(!playTimer){
playTimer=new Timer(delay*1000, 0);
playTimer.addEventListener(TimerEvent.TIMER, nextSlide);
}
isPlaying=true;
playTimer.start();
}
}
private function pause():void {
if(isPlaying) {
isPlaying=false;
playTimer.stop();
}
}
private function nextSlide(e:Event=null):void {
if(!isEnabled && !forcedByUsr) return;
if(isPlaying) playTimer.stop();
var evnt:MouseEvent = e as MouseEvent;
if(evnt && evnt.type=="mouseUp" && evnt.shiftKey) {
prevSlide();
} else {
idx++;
if(idx==slideshowXML.Img.length()) idx=0;
isReload=false;
setImgSrc();
}
}
private function prevSlide(e:MouseEvent=null):void {
if(!isEnabled && !forcedByUsr) return;
if(isPlaying) playTimer.stop();
idx--;
if(idx<0) idx=slideshowXML.Img.length()-1;
isReload=false;
setImgSrc();
}
private function seek(i:Number):void {
if(!isEnabled && !forcedByUsr) return;
if(isPlaying) playTimer.stop();
if(i<0 || i>=slideshowXML.Img.length())
idx=slideshowXML.Img.length()-1;
else
idx=Math.floor(i);
isReload=false;
setImgSrc();
}
private function onKeyDown(e:KeyboardEvent):void {
forcedByUsr=true;
switch(e.keyCode) {
case 32: //space bar
playPause();
break;
case 36: //home
if(isPlaying) pause();
seek(0);
break;
case 35: //end
if(isPlaying) pause();
seek(-1);
break;
case 37: //<--
prevSlide();
break;
case 39: //-->
nextSlide();
break;
case 82: //`r'
e.shiftKey ? rotate(-1) : rotate();
break;
}
}
private function slideNum():Number {return idx;}
private function numSlides():Number {return slideshowXML.Img.length();}
private function playing():Boolean {return isPlaying;}
private function initApp():void {
this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
ExternalInterface.addCallback("setXML", setXML);
ExternalInterface.addCallback("play",
function():void{forcedByUsr=true;play();});
ExternalInterface.addCallback("pause",
function():void{forcedByUsr=true;pause();});
ExternalInterface.addCallback("playPause",
function():void{forcedByUsr=true;playPause();});
ExternalInterface.addCallback("seek",
function(i:Number):void{forcedByUsr=true;seek(i);});
ExternalInterface.addCallback("slideNum", slideNum);
ExternalInterface.addCallback("numSlides", numSlides);
ExternalInterface.addCallback("playing", playing);
ExternalInterface.addCallback("rotate", rotate);
var itemNextSlide:ContextMenuItem =
new ContextMenuItem("Next Slide, [\u2192]");
this.contextMenu.customItems.push(itemNextSlide);
itemNextSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{forcedByUsr=true;nextSlide();});
var itemPrevSlide:ContextMenuItem =
new ContextMenuItem("Previous Slide, [\u2190]");
this.contextMenu.customItems.push(itemPrevSlide);
itemPrevSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{forcedByUsr=true;prevSlide();});
var itemPlayPause:ContextMenuItem = new ContextMenuItem("N.N.");
this.contextMenu.customItems.push(itemPlayPause);
itemPlayPause.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{forcedByUsr=true;playPause();});
var itemFirstSlide:ContextMenuItem =
new ContextMenuItem("First Slide, [Home]");
this.contextMenu.customItems.push(itemFirstSlide);
itemFirstSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{
forcedByUsr=true;if(isPlaying) pause();seek(0);});
var itemLastSlide:ContextMenuItem =
new ContextMenuItem("Last Slide, [End]");
this.contextMenu.customItems.push(itemLastSlide);
itemLastSlide.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{
forcedByUsr=true;if(isPlaying) pause();seek(-1);});
var itemRotRight:ContextMenuItem =
new ContextMenuItem("Rotate Right, [r]");
this.contextMenu.customItems.push(itemRotRight);
itemRotRight.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{forcedByUsr=true;rotate();});
var itemRotLeft:ContextMenuItem =
new ContextMenuItem("Rotate Left, [\u21e7]+[r]");
this.contextMenu.customItems.push(itemRotLeft);
itemRotLeft.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function(e:ContextMenuEvent):void{forcedByUsr=true;rotate(-1);});
this.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,
function(e:ContextMenuEvent):void{
itemPlayPause.caption=(isPlaying ? "Pause" : "Play")+", [Space]";
itemPlayPause.visible=itemNextSlide.visible=itemPrevSlide.visible=
itemFirstSlide.visible=itemLastSlide.visible=false;
if(slideshowXML.Img.length()>1){
itemPlayPause.visible=itemNextSlide.visible=itemPrevSlide.visible=
itemFirstSlide.visible=itemLastSlide.visible=true;
}
});
timeoutTimer=new Timer(30000, 1);
timeoutTimer.addEventListener(TimerEvent.TIMER, onAnyError);
curFile=xmlfile; if(xmlfile) setXML(xmlfile);
CursorManager.hideCursor();
}
private var isIOError:Boolean;
private function onAnyError(e:Event):void {
if(e.type!=IOErrorEvent.IO_ERROR || setXMLDone==false){
isIOError=false;
setXMLDone=true;
if(Img1.visible){
src2=null; src2="/dev/null"
}else{
src1=null; src1="/dev/null"
}
caption.text=e.type+': '+curFile;
if(e.type==TimerEvent.TIMER)
caption.text="timeout after 30 s: "+curFile;
CursorManager.removeBusyCursor();
}else{
if(isIOError) caption.text=e.type+': '+curFile;
onImgDone(e);
}
caption.visible=true;
if(reloadTimer && reloadTimer.hasEventListener(TimerEvent.TIMER)){
reloadTimer.removeEventListener(TimerEvent.TIMER, reloadImg);
reloadTimer=null; isReload=false;
}
}
private function onImgDone(e:Event):void {
timeoutTimer.reset();
if(e.target==Img1){
Img1.visible=true;Img2.visible=false;
} else {
Img2.visible=true;Img1.visible=false;
}
if(slideshowXML.Img.length()>1){
slideNo.text=String(idx+1)+"/"+slideshowXML.Img.length().toString();
slideNo.visible=slideNo.includeInLayout=true;
} else {
slideNo.visible=slideNo.includeInLayout=false;
}
var curRot:Number=0;
if (rotations.hasOwnProperty(slideshowXML.Img[idx].URL[urlIdx].toString()))
curRot=rotations[slideshowXML.Img[idx].URL[urlIdx].toString()];
else
curRot=Number(slideshowXML.Img[idx].attribute('rot90'));
rotate(0);
if(e.type==FlexEvent.READY) {
rotate(curRot);
if(slideshowXML.Img[idx].caption.toString()!=""){
caption.text=slideshowXML.Img[idx].caption.toString();
caption.visible=true;
} else {
caption.text="";
caption.visible=false;
}
if(!isReload) anim.play();
if(slideshowXML.Img[idx].attribute('live')>0)
cache.removeCacheEntry(curFile);
}
CursorManager.removeBusyCursor();
isEnabled=true;
if(isPlaying && !playTimer.running) playTimer.start();
}
]]>