1 Reply Latest reply on May 14, 2009 4:19 PM by Flex harUI

    Overriding the coordinate functions

    Martin Harrigan

      Hi all,

       

      Can somebody put me out of my misery and explain what's going wrong here: I want to create a custom control that "pads itself". I have two files: main.mxml has a Canvas with no padding that includes a custom Label component. For the Label component (ui/MyLabel.as) I have overridden the set/get x/y functions to include some padding. But it doesn't work! If I remove the two get functions it works okay, but I want the padding to be completely transparent to anything that uses MyLabel. What am I overlooking and is there any way to fix it?

       

      Regards,

      Martin.

       

      main.mxml:

      ******************************

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:ui="ui.*" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Canvas>
              <ui:MyLabel text="Hello World!" x="0" y="0" />
          </mx:Canvas>
      </mx:Application>

       

       

      ui/MyLabel.as:

      ******************************

      package ui {

       

          import mx.controls.Label;
         
          public class MyLabel extends Label {
             
              private static const MY_PADDING : uint = 100;
         
              public function MyLabel() { super(); }

              override public function get x() : Number { return super.x - MY_PADDING; }

              override public function set x(v : Number) : void { super.x = v + MY_PADDING; }

              override public function get y() : Number { return super.y - MY_PADDING; }

              override public function set y(v : Number) : void { super.y = v + MY_PADDING; }
          }
      }