# Scale MC and center over child

**URL:** <https://forum.kirupa.com/t/scale-mc-and-center-over-child/311940>\
**Category:** flash\
**Created:** [July 20, 2010, 9:41pm UTC](https://forum.kirupa.com/t/scale-mc-and-center-over-child/311940 "2010-07-20T21:41:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshgage](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@joshgage](https://forum.kirupa.com/u/joshgage)\
**Post date:** [July 20, 2010, 9:41pm UTC](https://forum.kirupa.com/t/scale-mc-and-center-over-child/311940/1 "2010-07-20T21:41:59Z")

</div>

I have a movie clip of all counties in the state of Montana (_ **allcnt\_mc** _). Within \*\*\*allcnt\_mc \*\*\*there are individual movie clips specific to each county with name equal to the county’s name. When clicking on a county, I’d like to zoom to that county and center the stage on it. I’ve added event listeners to all counties through querying an xml table that has demographic info I am calling into dynamic text boxes. Here is the code I have thus far to load the xml and add the listeners to the county movie clips.

```auto
//load xml
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("cntydat.xml"));
function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    createListeners();
    }

//create listeners for all mc's and designate functions
function createListeners():void{
for(var i:uint=0;i<xmlData.row.NAME.length();i++){
var mc:MovieClip = MovieClip(allcnt_mc.getChildByName(xmlData.row.NAME*));
mc.ivar = i;
mc.addEventListener(MouseEvent.MOUSE_OVER,zoomin);

```

I’ve also specified a functions on CLICK and MOUSE\_OUT called zoomin and zoomout.

I’d like zoom in to zoom to the extent of the county movie clip i’ve clicked on. To create the effect of zooming on the whole state, I’ll scaleX and scaleY the _ **allcnt\_mc** _.

Where I need help is making the extent of the zoom proportional to the dimensions of the child movie clip I’ve clicked on and centering the stage over the county I’ve called on. For an example of how I’ve been calling on the counties and changing their color on MOUSE\_OVER, I’ve been using this function

```auto
function colchange(e:Event):void{
var ct:ColorTransform=e.currentTarget.transform.colorTransform;
ct.color=overColor;
e.currentTarget.transform.colorTransform=ct
}

```

To accomplish the effect I am going after, I imagine I’ll create a CLICK event that scales the X and Y of \*\*\*allcnt\_mc\*\*\*and make that proportional to _ **e.currentTarget** _ and also moves the whole _ **allcnt\_mc** _, centering it over the _ **e.currentTarget** _. Another click would reverse the process, scaling _ **allcnt\_mc** _ back to 1 and centering over _ **allcnt\_mc** _. I am just missing some action that would call on the geometry/coordinates of the _ **e.currentTarget** _.

If anyone could help move me in the right direction, I’d really appreciate it.

Thanks so much in advance,

Josh
