AS3 Nested loops, arrays and movieclips

So I have an array like so

    var i:int;

    for (i=0; i< points.length; i++) {
                
    if (TotalScore >= points[i])
    {
    ach.scroll.content["ach"+i].text = "Unlocked";
    ach.scroll.content["ach"+i].textColor = 0x9900cc;
    
    }
                
}

That displays achievements on an interface.

But what I also want to do is display when an achievement is unlocked using a popup with another interface… results. The popup lets a player know they have unlocked an achievement without having to go to the achivements interface everytime. The popup must only display once until the next achievement is reached. The popup is set to ‘true’.

So …

I know it has something to do with nested loops. Somewhere in there I have to tell it to play the popup once prior to the results interface but still show each achievement as unlocked on the achievements interface.

I tried to add a new for loop but it either displays the popup every time or doesn’t show all the achievements when they are reached.

Couldn’t you put in a boolean to check if the popup already played? So if the loop is re-evaluated, it is just ignored and doesnt play, since it has a flag that tells it it already played?

You can put the boolean in the [ach+i] object. Like [ach +i].didplay = true?

Edit: I assume this is as2?

No its AS3. Sorry I should have specified. Yes I’ve tried that but it plays the popup every time instead of once until the next condition is met.

Hmm, that sounds like the boolean is not set properly or not preserved? Perhaps store the booleans in an array of equal length of the points array, in the same scope as the points array?

Also, you don’t want to work programmatically on graphic that is not displayed, so you should seperate popup from achievment if one of them is not shown.

Thanks for your reply but since I’m a total noob could you please be more specific? How would I separate the popup from the achievement?

This is the code for the popup…

function showAchPopUp(yes:Boolean)
{
if(yes)
{
goTween(resultmc.AchPopUp_mc, “alpha”, 0, 1);
goTween(resultmc.AchPopUp_mc, “scaleX”, 1, 1);
goTween(resultmc.AchPopUp_mc, “scaleY”, 1, 1);
goTween(resultmc.AchPopUp_mc, “y”, -3000, 0);
resultmc.AchPopUp_mc.btn.buttonMode = true;
resultmc.AchPopUp_mc.btn.addEventListener(MouseEvent.CLICK, hideAchunlocked);

} else
{
goTween(resultmc.AchPopUp_mc, "alpha", 1, 0);
goTween(resultmc.AchPopUp_mc, "scaleX", 1, 1);
goTween(resultmc.AchPopUp_mc, "scaleY", 1, 1);
goTween(resultmc.AchPopUp_mc, "y", resultmc.AchPopUp_mc.y, -3000);
resultmc.AchPopUp_mc.btn.removeEventListener(MouseEvent.CLICK, hideAchunlocked);

}
resultmc.AchPopUp_mc.ach1.text = "You have unlocked one or more Achievements"; 
resultmc.AchPopUp_mc.DisplayTxt.text = "Your Results"; 

}
function hideAchunlocked(e:MouseEvent){

var mc:MovieClip = MovieClip(e.currentTarget.parent);
positioningInterface(mc, mc.x, -1000);	

}

and the array for points is like so…

var points:Array = [100, 200,300, 400, 500];

I had tried adding showAchPopUp(true); to the for loop but of course that’s displaying the popup every time. Obviously I have to set it to false once it has played until the next condition is met. Am so confused.

And I realised in the original question I wrote that I had an array whereas it should have been ‘a for loop’. Told you I’m a noob lol

I don’t understand why this is so difficult!

The achievements display as should but why can’t I get the popup movieclip to display when an achievement is met… once? I have no probs getting the popup to display but I just can’t get it to not play until required.

if (TotalScore >= points[i])
{
ach.scroll.content[“ach”+i].text = “Unlocked”;
ach.scroll.content[“ach”+i].textColor = 0x9900cc;
if the ach is unlocked display a movieclip once
if the ach is unlocked don’t display the movieclip again until the next ach is unlocked

}

I’ve looked at creating a new function … say displayAch and setting a for loop and walking backwards thru it saying popup true else false.

I’ve tried to create 2 for loops in the achievements and breaking the outside loop (the popup) but it breaks the achievements as well.

Btw separating the popup from the achievements may not work since points isn’t the only achievement in my game. I have games played and correct answers too and this data isn’t known until checkAchieve is fired (which is where the points and other arrays are checked if locked or unlocked).

I am tearing my hair out! I seem to get one thing to work but not both!

Sigh.