Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Would like my preloader to preload the xml as well! :)

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
OK. here it is.. I have a main flash movie which when you click a button it loads another .swf into the mainholder mc using the following code:

Code:
//begin intro loading process//
_root.attachMovie("loader", "loader", 15)
_root.loader._x = 140;
_root.loader._y = 80;
_root.loader._visible = false;
my_mc = new MovieClipLoader(); 
preload = new Object(); 
my_mc.addListener(preload); 

preload.onLoadStart = function(targetMC) { 
_root.loader._visible = true;}

preload.onLoadProgress = function(targetMC, lBytes, tBytes) { 
_root.loader.bar._width = (lBytes/tBytes)*100; 
_root.loader.pText.text = "% "+Math.round((lBytes/tBytes)*100); 
}; 

preload.onLoadComplete = function(targetMC) { 
_root.loader._visible = false;

}; 

my_mc.loadClip("necklaces.swf", _root.mainholder);

now here's the rub. The movie that is loaded, "necklaces.swf" loads xml data in the first frame - a quite a bit of data. On the first frame of this movie there is a stop command - and then it waits for all the xml data to load - once all the xml data is loaded, it goes to frame 2 where it begins to show the movie, etc.

Now since the first movie simply loads the second movie the preloader completes, but there is a lag when the second movie is loading the xml. (it isn't until the second movie loads all the xml data that it begins to load.

So my question is. Is there a way when u are at the first movie that when you click the button to load the second movie, the preloader not only shows the progress of loading the second movie, but also the xml data load on teh second movie, so there is no lag?

BTW here is the code on the first frame for the second movie:
Code:
stop();

function loadXML(loaded) { 
if (loaded) { 
xmlNode = this.firstChild; 
image = [];   //creating array for xml data image
imagebiggest = [];//when you click on "click to enlarge"
description = []; //creating array for xml data description
price = [];   //creating array for xml data price
bigimage =[];
fulldescription = [];
match1smallpic = [];
match1bigpic = [];
match1price = [];
match1description = [];
match1fulldescription = [];
match2smallpic = [];
match2bigpic = [];
match2price = [];
match2description = [];
match2fulldescription = [];


_root.total = xmlNode.childNodes.length; //used to make sure go through all nodes //don't change _root value
for (i=0; i<_root.total; i++) { 
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue; 
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue; 
price[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue; 
bigimage[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
fulldescription[i] = xmlNode.childNodes[i].childNodes[4].firstChild.nodeValue;
match1smallpic[i] = xmlNode.childNodes[i].childNodes[5].firstChild.nodeValue;
match1bigpic[i] = xmlNode.childNodes[i].childNodes[6].firstChild.nodeValue;
match1price[i] = xmlNode.childNodes[i].childNodes[7].firstChild.nodeValue;
match1description[i] = xmlNode.childNodes[i].childNodes[8].firstChild.nodeValue;
match1fulldescription[i] = xmlNode.childNodes[i].childNodes[9].firstChild.nodeValue;
match2smallpic[i] = xmlNode.childNodes[i].childNodes[10].firstChild.nodeValue;
match2bigpic[i] = xmlNode.childNodes[i].childNodes[11].firstChild.nodeValue;
match2price[i] = xmlNode.childNodes[i].childNodes[12].firstChild.nodeValue;
match2description[i] = xmlNode.childNodes[i].childNodes[13].firstChild.nodeValue;
match2fulldescription[i] = xmlNode.childNodes[i].childNodes[14].firstChild.nodeValue;
imagebiggest[i] = xmlNode.childNodes[i].childNodes[15].firstChild.nodeValue;
//just loaded all data into the arrays - notice the childnodes value for the level of 
//each item//
thumbnails_fn(i); //this function does all the actions we want//
} 
} else { 
content = "file not loaded!"; 
} 
} 
xmlData = new XML(); 
xmlData.ignoreWhite = true; 
xmlData.onLoad = loadXML; 
xmlData.load("images.xml"); 


function thumbnails_fn(k) { 
contentMain.attachMovie("text", "text", 1);
contentMain.text._x = 25;
contentMain.text._y = 25;

itemname = "item" + k; //so we know what number item it is on//
var itemMC = contentMain.attachMovie("item", itemname, contentMain.getNextHighestDepth());
    //item is the name of the mc that we want our pics/text to load into//
    //it loads into contentMain for scrollbar - must use next highest depth.//
	
    //following if statements are for the number of items per line & placing next line at correct place//
    if (k<=2) {
        //3 is the number of items per line, remember it starts at 0 so 3 equals 4 item mc's per line//
        itemMC._x = 30+(itemMC._width+40)*k;
        //first number sets the spacing from left for first mc/
		//width + this number is the spacing between mc's
        itemMC._y = 150;
        //offsetting the first row (moving down) so that my header can be seen.
    } else if (k>=3 && k<=5) {
        //second line starts at fifth item mc//
        itemMC._y = 325;
        //175 (150 (initial setting) + 175) is the amount of spacing on between levels (y value)//
        itemMC._x = 30+(itemMC._width+40)*(k-3);
        //15 is spacing between mc's & 4 is the number of item mc's on first level//
    } else if (k>=6 && k<=8) {
        itemMC._y = 500;
        itemMC._x = 30+(itemMC._width+40)*(k-6);
    } else if (k>=9 && k<=11) {
        itemMC._y = 675;
        itemMC._x = 30+(itemMC._width+40)*(k-9);
	}

tlistener = new Object(); //this function is called after pic is loaded into first "item//
tlistener.onLoadInit = function(target_mc) { //target mc is contentMain.item#.picture
tlistener.onLoadComplete = function() {
//this is where the movie begins to play//	
_root.mainholder.gotoAndPlay(2);
}




target_mc._parent.description.text = description[k];//adds the description from xml
target_mc._parent.price.text = "$" + price[k];//adds price from xml

target_mc._parent.onRelease = function() { 
_root.itemchoicenumber = k; //do not change root value!
_root.bigpicchoice = bigimage[k];
_level0.mainholder.gotoAndStop(10); 
}
target_mc._parent.onRollOver = function() { 
this._alpha = 50; 
this._width = this._width + 5;
this._height = this._height +5;
}; 
target_mc._parent.onRollOut = function() { 
this._alpha = 100; 
this._width = this._width - 5;
this._height = this._height - 5;
}; 
}; 
image_mcl = new MovieClipLoader(); //these 3 lines load the pic into the "item" mc, into the "picture"mc for placement.
image_mcl.addListener(tlistener); //also it calls the tlistener function where all actions for specific movie is held.
image_mcl.loadClip(image[k], contentMain[itemname].picture);
}

You can see an example of what I mean by going to
and clicking on necklaces. You will notice the lag after the necklaces.swf had loaded and it is loading the xml data.

If this is not possible, what are my other options? What might be useful. Thansk in advance.

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top