Hey everybody. I currently have a gallery that loads from XML. I was wondering if there was a way to add a preloader to load all of the image nodes at the beginning of the .swf. I tried making en empty movieclip off of the stage and loading each image into it to cache them, but it didn’t seem to work. Take a look here to see what I’m working on. When you click a button, the images load after the tween. Click on the button again after the images are cached to see what it is supposed to look like. Here’s my AS:
import mx.transitions.Tween;
import mx.transitions.easing.*;
import com.mosesSupposes.fuse.*;
ZigoEngine.register(Fuse,PennerEasing,FuseFMP);
import flash.display.BitmapData;
var i:Number;
var totalBytes:Number
function loadXML(loaded) {
var singleNodes:Array = new Array();//Array to hold the different nodes
if (loaded) {
var xmlNode = this.firstChild;
var menuItems = xmlNode.childNodes;
var smallPics:Array = new Array();
_root.createEmptyMovieClip("menuHolder",1);
menuHolder._y = 50;
_root.createEmptyMovieClip("pictureHolderNoSee", 1000);
pictureHolderNoSee._x = -1000;
for (i=0; i<=menuItems.length-1; i++) {
var menuTitles = xmlNode.childNodes*.attributes.titles;
smallPics.push(xmlNode.childNodes*.childNodes*.attributes.small);
singleNodes.push(xmlNode.childNodes*);//Add node to singleNodes
attachButtons();
_root.menuHolder["button"+i].name_txt.text = menuTitles;
_root.menuHolder["button"+i].onRollOver = onButtonRollOver;
_root.menuHolder["button"+i].onRollOut = onButtonRollOut;
_root.menuHolder["button"+i].onReleaseOutside = onButtonRollOut;
_root.menuHolder["button"+i].i = i;//Property called i
_root.menuHolder["button"+i].onRelease = function() {
for (t=0; t<=100; t++) {
removeMovieClip(_root["outsideHolder"+t]);
}
for (j=0; j<=singleNodes[this.i].childNodes.length-1; j++) {//Length for each one
//trace(singleNodes[this.i].childNodes[j].attributes.big);
_root.createEmptyMovieClip("outsideHolder"+j,_root.getNextHighestDepth()+10);
_root["outsideHolder"+j].createEmptyMovieClip("pictureHolder",1);
_root["outsideHolder"+j]._xscale = 30;
_root["outsideHolder"+j]._yscale = 30;
var img1:BitmapData = BitmapData.loadBitmap("img2");
_root["outsideHolder"+j]._x = randRange(0, Stage.width);
_root["outsideHolder"+j]._y = Stage.height+100;
_root["outsideHolder"+j]._rotation = randRange(-10, 10);
loadBitmapSmoothed(singleNodes[this.i].childNodes[j].attributes.big,_root["outsideHolder"+j].pictureHolder);
var tw3:Tween = new Tween(_root["outsideHolder"+j], "_x", Strong.easeOut, _root["outsideHolder"+j]._x, randRange(210, Stage.width-100), 1, true);
var tw4:Tween = new Tween(_root["outsideHolder"+j], "_y", Strong.easeOut, _root["outsideHolder"+j]._y, randRange(0, Stage.height-200), 1, true);
var tw5:Tween = new Tween(_root["outsideHolder"+j], "_rotation", Strong.easeOut, _root["outsideHolder"+j]._rotation, randRange(-30, 30), 1, true);
_root["outsideHolder"+j].onPress = function() {
startDrag(this, false, 0, 0, Stage.width-200, Stage.height-200);
this.swapDepths(_root.getNextHighestDepth());
var f:Fuse = new Fuse();
f.push({target:this, time:1, xscale:50, yscale:50, DropShadow_strength:0.5, rotation:0, ease:"easeOutExpo"});
f.push({target:this, DropShadow_strength:0.5, xscale:75, yscale:75, delay:0.5});
f.start();
};
_root["outsideHolder"+j].onRelease = _root["outsideHolder"+j].onReleaseOutside=function () {
this.stopDrag();
var f:Fuse = new Fuse();
f.push({target:this, time:1, xscale:30, yscale:30, DropShadow_strength:0, rotation:randRange(-20, 20), ease:"easeOutExpo"});
f.start();
};
}
};
}
} else {
trace("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("menu.xml");
///////////////////////////////////
/////Functions/////////////////////
function attachButtons() {
menuHolder.attachMovie("button","button"+i,i,{_x:0, _y:(i*20)+110});
}
function onButtonRollOver() {
var tw:Tween = new Tween(this.name_txt, "_x", Strong.easeOut, this.name_txt._x, 20, 0.5, true);
var tw2:Tween = new Tween(this.button_bg, "_alpha", Strong.easeOut, this.button_bg._alpha, 100, 0.5, true);
}
function onButtonRollOut() {
var tw:Tween = new Tween(this.name_txt, "_x", Strong.easeOut, this.name_txt._x, 9, 0.5, true);
var tw2:Tween = new Tween(this.button_bg, "_alpha", Strong.easeOut, this.button_bg._alpha, 60, 0.5, true);
}
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.round(Math.random()*(max-min+1)+(min-.5));
return randomNum;
}
function loadBitmapSmoothed(url:String, target:MovieClip) {
var bmc:MovieClip = target.createEmptyMovieClip("bmc", target.getNextHighestDepth());
var listener:Object = new Object();
listener.tmc = target;
listener.onLoadInit = function(mc:MovieClip) {
mc._visible = false;
var bitmap:BitmapData = new BitmapData(mc._width, mc._height, true);
this.tmc.attachBitmap(bitmap,this.tmc.getNextHighestDepth(),"auto",true);
bitmap.draw(mc);
this.tmc._x = (this.tmc._width/2)*-1;
this.tmc._y = (this.tmc._height/2)*-1;
var w:Number = this.tmc._width;
var h:Number = this.tmc._height;
this.tmc.lineStyle(5,0xFFFFFF,100,true,"none","square","miter",10);
this.tmc.moveTo(0,0);
this.tmc.lineTo(w,0);
this.tmc.lineTo(w,h);
this.tmc.lineTo(0,h);
this.tmc.lineTo(0,0);
};
var loader:MovieClipLoader = new MovieClipLoader();
loader.addListener(listener);
loader.loadClip(url,bmc);
}
And my XML (just in case):
[URL=“http://gotoandlearnforum.com/viewtopic.php?f=28&t=19354#”]
<?xml version="1.0"?>
<menu>
<item titles="Bookshelf">
<pic big="pics/bookshelf/photo1big.jpg"></pic>
<pic big="pics/bookshelf/photo2big.jpg"></pic>
<pic big="pics/bookshelf/photo3big.jpg"></pic>
<pic big="pics/bookshelf/photo4big.jpg"></pic>
</item>
<item titles="Boxes">
<pic big="pics/boxes/photo1big.jpg"></pic>
<pic big="pics/boxes/photo2big.jpg"></pic>
<pic big="pics/boxes/photo3big.jpg"></pic>
<pic big="pics/boxes/photo4big.jpg"></pic>
<pic big="pics/boxes/photo5big.jpg"></pic>
<pic big="pics/boxes/photo6big.jpg"></pic>
<pic big="pics/boxes/photo7big.jpg"></pic>
<pic big="pics/boxes/photo8big.jpg"></pic>
<pic big="pics/boxes/photo9big.jpg"></pic>
</item>
<item titles="Hope Chest">
<pic big="pics/chest/photo1big.jpg"></pic>
<pic big="pics/chest/photo2big.jpg"></pic>
<pic big="pics/chest/photo3big.jpg"></pic>
<pic big="pics/chest/photo4big.jpg"></pic>
<pic big="pics/chest/photo5big.jpg"></pic>
<pic big="pics/chest/photo6big.jpg"></pic>
</item>
<item titles="Desk">
<pic big="pics/desk/photo1big.jpg"></pic>
<pic big="pics/desk/photo2big.jpg"></pic>
<pic big="pics/desk/photo3big.jpg"></pic>
<pic big="pics/desk/photo4big.jpg"></pic>
<pic big="pics/desk/photo5big.jpg"></pic>
<pic big="pics/desk/photo6big.jpg"></pic>
<pic big="pics/desk/photo7big.jpg"></pic>
<pic big="pics/desk/photo8big.jpg"></pic>
<pic big="pics/desk/photo9big.jpg"></pic>
<pic big="pics/desk/photo10big.jpg"></pic>
<pic big="pics/desk/photo11big.jpg"></pic>
<pic big="pics/desk/photo12big.jpg"></pic>
<pic big="pics/desk/photo13big.jpg"></pic>
</item>
<item titles="Crown Moulding">
<pic big="pics/moulding/photo1big.jpg"></pic>
<pic big="pics/moulding/photo2big.jpg"></pic>
</item>
<item titles="TV Stand">
<pic big="pics/stand/photo1big.jpg"></pic>
<pic big="pics/stand/photo2big.jpg"></pic>
<pic big="pics/stand/photo3big.jpg"></pic>
<pic big="pics/stand/photo4big.jpg"></pic>
<pic big="pics/stand/photo5big.jpg"></pic>
<pic big="pics/stand/photo6big.jpg"></pic>
<pic big="pics/stand/photo7big.jpg"></pic>
<pic big="pics/stand/photo8big.jpg"></pic>
<pic big="pics/stand/photo9big.jpg"></pic>
<pic big="pics/stand/photo10big.jpg"></pic>
<pic big="pics/stand/photo11big.jpg"></pic>
<pic big="pics/stand/photo12big.jpg"></pic>
</item>
<item titles="Tables">
<pic big="pics/tables/photo1big.jpg"></pic>
<pic big="pics/tables/photo2big.jpg"></pic>
<pic big="pics/tables/photo3big.jpg"></pic>
<pic big="pics/tables/photo4big.jpg"></pic>
<pic big="pics/tables/photo5big.jpg"></pic>
<pic big="pics/tables/photo6big.jpg"></pic>
<pic big="pics/tables/photo7big.jpg"></pic>
<pic big="pics/tables/photo8big.jpg"></pic>
<pic big="pics/tables/photo9big.jpg"></pic>
<pic big="pics/tables/photo10big.jpg"></pic>
<pic big="pics/tables/photo11big.jpg"></pic>
<pic big="pics/tables/photo12big.jpg"></pic>
<pic big="pics/tables/photo13big.jpg"></pic>
</item>
</menu>
Thanks for anyone’s help.