Skip to main content
March 24, 2015
Answered

Text manipulation in a loop

  • March 24, 2015
  • 1 reply
  • 356 views

Hi all, very new to actionscript, so may be very simple and stupid question, but here I go : So just a simple program where the user enters a base and a power i.e : 4^3. My job is to show the user the value of that base to every power smaller and equal to it. So in this example it would show as :

4^0=1

4^1=4

4^2=16

4^3=64

I am able to show the value but only of the power entered by user, my question is how can I loop it so that every value is shown? And so that every different value is beneath the previous one as shown in my example.

If it isn't clear enough feel free to ask additional questions.

Thanks for the help.

This topic has been closed for replies.
Correct answer dmennenoh

Use the appendText method of the TextField - this way you can add to the field instead of replacing it's contents with .text = ""

monMessage.appendText(nouvMessage + "\n");

1 reply

Ned Murphy
Legend
March 24, 2015

Create a for loop that counts up from 0 to the specified power value...

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

     // calculate using the value of i

}

March 24, 2015

I understand how to do the loop itself, what I am having trouble with is the text displaying, this is what I have so far :

var i:int =1;

  var exposantMaleable:int = 1;

  while(exposantMaleable <= exposant)

  {

  nouvMessage="Le chiffre " + base + " exposant " + exposantMaleable + " = " + puissance;

  monMessage.text=nouvMessage;

  addChild(monMessage);

  puissance = Math.pow(base, exposantMaleable);

  exposantMaleable ++

nouvMessage="Le chiffre " + base + " exposant " + exposantMaleable + " = " + puissance;


^that is the part I would like to loop, the message itself, so that the loop adds on the right amount of messages, when I run the program it only shows the message once

dmennenohCorrect answer
Inspiring
March 24, 2015

Use the appendText method of the TextField - this way you can add to the field instead of replacing it's contents with .text = ""

monMessage.appendText(nouvMessage + "\n");