Search code examples
loopspositionactionscript-2movieclipgsap

ActionScript 2 - Get MovieClips' initial position and save it for each mc for later target position


I am working on an animation in AS2 which requires that all text MovieClips (instance names starting with "txt_") will be manually placed initially on stage and I need to store their own initial placed positions (x,y) so they will be retrievable later when I want to animate them to these same final coordinates regardless of where they move around in the meantime.

So the following steps needed:

  1. All these text movieclips are placed on stage manually from library (not dynamically) matching their expected target keyframe end position (x,y) to get desired final screen layout.
  2. Then a frame script loops through all these MovieClip instances on stage before rendering them on stage and stores their initial (also future target) (mc.targetPosX or mc.targetPosY) positions.
  3. Then frame script also moves all of these MovieClip instances before rendering them on stage and moves/offsets them elsewhere on stage (eg. mc._x +=25px;) and hides them (eg. mc._alpha =0;)
  4. Finally by using a tween like Greensock I want to use their stored target end position to animate each of them to their stored final target position. (eg. TweenLite.to(mc, 1,{_alpha:100, _x:mc.targetPosX, ease:Quad.easeOut});)

I was able to create a loop to get "txt_" movieclips but then I don't know how to save their target positions with their instance and use them outside the loop afterwards. Thank you in advance, Attila


Solution

  • I don't know what problems do you have trying store some variables inside instances, but here my suggestions about proccess you described.

    First of all we have loop which do all thing you described at question. To do so we must have some list of you mc's or pattern to make this list dynamically. From you question i suppose that you use this kind of loop.

    for(var i=0, txtCount=10; i<txtCount; i++){
        textMc = this['txt_'+i];
        //do stuff
        ...
    }
    

    From here on your points.

    1. You already did it.

    2. Use loop described above to store current object properties inside his instance

      textMc.storedX=textMc._x;
      textMc.storedY=textMc._y;
      
    3. Here is same loop place object wherever you like

      textMc._x+=25;
      textMc._alpha=0;
      
    4. Finally right after that in the same loop use greensock.

      TweenLite.to(textMc, 1,{_alpha:100, _x:mc.storedX, ease:Quad.easeOut});
      

    That's it.