Page 1 of 1

Actionscript 3: Class extending MovieClip in odd position

Posted: Sat May 21, 2011 11:38 pm
by Chalks
Hope there are some AS3 folks here. I just picked up flash a week ago, and I've been having a blast with it. This is the first problem I've run across that has proved un-googlable (or maybe my google-fu is just weak). Anyways... I would love if someone could take a look at the code below. When you do, you'll see that the movieclip should obviously be at position (0, 0) on the stage. However it appears at (25, 5)! if I leave in the original "this.x = xx;", then it appears at (50, 5). If I also leave in "this.y=yy;" then it appears at (50, 10).

Any ideas what's happening? I feel like I'm doing something extremely dumb.

Thanks!

Code: Select all

// actionscript in frame 1 that creates an instance of my class
     var button:Btn = new Btn(showUpgrade, 25, 5, "Show", true, 5);
     addChild(button);
     trace(button.x.toString()); // prints 0 

Code: Select all

package  {
// imports here
public class Btn extends MovieClip {
     // global vars here
     public function Btn(cback:Function=null, xx:Number=0, yy:Number=0,  lbl:String="Button", manualButton:Boolean=false, wdth:Number=0,  hght:Number=0) {
         trace(this.x.toString());  // prints 0
         this.x = 0;
         trace(this.x.toString());  // prints 0
         this.y = 0;
         // other irrelevant code below
    }
}
}

Re: Actionscript 3: Class extending MovieClip in odd positio

Posted: Tue May 24, 2011 1:26 pm
by Jade
Make sure your graphic is at position 0,0 on the stage inside of the movie clip. When you re-position a movie clip it's done relative to where it is inside of the movieClip object.