Jump to content
Search Community

Tweening Dynamically Created movieClips from Library

jemnon test
Moderator Tag

Recommended Posts

I having an issue with tweening the movie clips individually after they've been added to the stage.

 

essentially, i just want each movie clip to tween after they've been added to the stage.

 

here is my code:

 

import com.greensock.*;
import com.greensock.easing.*;

var mc:Number = 28;
var topPos:uint;
var arry:Array;
var hc:Array;
var tl:TimelineLite = new TimelineLite();

//trace(arry.length);

init();

function init():void {	
for(var i:int = 0; i		var b:MovieClip = new box_mc();
	b.x = (i % 7) * 49;
	b.y = int(i / 7) * 49;
	holder_mc.alpha = 0;
	holder_mc.addChild(;

	animateChildren(holder_mc);

	b.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
	b.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
	b.buttonMode = true;
	b.mouseChildren = false;
}
}

function animateChildren(holder_mc:MovieClip):void {
var arry:Array = new Array(holder_mc.numChildren);

trace(arry.length);

for(var n:int = 0; n < arry.length; n ++) {
	TweenMax.allTo(arry[n], 1, {alpha:1}, 0.3);
}
}

function onMouseOver(evt:MouseEvent):void {
var m:MovieClip = MovieClip(evt.target);

TweenLite.to(m, 1, {scaleX:1.5, scaleY:1.5});

topPos = holder_mc.numChildren - 1;
holder_mc.setChildIndex(m, topPos);
}

function onMouseOut(evt:MouseEvent):void {
var m:MovieClip = MovieClip(evt.target);
TweenLite.to(m, 1, {scaleX:1, scaleY:1});
}

 

thanks

Link to comment
Share on other sites

also, getting this error after publish,

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at com.greensock::TweenMax$/allTo()

at 1_fla::MainTimeline/animateChildren()

at 1_fla::MainTimeline/init()

at 1_fla::MainTimeline/frame1()

Link to comment
Share on other sites

hello jemmon,

 

there are a number of things that are messing up here:

 

the biggest problems are in here:

 

var arry:Array = new Array(holder_mc.numChildren);

trace(arry.length);

for(var n:int = 0; n

TweenMax.allTo(arry[n], 1, {alpha:1}, 0.3);

}

 

the whole point of allTo is so that you don't need to manually loop through an array... you just tell allTo what array to loop through.

i have a video here on allFrom which works in a similar fashion: http://bit.ly/f5qWol

 

so either kill the for loop, or just use the loop to call a bunch of TweenMax.to()s

 

next your arry Array doesn't have anything in it.

in your loop add

trace(arry[n])

 

I don't think anything will trace.

 

what you want to do is define your arry Array outside of any functions.

in the init function add each b to arry via

 

arry.push(B)

 

this will put each b into arry so that TweenMax.allTo(arry, 1, {alpha:1}) will work inside animateChildren()

 

lastly

 

the init function is calling animateChildren 28 times because it is inside a loop

furthermore animateChildren is hoping to also loop through all the items in holder_mc.

So 28 times you are calling a function that is trying to animate everything in holder_mc.

so inside the init() function make sure animateChildren doesn't run until all objects are on the stage by moving animateChildren() outside the init() loop.

 

also, each b needs to have it's alpha set to 0 initially so that your tween bringing the alpha to 1 actually has something to do.

 

 

ultimately your code should look something like this (i can't guarantee it will work)

 

var arry:Array = new Array();

function init():void {   
  for(var i:int = 0; i      var b:MovieClip = new box_mc();
     b.x = (i % 7) * 49;
     b.y = int(i / 7) * 49;

//make each b alpha 0       
     b.alpha = 0;

     holder_mc.alpha = 0;
     holder_mc.addChild(;

// add each b to the arry Array
     arry.push(;


     b.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
     b.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
     b.buttonMode = true;
     b.mouseChildren = false;
  }

//call animateChildren() outside the loop
  animateChildren();
}



function animateChildren():void {
//clean up animateChildren by using a single allTo() : no need for a loop

// oh an make sure the holder can be seen

holder_mc.alpha = 1

  TweenMax.allTo(arry, 1, {alpha:1}, 0.3);
  }
}

 

you were very close! hopefully this explanation brings you closer to making something sweet.

 

Carl

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...