views:

27

answers:

1

Hello,
This picture gallery adds children. It does what it needs to, but throws a #2007 error.

There's a garbage and range issue I want to fix. Is there an easy solution for this?
Thanks,

//PICTURE GALLERY
var um0:MovieClip = new z0;
var um1:MovieClip = new z1;
var um2:MovieClip = new z2;
var um3:MovieClip = new z3;
var AR:Array = [um0,um1,um2,um3];
var i:int = 0;  
//GO FORWARD THROUGH GALLERY
b.addEventListener(MouseEvent.CLICK, onClam);
function onClam(e:MouseEvent){
i++;
containerInstance.addChild(AR[i]);
}
//GO BACKWARD THROUGH GALLERY 
d.addEventListener(MouseEvent.CLICK, onClum);
function onClum(e:MouseEvent){
i--;
containerInstance.addChild(AR[i]);
}

ERROR
TypeError: Error #2007: Parameter child must be non-null

+2  A: 

Try this to make your index wrap around the array length (you could also use modulo, but this is simpler I think):

function onClam(e:MouseEvent){
    i++;
    if(i >= AR.lenght) {
        i = 0;
    }
    containerInstance.addChild(AR[i]);
}

function onClum(e:MouseEvent){
    i--;
    if(i < 0) {
        i = AR.length - 1;
    }
    containerInstance.addChild(AR[i]);
}
Juan Pablo Califano
The modulo implementation for +1 is `i = (i + 1) % AR.length;` and for -1 `i = (i + AR.length - 1) % AR.length;`
washwithcare
@washwithcare, thanks for the modulo example.
pixelGreaser