0

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?

//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

1 Answer 1

2

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]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

The modulo implementation for +1 is i = (i + 1) % AR.length; and for -1 i = (i + AR.length - 1) % AR.length;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.