learningtech
learningtech

Reputation: 33675

actionscript 3 position textfield N pixels from bottom or 90% from top

I'm new to actionscript 3. I want to create a textfield that is either N number of pixels from the bottom of the stage or 90% from the top of the stage.

Basically i want the textfield to always appear near the bottom of the stage. What property of the TextField() object do I configure to achieve this?

Upvotes: 2

Views: 1379

Answers (1)

user562566
user562566

Reputation:

function updateTextPosition():void
{
    var newPositionY:Number = (stage.stageHeight * .90);
    myTextField.y = newPositionY;
}

Now if you want to account for the height of the actual text for whatever reason, you change it to this:

function updateTextPosition():void
{
    var newPositionY:Number = (stage.stageHeight * .90) - myTextField.textHeight;
    myTextField.y = newPositionY;
}

Remember the origin of the field is top left, so the bottom of the text will appear at myTextField.x + myTextField.textHeight;.

Also, you can listen for the RESIZE event on the stage and update your TextField like so:

stage.addEventListener(Event.RESIZE, onStageResized);

function onStageResized(e:Event):void
{
    updateTextPosition();
}

Upvotes: 2

Related Questions