Link to home
Start Free TrialLog in
Avatar of rgarimella
rgarimella

asked on

Spacing Dynamic TextFields Y axis in AS3

Hi Folks,

I was trying to position the text dynamically, especially the y axis.

I want that there should be always 40 pixels difference between all the textfields irrespective of their height.

How do I get the calculation/logic so that y and 40 pixel difference is calculated from the last line of the text of the previous text field.

Thanks

RG

The code below shows 40 pixel difference but does not calulcate the height of the TextField.
var tTimer:Timer = new Timer(50, 1); // adding a new timer that will trigger ONCE
tTimer.addEventListener("timer", positionText); // Adding a listener, that will trigger after the estimated time (50ms)
tTimer.start(); // initialising the timer
 
 
function positionText(event:TimerEvent):void {
    for(var i:int = 0; i < _totalDistractors ; i++) {
		//*******
		var taradioButtoni:TextField = new TextField();
 
		taradioButtoni.multiline = true;
		taradioButtoni.wordWrap= true ;
		taradioButtoni.text = answerChoices[i];
		taradioButtoni.width = 380;
 
		taradioButtoni.x = 60;
		taradioButtoni.y = answerY + i*(taradioButtoni.textHeight + 40);
		trace("y " + taradioButtoni.y);
 
		addChild(taradioButtoni);
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SamuelRostol
SamuelRostol
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, the attachment didn't attach - here it is :)
TextPositioning.fla.zip
Avatar of rgarimella
rgarimella

ASKER

Perfect

Thanks so much

RG