Displaying multiple random photos from an array.

This is a discussion on Displaying multiple random photos from an array. within the Macromedia Flash forums in Adobe Tools category; Hi Guys/Gals, I'm by no means a pro at actionscript, and have run into an issue making a simple gallery that displays 4 random photos that are loaded from an XML list. The XML is dynamically generating and will have an unknown amount of images listed. Below is the code that I am using now, that does work, however the Array.prototype function is not compatible with an existing framework im using and clashes causing other things to fail. The existing framework cannot be changed, so I am looking for a new way to pull and display these images. Any help ...

Go Back   Application Development Forum > Adobe Tools > Macromedia Flash

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 11-11-2008, 12:03 AM
matter_j
Guest
 
Default Displaying multiple random photos from an array.

Hi Guys/Gals,

I'm by no means a pro at actionscript, and have run into an issue making a
simple gallery that displays 4 random photos that are loaded from an XML list.
The XML is dynamically generating and will have an unknown amount of images
listed.

Below is the code that I am using now, that does work, however the
Array.prototype function is not compatible with an existing framework im using
and clashes causing other things to fail. The existing framework cannot be
changed, so I am looking for a new way to pull and display these images.

Any help is much appreciated.

AS Looks like this.

-----------------------------------------

var numOfItemsIntro:Number;
var homeIntro:MovieClip = this;
var thumbWidthIntro:Number = 185;
var thumbPaddingIntro:Number = 0;
var posXIntro:Number = 0;

var xml:XML = new XML();
xml.ignoreWhite = true;

xml.load("intro-gallery.xml");

xml.onLoad = function() {
var nodes:Array = new Array();
nodes = nodes.concat(this.firstChild.childNodes);
nodes.shuffleIntro();
numOfItemsIntro = 4;
for (var i = 0; i<numOfItemsIntro; i++) {
var t = homeIntro.attachMovie("pic", "pic"+i, i+1);
t.thumbHolder.hold.loadMovie(nodes[i].attributes.image);
t._x = posXIntro;
posXIntro += thumbWidthIntro+thumbPaddingIntro;
}
};


Array.prototype.shuffleIntro = function() {
for (var i = 0; i<this.length; i++) {
var tmpIntro = this[i];
var randomNum = random(this.length);
this[i] = this[randomNum];
this[randomNum] = tmpIntro;
}
};

-----------------------------------------

XML File follows this format

-----------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<icons>
<icon imageid="1" image="usedfiles/image-1.jpg"/>
<icon imageid="2" image="usedfiles/image-2.jpg"/>
<icon imageid="3" image="usedfiles/image-3.jpg"/>
<icon imageid="4" image="usedfiles/image-4.jpg"/>
<icon imageid="5" image="usedfiles/image-5.jpg"/>
<icon imageid="6" image="usedfiles/image-6.jpg"/>
<icon imageid="7" image="usedfiles/image-7.jpg"/>
</icons>

-----------------------------------------


Thanks in advance to anyone who can shed some light onto this.

Matt

Reply With Quote
  #2  
Old 11-11-2008, 03:29 AM
Devendran
Guest
 
Default Re: Displaying multiple random photos from an array.

Below simple function will sort your array


myArray.sort(function(){ return Math.round(Math.random()) == 0 ? -1: 1 })

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:18 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.