Jump to content
Search Community

create TimelineLite objects with a for loop

bonassus test
Moderator Tag

Recommended Posts

Im trying to create 8 TimelineLite objects with a for loop calling myFunction which creates them. I'm getting this Error :

1078: Label must be a simple identifier.

on this line:

timelineArray[number]:TimelineLite = new TimelineLite();

Is the syntax wrong?

 

var   timeline1:TimelineLite;
var	timeline2:TimelineLite;
var	timeline3:TimelineLite;
var	timeline4:TimelineLite;
var	timeline5:TimelineLite;
var	timeline6:TimelineLite;
var	timeline7:TimelineLite;
var	timeline8:TimelineLite;

var timelineArray:Array;

timelineArray = new Array(timeline1,timeline2,timeline3,timeline4,timeline5,timeline6,timeline7,timeline8);

for(var i = 0; i < 8; i++){
myFunction(i);
}

function myFunction(number){
var number;
timelineArray[number]:TimelineLite = new TimelineLite();
timelineArray[number].insertMultiple([
TweenMax.to(object1,1{scale:1,ease:Back.easeOut}),
TweenMax.to(object2,1,{scale:1,ease:Back.easeOut}),
], 0, TweenAlign.START, 0.3);
}

Link to comment
Share on other sites

There were a few syntax errors in there. The following code will not throw any errors and if you have movieclips called object1, and object2 on the stage. they will appear to grow once.

 

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

var   timeline1:TimelineLite;
var   timeline2:TimelineLite;
var   timeline3:TimelineLite;
var   timeline4:TimelineLite;
var   timeline5:TimelineLite;
var   timeline6:TimelineLite;
var   timeline7:TimelineLite;
var   timeline8:TimelineLite;

var timelineArray:Array;

timelineArray = new Array(timeline1,timeline2,timeline3,timeline4,timeline5,timeline6,timeline7,timeline8);

for(var i = 0; i myFunction(i);
}

function myFunction(number){
timelineArray[number] = new TimelineLite();
timelineArray[number].insertMultiple([
TweenMax.to(object1,1, {scaleY:2,ease:Back.easeOut}),
TweenMax.to(object2,1,{scaleX:2,ease:Back.easeOut})
], 0, TweenAlign.START, 0.3);
}

 

What you are doing here is creating 8 timelines that all tell the same 2 objects to change the same property on each clip all at the same time.

 

here are some of the thing i fixed:

 

function myFunction(number){

var number; doesn't do anything

timelineArray[number]:TimelineLite kill that = new TimelineLite();

timelineArray[number].insertMultiple([

TweenMax.to(object1,1{scale there is no scale property, use scaleX and or scaleY :1,ease:Back.easeOut}),

TweenMax.to(object2,1,{scale:1,ease:Back.easeOut}),

] hard bracket ] in the wrong place (see my code), 0, TweenAlign.START, 0.3);

}

 

It is a little tricky keeping track of the ()[] when using insertMultiple. But once you do it right a few times it comes natural.

since you are using a loop, you could probably avoid declaring all the timelines at the top and manually inserting them into your array.

Perhaps you can explain what you are trying to accomplish and someone can help you optimize your code.

 

Keep at it.

 

Carl

Link to comment
Share on other sites

Thanks Carl.

I appreciate your help. I am new at programing. My example was confusing because i over simplified it. the two objects I was controlling in the example are actually arrays of objects themselves. The scale property is a plugin. it's working now and your you help made me realize that I don't need that var number. I thought I had to capture that value in a var. Thanks for the advice about declaring the timelines with the for loop I guess I can just do it all in one place?

thanks again.

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...