I’m having some problems applying a new matrix to a movieclip in AS3. Everytime I apply a new one to an Movie Clip it gets reset. For example:
trace(MC.transform.matrix.tx, MC.x, MC.y);//FIRST
MC.transform.matrix = new Matrix(1, 0, 0, 1, -(MC.width/2), -(MC.height/2));
trace(MC.transform.matrix.tx, MC.x, MC.y);//SECOND
func2();
function func2():void
{
trace(MC.transform.matrix.tx, MC.x, MC.y);//THIRD
}
heres what happens:
First trace outputs MC’s original matrix
Second trace outputs the MC’s new matrix that I made (all good so far)
Thrid trace outputs MC’s original matrix
Info:
MC is a movieclip placed on the stage with the instance name MC
Using Flash CS3
Any ideas why this is happening?
Thanks guys!
Edit—
Sorry here’s the code
import flash.geom.Matrix;
var MC:MovieClip = new MovieClip();
MC.graphics.beginFill(0xFFFFFF, alpha);
MC.graphics.lineStyle(0.5, 0x000000);
MC.graphics.drawRect(0, 0, 100, 100);
addChild(MC);
MC.x = stage.x;
MC.y = stage.y;
stage.addEventListener(KeyboardEvent.KEY_DOWN, func);
function func(e:KeyboardEvent):void
{
trace(MC.transform.matrix.tx, MC.x, MC.y);
setRegistrationPoint(MC, MC.width/2, MC.height/2, true);
trace(MC.transform.matrix.tx, MC.x, MC.y);
MC.x = stage.x;
MC.y = stage.y;
func2();
}
function func2():void
{
trace(MC.transform.matrix.tx, MC.x, MC.y);
}
function setRegistrationPoint(s:Sprite, regx:Number, regy:Number, showRegistration:Boolean )
{
//translate movieclip
s.transform.matrix = new Matrix(1, 0, 0, 1, -regx, -regy);
//trace("hello");
//registration point.
if (showRegistration)
{
var mark:Sprite = new Sprite();
mark.graphics.lineStyle(1, 0x000000);
mark.graphics.moveTo(-5, -5);
mark.graphics.lineTo(5, 5);
mark.graphics.moveTo(-5, 5);
mark.graphics.lineTo(5, -5);
s.parent.addChild(mark);
}
}