Skip to main content
Inspiring
August 11, 2010
Question

getting label's height to determine it's y within a class

  • August 11, 2010
  • 1 reply
  • 382 views

I got something like this:

var myClass:myClass = new myClass;

addChild(myClass.showLabel);

Then, inside this class there's this code:

public class myClass {

     private var myLabel:Label;

     private var myCanvas:Canvas;

     public function myClass() {

          myCanvas = new Canvas;

          myCanvas.width = 30;

          myCanvas.height = 30;

          myCanvas.x = 30;

          myCanvas.y = 30;

          myLabel = new Label;

          myCanvas.addChild(myLabel);

     }

     public function showLabel():Canvas {

          myLabel.text = 'example';

          myLabel.y = myCanvas.height/2 - myLabel.height/2;

          return myCanvas

    }

When debuging I see that 'myLabel.height' = 0. I don't know how to find it's final height. I was trying to use myCanvas.validateNow() before determining myLabel.y, but it didn't work.

This is a Flex project, but I don't think this matters.

This topic has been closed for replies.

1 reply

Inspiring
August 11, 2010

You, probably, should post this question in Flex forum.

I don't use Flex but from my limited experience dimensions and x/y coordinates in Flex UIComponents (Canvas is one of those) depend on display list content. If you look at their documentation, width, height, y, and x are [override] variables. This means they don't behave as regular DisplayObject variables.