# Tweening Dynamically attached MCs

**URL:** <https://forum.kirupa.com/t/tweening-dynamically-attached-mcs/185348>\
**Category:** flash\
**Created:** [April 12, 2006, 5:46pm UTC](https://forum.kirupa.com/t/tweening-dynamically-attached-mcs/185348 "2006-04-12T17:46:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geminian1](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Geminian1](https://forum.kirupa.com/u/Geminian1)\
**Post date:** [April 12, 2006, 5:46pm UTC](https://forum.kirupa.com/t/tweening-dynamically-attached-mcs/185348/1 "2006-04-12T17:46:21Z")

</div>

Hi guys.  
Need some help with a picture transition I am building using borrowed code from various tutorials. I am trying to make a grid with a dynamically attached clip(ball), use the grid as a mask for a picture(pic) and tween it forward on the press of a button (red):

```auto

import mx.transitions.easing.*;
import mx.transitions.Tween;
 
exp = function(mymc){
 new Tween(mymc,"_xscale",Strong.easeIn,mymc._xscale,300,3,true);
 new Tween(mymc,"_yscale",Strong.easeIn,mymc._yscale,300,3,true);
}
 
var PH = _root.createEmptyMovieClip("PH_mc", 0);
var ball:MovieClip;
var depth = 0;
 
for (var i=0; i < 100; i++) {
 for(var j=0;j< 100; j++){
    ball = PH.attachMovie("ball", "ball_"+ i + "_" + j,depth++); 
    ball._x = i*ball._width;
    ball._y = j*ball._height;
    }
}
red.onRelease = function(){
exp(ball);
}
pic.setMask(PH);
 

```

My problem is that I cannot get the grid to tween forward on pressing red. I have tried various other ways to call function exp with no success, although I have noticed that:

```auto

red.onRelease = function(){
exp(PH);
}

```

successfully tweens the container clip for the grid. Furthermore, I have noticed Flash 8 takes some time before testing the movie. Is my code inefficient?

Many thanks for any help.

Geminian1

---

<div class="post-metadata">

**Author:** ![Geminian1](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@Geminian1](https://forum.kirupa.com/u/Geminian1)\
**Post date:** [April 19, 2006, 8:21pm UTC](https://forum.kirupa.com/t/tweening-dynamically-attached-mcs/185348/2 "2006-04-19T20:21:48Z")

</div>

Hi guys,  
Did not get any reply unfortunately, but eventually trawled everywhere, huffed, puffed and stumbled on a formula courtesy [Nuno Mira](http://www.nunomira.com/blog/?p=15); I made the ball clip with my picture and attached the following code to it’s first frame:

```auto

import mx.transitions.Tween;
import mx.transitions.easing.*;
 
var x0:Number = 0; // x position (upper left corner)
var y0:Number = 0; // y position (upper left corner)
var nr:Number = 12; // number rows
var nc:Number = 12; // number colums
var vd:Number = 50; // vertical distance between the mcs
var hd:Number = 50; // horizontal distance between the mcs
var s:Number = 0; // variable to hold names and depths
 
this.createEmptyMovieClip("pic",0);
 
for (var i = 1; i <= nr; i++) {
 for (var j = 1; j <= nc; j++) {
  s++;
  var mc = pic.attachMovie("square", "square" + s, s);
  mc._x = x0 + hd * (j - 1);
  mc._y = y0 + vd * (i - 1);
  new Tween(mc,"_xscale",Strong.easeInOut,mc._xscale,300,2,true);
  new Tween(mc,"_yscale",Strong.easeInOut,mc._yscale,300,2,true);
 }
}
this.setMask(pic);

```

I then dynamically attached the ball clip to the root timeline by pressing the red button:

```auto

red.onRelease = function(){
 _root.attachMovie("ball","ball",0);
 
}

```

Hope someone finds this useful.

Geminian1

---

<div class="post-metadata">

**Author:** ![joran420](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joran420/32/2329_2.png) [@joran420](https://forum.kirupa.com/u/joran420)\
**Post date:** [April 19, 2006, 11:48pm UTC](https://forum.kirupa.com/t/tweening-dynamically-attached-mcs/185348/3 "2006-04-19T23:48:00Z")

</div>

I think that you prolly wanna use a depth other than 0…
