PDA

View Full Version : using attachMovie multiple times


norfy
09-14-2005, 12:37 PM
I've been searching the site for an answer to this and have inserted some code that people have posted, but it still not quite there. Basically, I wanted to display the same movieclip (a button) on the screen next to each other and then attach different rollover etc functions to each one.

I have created a blank movie clip which I am attempting to attach the multiple movies to (changing the x pos each time). What it is doing is creating the first one, then the second one appears next to it in the right place, but then that disappears and the 3rd one appears it its right place and so on through to the end. So I end up with my first one in place and my last one in place.

I am reading from an xml file to get me the count of the buttons and I'm using a setInterval to delay the output of the buttons on the screen (the idea being they appear one after the other, in a row)

Here is my code:
function xmlLoad(loaded) {
if (loaded) {
xmlNode = this.firstChild;
intNum = intNum;
total = xmlNode.childNodes.length;
catText_arr = [];
catID_arr = [];

for (i=0; i<total; i++) {
catText_arr[i] = xmlNode.childNodes[i].attributes.catText;
catID_arr[i] = xmlNode.childNodes[i].attributes.catid;
}
//create the container movie to attach all other to
attachMovie("boxHolder", boxHolder, 0);
i = 0;
runMovie();
} else {
trace("what xml file");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = xmlLoad;
xmlData.load("xml/images.xml");
function runMovie() {
if (i<=catText_arr.length) {
trace("attach movie"+i);
_root[boxHolder].attachMovie("movie_btn", "movie_btn_"+i+"_mc", this.getNextHighestDepth());
_root[boxHolder]["movie_btn_"+i+"_mc"]._x = 640-28*i;
_root[boxHolder]["movie_btn_"+i+"_mc"]._y = 402;
_root[boxHolder]["movie_btn_"+i+"_mc"].no = i;
_root[boxHolder]["movie_btn_"+i+"_mc"].onRollOver = function() {
catText.text = catText_arr[this.no];
};
_root[boxHolder]["movie_btn_"+i+"_mc"].onRollOut = function() {
catText.text = "";
};
} else {
clearInterval(runMe);
}
i++;
}
runMe = setInterval(runMovie, 500);


I've been looking at this all morning and would appreciate any help you can give.

Thanks
Mark

303 maddec
09-14-2005, 01:24 PM
Hi there,



A: check that your xml loading and parsing is working properly.
B: test your autobutton generation routine (attachement of the correct gfx and assigment of the correct actions.
C: the appear step by steps feature should be tested as soon as the preceeding steps are working properly.

it will be also easier to test each steps separately and to assemble the whole at the end.

A small advice: good practice rules advice to avoid the use of attributes in xml, prefer the usual notation <myTag></myTag> and sub-tags even if it could appear less convenient to use at first, in the long run it will prove to be better.

Best regards.

maddec

norfy
09-14-2005, 01:32 PM
I know the xml is working because it is given me an output count of 6, I was using a for loop which worked perfectly and they all displayed (at once), but I couldn't put the delay on here so that is why I used the setInterval so I could call the function over and over until the count had been reached. (That is still working because when I look at the trace output it is displaying 6 trace outputs and then stopping, ie the clearInterval())

I think the problem exists where I attach the new movies, it seems to be overwriting the previous attached movie with the new movie in it's new position etc.

I just can't figure out why it is not attaching multiple movies to the same initial movie holder.

???

deadbeat
09-14-2005, 07:21 PM
You are using this to get the NextHighestDepth, but you are attaching the clip to _root[boxHolder] - which is whare you need to get the depth from...

Try:

_root[boxHolder].attachMovie("movie_btn", "movie_btn_"+i+"_mc", _root[boxHolder].getNextHighestDepth());

K.

norfy
09-14-2005, 09:20 PM
Great, thanks, that did the trick!
Appreciate your time
Mark