0

I have a movie clip that I scaled by hand in the timeline.

I am now trying to get the WIDTH and HEIGHT with action script so I can load another movieClip into it and make it the same size.

However when I do the following code I can't position it correctly because the scale is WIDTH and HEIGHT displays the original size and not showing the scaled size cordinates. So when I place the new clip inside of it the I can't make it be the same WIDTH and HEIGHT as the rescaled clip;

ScaledMC.addChild(myMC);
myMC.x = - ScaledMC.width /2; //Because the MC registration is in the center

A work around could be some code to detect the x and y positions of the BOUNDARIES of the clip and where they are located on the stage.

Thanks for your time.

UPDATE: 4-25-12

I am posting full code of what I am trying to do and including FLA. When you click on the girl I need her to load into another movie clip. However the movie clip is scaled so when she gets loaded her position suddenly changes. I need it to look like she hasn't moved and stays in the same place.

import flash.geom.Rectangle;

var Girlx = Girl.x;
var Girly = Girl.y;

var b:Rectangle;
b = Room.ChalkBoard.getBounds(this);


trace(b);


Room.ChalkBoard.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

function fl_ClickToDrag(event:MouseEvent):void
{
    Room.ChalkBoard.startDrag();
}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

function fl_ReleaseToDrop(event:MouseEvent):void
{
    Room.ChalkBoard.stopDrag();
    b = Room.ChalkBoard.getBounds(this);
}



Girl.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    //Room.ChalkBoard.scaleX = 1;
   // Room.ChalkBoard.scaleY = 1;
    Room.ChalkBoard.addChild(Girl);


    // I NEED TO KNOW HOW TO SCALE GIRL BACK TO SAME SIZE
    // EXAMPLE:

Girl.scaleY = 1 + Room.ChalkBoard.scaleY;

Girl.scaleX = 1 + Room.ChalkBoard.scaleX;
Girl.x = Girlx - b.x; /// This formula works if Room is at scaleX is 1;
Girl.y = Girly - b.y;  /// This formula works if Room is at scaleY is 1;


}

HERE IS THE FLA: http://www.EdVizenor.com/Girl.fla

Papa De Beau
  • 3,744
  • 18
  • 79
  • 137

2 Answers2

1

If your problem is that you scale the movieclip and want to use the original dimensions (I think this is what you are saying) then you could try something like the following:

ScaledMC.addChild(myMC); 
myMC.x = - (ScaledMC.width/ScaledMC.scaleX) /2; 

Notice that I added in a factor for scaling of the movieclip object itself

M. Laing
  • 1,607
  • 11
  • 25
  • I will try it. Thanks alot. Also I scaled it in the timeline by hand. That was my first sentence of the post. perhaps I am using the wrong terminology. – Papa De Beau Apr 21 '12 at 01:51
  • Ohh ok. I wasn't sure what you meant but I understand now. So yes you are changing its scale property (there is both `scaleX` and `scaleY`). I edited my answer to remove the part asking how you scaled. – M. Laing Apr 21 '12 at 01:54
1

You can access the transformation Matrix that represents the object you've scaled with the IDE to work out how much you've scaled it. The key properties of Matrix that you want to look at are a for x-scale and d for y-scale.

Demo:

var matrix:Matrix = ScaledMC.transform.matrix;
trace(matrix.a, matrix.d);

You can then use the values to scaling your additional MovieClips, or whatever you need to do.

Bonus: Have a function:

function getScale(target:DisplayObject):Object
{
    var mtx:Matrix = target.transform.matrix;

    return {
        scaleX: mtx.a,
        scaleY: mtx.d
    }
}


// Get scaleX of ScaledMC.
trace(getScale(ScaledMC).scaleX);
Marty
  • 39,033
  • 19
  • 93
  • 162
  • Thanks Marty. I think my subject line is not clear. In the post I make my question more clear. I need to scale the movie clip called "Girl" and keep it in the same position in the movie clip she is in, when in reality she gets moved to inside another movie clip. But she stays in the same place. Best I can say is download the FLA above and run it and click on the girl. SHE MOVES and she is supposed to stay in the same place even though she was placed inside a scaled movie clip. – Papa De Beau Apr 26 '12 at 00:42
  • @PapaDeBeau Do you mean that when you scale the girl, she is moving away from what should be a fixed top-left position? If that's the case, your problem is purely related to the registration point you've allocated to that symbol not being exactly top-left. – Marty Apr 26 '12 at 00:44
  • Yes, she should remain fixed. I can keep her in the fixed position but the issue is because the clip she is loaded into has been scaled she thus gets scaled too and moves accordingly. The Scale is causing the issue. DEMO: http://edvizenor.com/Gril.html – Papa De Beau Apr 26 '12 at 00:46
  • @PapaDeBeau All I can suggest at this point is to rethink how you've structured the display tree in your project. – Marty Apr 26 '12 at 00:56
  • Thanks for your time tho. I believe its not an issue of tree or position. Its a SCALE issue. When I load the Girl mc into the Scaled movie clip she gets scaled too. I need her to go in but remain the same size. – Papa De Beau Apr 26 '12 at 01:04
  • @PapaDeBeau Yes, by display tree I am referring to how you've structured your rendering objects in terms of parent elements and the like, effecting child elements in ways you're not comfortable with. – Marty Apr 26 '12 at 01:10