Hi,
please read the following example code:
var n:int = 0;
function setDotz():void
{
var dot = new point();
var intstanceName:String = “p_mc”+n;
dot.name = intstanceName;
this.container_mc.addChild(dot);
var target:DisplayObject = this.container_mc.getChildByName(intstanceName);
trace(target.name);
this.container_mc.removeChild(target);
/*
The 3 lines above work here.
*/
n++;
}
function removeDotz(i:int)
{
var intstanceName:String = “p_mc”+i;
var target:DisplayObject = this.container_mc.getChildByName(intstanceName);
trace(target.name);
this.container_mc.removeChild(target);
/Here it does not work. Although the trace(target.name) gives the correct result,
this.container_mc.removeChild(target) fails with the Error #1009:
Cannot access a property or method of a null object reference./
}
for (var k:int = 0; k <=20; k++)
{
setDotz();
if (n >=20)
{
for (var i:int = 0; i <=20; i++)
{
removeDotz(i);
}
}
}
I have no idea why in the removeDotz function i can get access to the childs, but i cannot
remove them, whereas that works in the setDotz function.
Any ideas ?