# XML gallery random frist img / and object unload

**URL:** https://forum.kirupa.com/t/xml-gallery-random-frist-img-and-object-unload/307604
**Category:** Uncategorized
**Created:** [April 6, 2010, 4:28pm UTC](https://forum.kirupa.com/t/xml-gallery-random-frist-img-and-object-unload/307604 "2010-04-06T16:28:15Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![johnyct9760](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@johnyct9760](https://forum.kirupa.com/u/johnyct9760)
#### Post date: [April 6, 2010, 4:28pm UTC](https://forum.kirupa.com/t/xml-gallery-random-frist-img-and-object-unload/307604/1 "2010-04-06T16:28:15Z")

</div>

Hello All I’m have two question about a flash XML gallery that I currently working on.

1. Is there a way to pick a random image node in the XML file - meaning that every time the SWF file loads a random image loads, as the first image.

2. The second question I have is when the user clicks and then next image loads is there a way to unload the last image object.

What I mean is when I look at the SWF file and looks at:  
In the swf window  
Debug \> List Objects  
once you have clicked through a few pictures the list of object is always growing is there a way to unload those objects.

Link to source files:  
[http://www.johncliffordtaylor.com/flashGallery.rar](http://www.johncliffordtaylor.com/flashGallery.rar)

```php
var xmlRequest:URLRequest=new URLRequest("../xml/imageData.xml");
var xmlLoader:URLLoader=new URLLoader(xmlRequest);
var imgData:XML;
var imageLoader:Loader;
var rawImage:String;

var imgNum:Number=0;
//var randomImage:Number = (Math.floor(Math.random() * 4)); <= effort to load a random image node on the the SWF load.
//var imgNum:Number = randomImage;
var checkSec:Timer=new Timer(100);
var numberOfChildren:Number;

xmlLoader.addEventListener(Event.COMPLETE, xmlLoadedF);
picFrame_mc.master_mc.addEventListener(MouseEvent.CLICK, nextImgF);
picFrame_mc.buttonMode=true;

function xmlLoadedF(event:Event):void {
    checkSec.start();
    checkSec.addEventListener(TimerEvent.TIMER, checkerF);
    imgData=new XML(event.target.data);
}
function packagedF():void {
    checkSec.removeEventListener(TimerEvent.TIMER, checkerF);
    rawImage=imgData.image[imgNum].imgURL;
    numberOfChildren=imgData.*.length();
    imageLoader=new Loader ;
    imageLoader.load(new URLRequest(rawImage));
    picFrame_mc.master_mc.addChild(imageLoader);
}
function checkerF(event:TimerEvent):void {
    if (imgNum== 0) {
        packagedF();
    } else if (imgNum < numberOfChildren) {
        imageLoader.unload();
        packagedF();
    } else {
        imageLoader.unload();
        imgNum=0;
        packagedF();
    }
}
function nextImgF(event:MouseEvent):void {
    checkSec.addEventListener(TimerEvent.TIMER, checkerF);
    imgNum++;
}

```
