Skip to main content
tropicanaclock
Known Participant
July 16, 2012
Answered

Tricky Loop code help

  • July 16, 2012
  • 1 reply
  • 644 views

Hey all, I could use some help with this.

So my current code auto adjusts, and resizes a group of text.

I'm looking to convert it to a loop so I can make it generate more text fields without breaking it.

and I'm scratching my head on how to structure it.

addEventListener(Event.ENTER_FRAME,patchSpacingFun);

function patchSpacingFun(event:Event)

{

patTexArr1["pp2"].x = patTexArr1["pp1"].width + patTexArr1["pp1"].x;

          patTexArr1["pp3"].x = patTexArr1["pp2"].width + patTexArr1["pp2"].x;

          patTexArr1["pp4"].x = patTexArr1["pp3"].width + patTexArr1["pp3"].x;

          patTexArr1["pp5"].x = patTexArr1["pp4"].width + patTexArr1["pp4"].x;

          patTexArr1["pp6"].x = patTexArr1["pp5"].width + patTexArr1["pp5"].x;

          patTexArr1["pp7"].x = patTexArr1["pp6"].width + patTexArr1["pp6"].x;

          patTexArr1["pp8"].x = patTexArr1["pp7"].width + patTexArr1["pp7"].x;

          patTexArr1["pp9"].x = patTexArr1["pp8"].width + patTexArr1["pp8"].x;

          patTexArr1["pp10"].x = patTexArr1["pp9"].width + patTexArr1["pp9"].x;

          patTexArr1["pp11"].x = patTexArr1["pp10"].width + patTexArr1["pp10"].x;

          patTexArr1["pp12"].x = patTexArr1["pp11"].width + patTexArr1["pp11"].x;

}

here is basically what I got started for the loop

its supposed to make these from the PatchLims


var patTexArr1:Array = new Array();

for (var i:int =0; i<patchLims; ++i)

{

}

thanks

This topic has been closed for replies.
Correct answer kglad

if patTexArr1 is a movieclip, use:

var patchLims:int=11;

for (var i:int =1; i<patchLims; i++)

{

patTexArr1["pp"+(i+1)]=patTexArr1["pp"+i].width+patTexArr1["pp"+i].x;

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 16, 2012

if patTexArr1 is a movieclip, use:

var patchLims:int=11;

for (var i:int =1; i<patchLims; i++)

{

patTexArr1["pp"+(i+1)]=patTexArr1["pp"+i].width+patTexArr1["pp"+i].x;

}

tropicanaclock
Known Participant
July 16, 2012

Thanks for the help Kglad, got it working!

kglad
Community Expert
Community Expert
July 16, 2012

you're welcome.