I'm trying to program a main menu with buttons in it. I have a class called MenuAchievementsButton, and in its constructor, it is passed down the stage width and stage height from the document class. When I trace this, it is the correct width/ height.
I'm trying to get the button's height to be the stage height / 100. I've tried doing this.height = stage height / 100, but whenever I do so, it gives me 4x the result I want, even when I enter in a number like 5 and measure the px in Photoshop.
Also, when I try to move the object, a similar problem exists: When I want it to be, say, 20px right and down, it turns out to be 80px left and down.
Any help is appreciated!
package menus {
import flash.display.MovieClip;
public class MenuAchievementsButton extends MovieClip {
private var _stageWidth, _stageHeight:int;
public function MenuAchievementsButton(stageWidth:int, stageHeight:int) {
_stageWidth = stageWidth;
_stageHeight = stageHeight;
alpha = 1;
rescaleMe();
repositionMe();
trace(_stageWidth, _stageHeight);
}
private function rescaleMe():void {
var oldWidth = this.width;
var oldHeight = this.height;
this.height = _stageHeight/100;
this.width = (this.height * oldWidth) / oldHeight;
}
private function repositionMe():void {
this.x = 20;
this.y = 20;
trace(x,y,width,height);
trace("Stage height is: ",_stageHeight,"Stage height divided by 100 is: ", _stageHeight/100, "And the object's height, which should be stageheight / 100 is:", this.height);
//Gives Stage height is: 800 Stage height divided by 100 is: 8 And the object's height, which should be stageheight / 100 is: 8
//Actually, though, it's 36px!
}
}
}