AS3: Positioning and Size problems in Sprites and MovieClips


Struggling with your Sprites or MovieClips which don’t seem to be placed in the right spot or be of the right size?

Don’t worry, if there’s something I’ve learned from Flash, it’s to distrust Flash’s own positioning and size properties.

Instead, use your own getters and setters and get your piece of mind.

import flash.display.Sprite;

public class MyCoolObject : Sprite {

private var posX:int;

private var posY:int;

private var posZ:int;

private var sHeight:int;

private var sWidth:int;

public function MyCoolObject() {

}

/* Getters and Setters */

public function set X(val:int) {  this.posX = val; }

public function get X():int { return this.posX; }

public function set Y(val:int) {  this.posY = val; }

public function get Y():int { return this.posY; }

public function set Z(val:int) {  this.posZ = val; }

public function get Z():int { return this.posZ; }

public function set Height(val:int) {  this.sHeight = val; }

public function get Height():int { return this.sHeight; }

public function set Width(val:int) {  this.sWidth = val; }

public function get Width():int { return this.sWidth; }

}

It’s a bit of overhead, but trust me, you’ll thank me later…

1 thought on “AS3: Positioning and Size problems in Sprites and MovieClips

  1. These are really wonderful ideas in about blogging.
    You have touched some pleasant factors here. Any way keep up wrinting.

Leave a comment