Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Text manipulation in a loop

Guest
Mar 24, 2015 Mar 24, 2015

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.

TOPICS
ActionScript
319
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Mar 24, 2015 Mar 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");

Translate
LEGEND ,
Mar 24, 2015 Mar 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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2015 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 24, 2015 Mar 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");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 24, 2015 Mar 24, 2015

It always help when you include your code when asking for help with it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2015 Mar 24, 2015
LATEST

Thank You, noted for next time

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines