ADD NEW FRAME - Need help urgently!

I’m almost done with my little application, but as allways there’s a problem.

Little description: I have an array of questions and function which randomly choose n of those questions. I want only 10 questions to be displayed on the screen (10 questions in each frame). For better understanding, I’ve created function which “breakes” those n questions into portions of 10 questions and push each portion into separated Sprite and then all Sprites into one array of Sprites which I called pitanjaSprites. So each element of that array is the mentioned 10-queastions array in each own Sprite.** The problem** is in displaying that Sprites. I’ve added eventhandler to the stage like this:

  • pitanjaSprites = array with Sprites
    I want each element of that array to be displayed in separated Frame


* addEventListener(Event.ENTER_FRAME, onEnterFrame);
*
* function onEnterFrame(event:Event) {
    for (var j:int=0; j<pitanjaSprites.length; j++) {
        if (this.currentFrame == j+1) {
            addChild(pitanjaSprites[j]);
        }
    }
}*

You’re probably assuming what’s happening! Each time I enter a certain frame, not only the corresponding pitanjaSprites element is displayed but all of them!!! (except on the first frame) NEED HELP WITH THAT!!!

Theoretically I know what would I have to do to fix the problem, but don’t know how to write proper code for that! I’ve tried with removeChild but it doesn’t work, at least not on the way I’ve created “child removing”. If somehow I could first empty the stage in the particular frame (frame I’m entering at particular moment) and then add child.

Other solution I could think of is creating new frame with AS, not in .fla document, which would be more practical, since I don’t know what n number of questions will be randomly chosen and how many of 10-questions portions am I going to have - the number of frames, in total, depends on that information…

I’m really slightly going mad since I’m circling for few days in almost same part of the code and don’t know how to fix it.

Thanks anybody who is willing to give me a hint…

Aleksandra-Maria Vukovic