Author Topic: FlxButton label is offset from corner of screen, instead of button  (Read 884 times)

pampl

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Normally when I load text in a FlxButton it uses the X and Y co-ords as offsets from the upper left corner of the button, instead of the corner of the screen, but for some reason I can't figure out one button is doing the latter.
Here's the base state where I create the buttons:
Code: [Select]
override public function create() :void
{
player = SaveGame.loadCharacter();

firstButton = new FlxButton(1, 0, firstFunction);
firstButton.loadText(new FlxText(25, 4, 30, "error"), null);

...
tenthButton = new FlxButton(1, 209, tenthFunction);
tenthButton.loadText(new FlxText(25, 4, 30, "error"), null);
}
And here's where I add text to them:
Code: [Select]
...
if (_monsters.length >= 2)
{
secondButton.loadText(new FlxText(5, 4, 90, "Target " + _monsters[1].name), null);
add(secondButton);
}
else
{
secondButton.destroy();
}
...
if (_monsters.length >= 10)
{
tenthButton.loadText(new FlxText(5, 4, 90, "List more targets"), null);
add(tenthButton);
}
else
{

tenthButton.loadText(new FlxText(5, 4, 90, "Cancel"), null);
add(tenthButton);
}

That works for the other buttons, but fails on the tenth button. There's an obvious work-around, but I'm curious about why this is happening and a little worried that I have a mutant button that's going to cause bugs in the future.

Bandaro

  • Member
  • **
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Bit of an old topic, but I've recently had this same issue. Make sure to include a call to the FlxButton's update() method somewhere, as the label's x and y are set here rather than in the constructor.