Aqua-Soft Forums: PictureViewer Random Play - Aqua-Soft Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PictureViewer Random Play Rate Topic: -----

#1 User is offline   dubbb Icon

  • Group: Member
  • Posts: 2
  • Joined: 04-December 08

Posted 06 December 2008 - 05:26 PM

Hi,

When you use the Autoplay option with pictureviewer the images are displayed in Alfabetic order.
i was wondering if someone could change the code so it will show the images in random order.

// main.js

var currentimg = '';  //Current img

var previmg = '';  //Previous img



function Init(){

  LoadImage(1);

}



//Get the extension of the filename

function GetExtensionOfFile(filename){

  var spl;

  spl = filename.split('.');

  return (spl[spl.length-1].toUpperCase());

}

//Is the file a valid image type file.

function FileIsValidImg(filename){

  var ext;

  ext =  GetExtensionOfFile(filename);

  return ((ext=='JPG') || (ext=='BMP') || (ext=='PNG') || (ext=='GIF'));

}

//Get the last valid image file in the directory

function GetLastImgInDirectory(){

  var path = this.ConvertToValue(this.parameters('PATH').value);

  var files = new ActiveXObject("Scripting.FileSystemObject");

  var f = files.GetFolder(path);

  var fc = new Enumerator(f.files);

  var lastimg;

  var filen;

  for (; !fc.atEnd(); fc.moveNext())

  {

	//Name of new file

	filen = fc.item().Name

	if (FileIsValidImg(filen))  //Verify if its a valid image by checking its extension

	  lastimg = filen;

  }

  return(lastimg);

}

//load next image in the directory   Direction 1 or -1 for next or previous

function LoadImage(direction){

  var path = this.ConvertToValue(this.parameters('PATH').value);

  var files = new ActiveXObject("Scripting.FileSystemObject");

  var f = files.GetFolder(path);

  var fc = new Enumerator(f.files);

  var firstimg = '';  

  var newfile = '';

  var viewer = this.layers('DispayImg');



  for (; !fc.atEnd(); fc.moveNext())

  {

	//Name of new file

	newfile = fc.item().Name

	if (FileIsValidImg(newfile))  //Verify if its a valid image by checking its extension

	{

	  if (firstimg == '') // remember the first image

		firstimg = newfile;

	  if (currentimg=='') //First time, image not load yet

	  {

		currentimg = newfile;

		viewer.src = path+''+currentimg;

		return;

	  }

	  else

	  {

		if (newfile == currentimg) //found last image position

		{

		  if (direction > 0) //next

		  {

			currentimg = ''; //get the next file

		  }

		  else

		  {

			if ((previmg == currentimg) || (previmg==''))

			  previmg = GetLastImgInDirectory();

			currentimg = previmg;

			viewer.src = path+''+currentimg;

			return;

		  }

		}

	  }

	  previmg = newfile;   //Remember the previous img

	}

  }

  //If you reach here then you load the first file again

  currentimg = firstimg;

  viewer.src = path+''+currentimg;

} 



//Prompt the user for the path of the files

function PromptPath(){

  var newpath = this.UI.PromptDirectory('Please select a folder with images.');

  if (newpath != '')

  {

	this.parameters('PATH').value = newpath;

	this.controls('Imagepath').redraw();

  }

}

//Drag and Drop a image file

function DropFile(){

  var viewer = this.layers('DispayImg');

  var filename = this.GetDroppedFileName();

  if (FileIsValidImg(filename))

  {

	viewer.src = filename;

  }

}

//Start the slide show

function StartPlay(){

  if (currentimg == '')

	LoadImage(1); //Load one image

  var pl = this.layers('Play');

  var delaytm = this.timers('DELAY');

  var delayval = this.parameters('DELAY');

  delaytm.Delay = delayval.Value; //four seconds

  delaytm.ResetTimer();

  pl.down = true;

}



//Stop Play of all the files

function StopPlay(){

  var pl = this.layers('Play');

  if (pl.down)

  {

	var delaytm = this.timers('DELAY');

	delaytm.StopTimer();

	pl.down = false;

  }

}



//Set the values

function SetValues(){

  if (this.GetChangeToSide() == '1') ///Backside

  {

	var lyscale = this.layers('Scaleimgchk');

	var lyscaleprop = this.layers('Scalepropchk');

	var prmscale = this.parameters('SCALE');

	var prmscaleprop = this.parameters('SCALEPROP');

	lyscale.down = (prmscale.value=='True') //enabled

	lyscaleprop.down = (prmscaleprop.value=='True') //enabled

  }

  if (this.GetChangeToSide() == '0') ///Backside

  { //Set new delay

	var ctrldelay = this.controls('Delay');

	var paramdelay = this.parameters('DELAY');

	paramdelay.value = ctrldelay.value;

	if (this.layers('Play').Down) //animation is running update timer

	{

	  var delaytimer = this.timers('DELAY');

	  delaytimer.Delay = paramdelay.value;

	  delaytimer.ResetTimer();

	}



  }

}



//Set the parameter and the property for scaling

function SetScale(){

	var lyscale = this.layers('Scaleimgchk');

	var prmscale = this.parameters('SCALE');

	lyscale.down = !lyscale.down;

	prmscale.value = lyscale.down;

	var imgdisplay = this.layers('DispayImg');

	imgdisplay.Scale = lyscale.down;

}



//Set the parameter and the property for scale proportional

function SetScaleProp(){

	var lyscale = this.layers('Scalepropchk');

	var prmscale = this.parameters('SCALEPROP');

	lyscale.down = !lyscale.down;

	prmscale.value = lyscale.down;

	var imgdisplay = this.layers('DispayImg');

	imgdisplay.ScaleProportional = lyscale.down;

}

0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic