PDA

View Full Version : addChildAt limitations


pcmxa
03-02-2008, 01:42 AM
Hello,

I have an odd problem. I am adding 8 FLVPlabacks to the stage using addChildAt (playback1, 0) addChildAt (playback2, 1). Everything gets added fine. I then try to remove and stop them by:

var playback1clip = getChildAt (0);
removeChildAt(0);
playback1clip.stop();

I do this for each of the 8 FLV's, but when I test the movie it only removes half of them. It removes the ones in position 0, 2, 4, 6 but not at 1, 3, 5, 7. It does this even when I only do three (it removes the first and the third, not the middle one. What is really odd is that if I only put code for removing two:

var playback1clip = getChildAt (0);
removeChildAt(0);
playback1clip.stop();

var playback2clip = getChildAt (1);
removeChildAt(1);
playback1clip.stop();

while loading three (to positions 0, 1, and 2) it will still remove the first and the third, leaving the second. Is there a way "see" what indexes are being used by what objects? Is it possible to see the display list?

Thanks

spoken2.addEventListener(MouseEvent.CLICK, cacaphony);

function cacaphony(evt) {
cacaphonyP *=-1;
if (cacaphonyP == 1) {
var speaker1:FLVPlayback = new FLVPlayback();
var speaker2:FLVPlayback = new FLVPlayback();
var speaker3:FLVPlayback = new FLVPlayback();
var speaker4:FLVPlayback = new FLVPlayback();
var speaker5:FLVPlayback = new FLVPlayback();
var speaker6:FLVPlayback = new FLVPlayback();
var speaker7:FLVPlayback = new FLVPlayback();
var speaker8:FLVPlayback = new FLVPlayback();
speaker1.name = "bob";
speaker1.width=116;
speaker2.width=116;
speaker3.width=116;
speaker4.width=116;
speaker5.width=116;
speaker6.width=116;
speaker7.width=116;
speaker8.width=116;
speaker1.height=150;
speaker2.height=150;
speaker3.height=150;
speaker4.height=150;
speaker5.height=150;
speaker6.height=150;
speaker7.height=150;
speaker8.height=150;
speaker1.x = spaceAmount*1;
speaker2.x = spaceAmount*2;
speaker3.x = spaceAmount*3;
speaker4.x = spaceAmount*4;
speaker5.x = spaceAmount*5;
speaker6.x = spaceAmount*6;
speaker7.x = spaceAmount*7;
speaker8.x = spaceAmount*8;
speaker1.y=150;
speaker2.y=150;
speaker3.y=150;
speaker4.y=150;
speaker5.y=150;
speaker6.y=150;
speaker7.y=150;
speaker8.y=150;
addChildAt(speaker1, 0);
addChildAt(speaker2, 1);
addChildAt(speaker3, 2);
addChildAt(speaker4, 3);
addChildAt(speaker5, 4);
addChildAt(speaker6, 5);
addChildAt(speaker7, 6);
addChildAt(speaker8, 7);
speaker1.source = ("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker2.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker3.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker4.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker5.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker6.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker7.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker8.load("spoken/spoken"+(Math.round(Math.random()*106+1))+".flv");
speaker1.play();
speaker2.play();
speaker3.play();
speaker4.play();
speaker5.play();
speaker6.play();
speaker7.play();
speaker8.play();
} else {
var speaker1clip:Object = getChildAt(0);
removeChildAt(0);
speaker1clip.stop();
var speaker2clip:Object = getChildAt(1);
removeChildAt(1);
speaker2clip.stop();
var speaker3clip:Object = getChildAt(2);
removeChildAt(2);
speaker3clip.stop();

var speaker4clip:Object = getChildAt(3);
removeChildAt(3);
speaker4clip.stop();
var speaker5clip:Object = getChildAt(4);
removeChildAt(4);
speaker5clip.stop();
var speaker6clip:Object = getChildAt(5);
removeChildAt(5);
speaker6clip.stop(5);
var speaker7clip:Object = getChildAt(6);
removeChildAt(6);
speaker7clip.stop();
var speaker8clip:Object = getChildAt(7);
removeChildAt(7);
speaker8clip.stop();

}
}

matbury
03-02-2008, 02:38 AM
Try starting at the highest number and working your way down:

removeChildAt(7);
removeChildAt(6);
removeChildAt(5);
etc.

BTW, you'd be better off handling this kind of thing by storing your FLVPlaybacks in an array. That way you can just loop through them and make you code much more manageable. You can also sort through arrays and use swapChild() to change the depths of particular FLVs.

pcmxa
03-02-2008, 03:55 AM
Try starting at the highest number and working your way down:

removeChildAt(7);
removeChildAt(6);
removeChildAt(5);
etc.

BTW, you'd be better off handling this kind of thing by storing your FLVPlaybacks in an array. That way you can just loop through them and make you code much more manageable. You can also sort through arrays and use swapChild() to change the depths of particular FLVs.
Thanks,

That solved it. Now I will put it into an array. Thanks again for the help.