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!

mc is visible before array actions occur. 1

Status
Not open for further replies.

whoknows361

Technical User
Sep 22, 2005
228
US
hello all. I have successful code at this point - however, there is one thing that continues to occur that I can't figure out how to fix. IF you go to:
you will see that for about 3 seconds before all of my images load via my arrays, you see the frame in the upper left hand corner of the movie and then it dissapears.

Here is my code:
Code:
function loadXML(loaded) { 
if (loaded) { 
xmlNode = this.firstChild; 
image = [];   //creating array for xml data image
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;
//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//
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.//


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

//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//
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*k; //15 sets the spacing between "item" mc's//
target_mc._parent._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//
target_mc._parent._y = 325; //175 (150 (initial setting) + 175) is the amount of spacing on between levels (y value)//
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*(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) {
target_mc._parent._y = 500;
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*(k-6);
}
else if(k>=9 && k<=11) {
target_mc._parent._y = 675;
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*(k-9);
}
else if(k>=12 && k<=14) {
target_mc._parent._y = 850;
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*(k-12);
}
else if(k>=15 && k<=18) {
target_mc._parent._y = 1025;
target_mc._parent._x = 15+(eval(contentMain["item"+k])._width+5)*(k-15);
}

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];
_root.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);
}

Is there something I can change in the above code so that this frame being visible for a couple of seconds doesn't occur? Thanks in advance.

Jonathan
 
That frame is a MovieClip "item" in the Library isn't it? You're waiting the picture to be loaded completely before positioning it. That's why you're seeing it at (0, 0) - default position for attachMovie() - before it's moved to the right position. Instead, you can attachMovie and position it at the same time.

contentMain.attachMovie("item", itemname, contentMain.getNextHighestDepth(), {_x:xPos, _y:yPos});

(You already have the code to calculate xPos and yPos, move it above this line of code)

Kenneth Kawamoto
 
Kenneth,

I tried what I thought might be the answer, however, it loaded every "item" mc in the same place.

Can you show me, (copying the code above) - how this would be corrected with the code above? Thanks so much & sorry for asking you to do the manual stuff, but I am not sure what you mean.

Jonathan
 
What I meant was you should position the MovieClip as soon as it's attached. Try something like this:
Code:
...
     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 = 15+(itemMC._width+5)*k;
		//15 sets the spacing between "item" 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 = 15+(itemMC._width+5)*(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 = 15+(itemMC._width+5)*(k-6);
	} else if (k>=9 && k<=11) {
		itemMC._y = 675;
		itemMCt._x = 15+(itemMC._width+5)*(k-9);
	} else if (k>=12 && k<=14) {
		itemMC._y = 850;
		itemMC._x = 15+(itemMC._width+5)*(k-12);
	} else if (k>=15 && k<=18) {
		itemMC._y = 1025;
		itemMC._x = 15+(itemMC._width+5)*(k-15);
	}
...
(this can be a lot shorter, but that's another matter.)

Kenneth Kawamoto
 
Perfect. How did you come to know the answers to all of my questions :)

Thanks

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top