Attaching a animation to a movie clip and calling it later

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jsavagedesign
    New Member
    • Jun 2007
    • 17

    Attaching a animation to a movie clip and calling it later

    This is a project I have been working on lately and I keep running into problems.
    The idea is to be able to attaching an animation to a movie clip and call it later. Or multiple animation at once.

    example:
    on the stage you have a black box called: myClip
    in actionscript you type:
    growClip = grow(myClip);
    spinClip = spin(myClip);

    now when you call:
    growClip.run();
    spinClip.run();
    myClip will grow and spin.

    These function are ran with setinterval but when I do this myClip only spins.

    the function grow looks like this:
    Code:
    grow = function(mc,opts){
    	//opts == object containing required vars
    	opts.dir = (opts.dir > 0 || opts.dir == 0)?1:-1;
    	id=random(10000);
    	
    	mc["attach_animation"+id] = {}
    	co = mc["attach_animation"+id];
    	co.grow = {}
    	//Start: effect creation
    		co.grow.run = function(){
    			mc._xscale = mc._yscale = (opts.dir > 0)?0:100;
    			co.grow.growID = setInterval(co.grow.effect,5);
    		};
    		co.grow.kill = function(){
    			if(mc._xscale < 1) mc._visible = false;
    			mc._xscale = mc._yscale = 100;
    			
    			clearInterval(co.grow.growID);
    			delete co.grow;
    			trace("motion complete");
    		};
    		co.grow.effect = function(){
    			mc._xscale += opts.dir; 
    			mc._yscale = mc._xscale;
    			if(mc._xscale < 1 || mc._xscale > 100){
    				co.grow.kill();
    			}
    		};
    		co.grow.growID = 0;
    		
    	//END: effect creation
    	return co.grow;
    }
    
    growthis = grow(myClip,{dir:1});
    shrinkthis = grow(myClip,{dir:-1});
    growthis.run();
    The idea for the above code is from Adobe Spry framework

    Does setInterval cancel if they are applied together?
  • jsavagedesign
    New Member
    • Jun 2007
    • 17

    #2
    Well,

    This is depressing because I have found that everything I was trying to do has already been done for you by Adobe (and of course done better).

    I guess I am answering my own question here.
    If anyone cares all you have to do is:

    Code:
    //your movie clip is named "myClip"
    
    import mx.transitions.*;
    import mx.transitions.easing.*;
    TransitionManager.start(myClip, {type:Zoom, direction:Transition.IN, duration:2, easing:Elastic.easeOut});
    
    //or
    
    grow = new new TransitionManager(myClip);
    grow.startTransition({type:Zoom, direction:Transition.IN, duration:2, easing:Elastic.easeOut});
    
    /*
    There are lots of these with differant easing just search "TransitionManager" in the flash Help under "Components Language Reference" book
    */
    
    -J

    Comment

    Working...