1 Reply Latest reply on Nov 11, 2008 12:29 AM by Devendran

    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.onLoad = function() {
      var nodes:Array = new Array();
      nodes = nodes.concat(this.firstChild.childNodes);
      numOfItemsIntro = 4;
      for (var i = 0; i<numOfItemsIntro; i++) {
      var t = homeIntro.attachMovie("pic", "pic"+i, i+1);
      t.thumbHolder.hold.loadMovie(nodes .attributes.image);
      t._x = posXIntro;
      posXIntro += thumbWidthIntro+thumbPaddingIntro;

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


      XML File follows this format


      <?xml version="1.0" encoding="utf-8"?>
      <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"/>


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