Hello All I’m have two question about a flash XML gallery that I currently working on.
-
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.
-
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
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++;
}