Question

Hi I'm trying to make a powers calculator that displays every line calculated by the while loop in my actionscript3 code. When I run the program, the flash file only displays the last loop, can anyone help to make it work without using trace? I need it to display in the flash program. Here is my code:

private function evalue(event:MouseEvent = null):void 
{ 
maMiseEnForme.font="Arial"; 
maMiseEnForme.size=14; 
maMiseEnForme.bold=true; 
maMiseEnForme.color=0x000000; 
monMessage.x=270; 
monMessage.y=375; 

monMessage.autoSize=TextFieldAutoSiz... 
monMessage.border=true; 
monMessage.defaultTextFormat=maMiseE... 

var base:uint; 
var reponse:uint; 
var puissanceCount:int=1; 
var puissance:uint; 
var reponseText:String; 


base = uint(boiteBase.text); 
puissance = uint(boitePuissance.text); 
while (puissanceCount <= puissance) 
{ 
reponse = Math.pow(base,puissanceCount); 
reponseText=(base + "^" + puissanceCount + "=" + reponse + "\n"); 
monMessage.text=reponseText; 
addChild(monMessage); 
puissanceCount++ 
} 
} 
} 
}

I have attached a picture of what appears in the .swf window:

P.S: I'm a newbie to flash.

Thanks in advance.

Was it helpful?

Solution

You can use "+=" parameter instead of "=" parameter to update a string variable by "adding string to it" instead of "refreshing it everytime", then you can show text after your while loop finished. You don't need to addChild(nonMessage) in everyloop, just move it after your while{} loop. SO: You just need "monMessage.text+=reponseText;" instead of "monMessage.text=reponseText;" and move your "addChild()" to next to your while loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top