How to pass an integer to create new variable name?

Posted by Joe on Stack Overflow See other posts from Stack Overflow or by Joe
Published on 2012-07-07T15:02:30Z Indexed on 2012/07/07 15:16 UTC
Read the original article Hit count: 157

Filed under:

I have 50 svg animations named animation0, animation1, animation2 etc. and I want to load them when the integer 0 to 49 is passed to this function:

function loadAnimation(value){
    var whichswiffy = "animation" + value;
    var stage = new swiffy.Stage(document.getElementById('swiffycontainer'), whichswiffy);
    stage.start();
}

It doesn't work at the moment, maybe it's passing 'whichswiffy' rather than 'animation10'?

Any ideas?

© Stack Overflow or respective owner

Related posts about JavaScript