Search code examples
actionscript-3transitionaddchildtweener

addChild with effects, such as Tweener OR transitions


Is it possible to use addChild with tweener or transitions, I mean not only bring the child to the stage, but at the same time make this animated?

especially in this type of code:

var background=new MovieClip  ;
var g:Graphics=background.graphics;
g.lineStyle(2, 0xFFFFFF);
var mat:Matrix;
var alphas:Array;
var ratios:Array;

mat=new Matrix();
alphas=[1,1,1];
ratios=[0,150,255];

mat.createGradientBox(30,19,toRad(-90));
g.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,mat);
g.drawRoundRect(2, 2, 30, 19, 5);
addChild(background);

Solution

  • In you movieclip object add eventlistener in the constructor. I mean

    package
    {
    import flash.display.MovieClip;
    import flash.events.Event;
    
      public class Some extends MovieClip
      {
        public function Some()
        {
          addEventListener(Event.ADDED_TO_STAGE, Added);
        }
        public function Added(e.Event):void
        {
          removeEventListener(Event.ADDED_TO_STAGE, Added);
          addEventListener(Event.ENTER_FRAME, DrawLoop);
        }
        public function Added(e.Event):void
        {
          //here make your showing up effects
        }
      }
    }
    

    and of course then you need to create your object as extended class

    var background:Some = new Some()
    //your stuff here
    addChild(background);