Reference a variable in a for loop?

This is using actionscript 2.0.

How do I reference a variable in a for loop?
Any help much appreciated :slight_smile:

//Total Number of Pages
var PageCount:Number = 12;

// Page titles
var PageTitle1:String = "I am Page One";
var PageTitle2:String = "I am Page Two";
var PageTitle3:String = "I am Page Three";
var PageTitle4:String = "I am Page Four";
var PageTitle5:String = "I am Page Five";
var PageTitle6:String = "I am Page Six";
var PageTitle7:String = "I am Page Seven";
var PageTitle8:String = "I am Page Eight";
var PageTitle9:String = "I am Page Nine";
var PageTitle10:String = "I am Page Ten";
var PageTitle11:String = "I am Page Eleven";
var PageTitle12:String = "I am Page Twelve";

//The commented out bit below works, but is lengthy and bloaty ...


text1.text = PageTitle1;
text2.text = PageTitle2;
text3.text = PageTitle3;
text4.text = PageTitle4;
trace("Pagecount1's text= "+text1.text);


// So I want to use  a for loop, something like below, but I'm not 
//sure of the syntax of
//referencing incremented vartiables..

for(var i = 1; i <= PageCount; i++)
    // the below line doesn't work and I don't know why:(
    //["text"+i].text = ["PageTitle"+i]


// Essentially I want to end up with something like:
//text1.text = PageTitle1;
//text2.text = PageTitle2;
//text3.text = PageTitle3;
//text4.text = PageTitle4;
// All the way up to whatever the PageCount is