ActionScript 3.0 add border to movie clipe
I had created the script below but the cordinate is not working right. please see my scripts and let me know what is wrong with my scripts. thanks
/*mcc is the Instance name*/
var myMovieClip:Sprite = new Sprite();
trace("x" + mcc.x + "y" + mcc.y + "width" + mcc.width);
myMovieClip.graphics.lineStyle( 1, 0xFF0000 );
myMovieClip开发者_如何学运维.graphics.drawRect( 0, 0, mcc.width+1, mcc.height+1 );
myMovieClip.graphics.endFill();
myMovieClip.x = -(mcc.x/2);
myMovieClip.y = -(mcc.y/2);
mcc.addChild(myMovieClip);
would need to know more about mcc
looks like we're assuming that mcc has the content centered instead of the top right corner of mcc being at [0,0]
Try using the getBounds method instead.
something like this... though I haven't tested it
var bounds:Rectangle = mcc.getBounds(this)
myMovieClip.graphics.drawRect(
bounds.left-border/2, bounds.top-border/2,
bounds.width+border, bounds.height+border
);
myMovieClip.x = (mcc.x);
myMovieClip.y = (mcc.y);
mcc.addChild(myMovieClip);
thank you, it is working now, i used the getBounds and set the myMovieClip.x = (0); . It doesn't make sense but it works good now.
Anyway, the mcc could be anything, event rotate angle too.
var border=1;
var myMovieClip:Sprite = new Sprite();
myMovieClip.graphics.lineStyle( border, 0xFF0000 );
trace("getbound on mcc" + mcc.getBounds(mcc));
trace("parser" + mcc.getBounds(mcc).y)
trace("getbound on this" + mcc.getBounds(this));
trace("Other x " + mcc.x + " y " + mcc.y + " width " + mcc.width+ " height " + mcc.height);
var bounds =mcc.getBounds(mcc)
myMovieClip.graphics.drawRect(bounds.left-border/2, bounds.top/2,bounds.width+border, bounds.height+border);
myMovieClip.graphics.endFill();
myMovieClip.x = (0);
myMovieClip.y = (bounds.y)/2;
mcc.addChild(myMovieClip);
trace("New bound" + mcc.getBounds(mcc));
精彩评论