开发者

Indexing Array, Non-Null Error AS3

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, onC开发者_Python百科lam);
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


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]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜