Jump to content
Search Community

Find "key" labels before or after

martis test
Moderator Tag

Recommended Posts

Hey guys....

 

I have a Timeline with labels...., but only certain labels are "key" labels.

 

"Label_1", "Label_2", "Label_3", "Label_4", "Label_5"

 

I made an array with the "key" labels...

 

keyLabels = ["Label_1", "Label_3", "Label_5"];

 

What's the best way to find the before or after "key" label from the current label?

 

I am assuming its using getLabelsArray and seeing if the labels are in the key index or not...

 

Thanks!

Link to comment
Share on other sites

Yeah, there isn't anything in the GSAP API that will do that but like you said you could use the getLabelsArray and loop through it and look for matches in the key labels array.

 

I played around with using getLabelAfter to recursively see if the next label is in the key labels array.

 

Paste this code into an AS3 fla with access to the GreenSock com folder

 

import com.greensock.*;


var tl = new TimelineMax({paused:true});


tl.add("label1");
tl.add("key1", 1);
tl.add("label2", 2);
tl.add("label3", 3);
tl.add("key2", 4);




var keyLabels:Array = ["key1","key2"];


function getNextKeyLabel(current_label) {
var labelTime = tl.getLabelTime(current_label);
if (labelTime == -1) {
//passed in invalid label
return -1;
}
//find the next label
var nextLabel = tl.getLabelAfter(labelTime);
if (nextLabel) {
//search keyLabels for nextLabel
for (var i:int = 0; i < keyLabels.length; i++) {
if (keyLabels[i] == nextLabel) {
return nextLabel;
}
}
return getNextKeyLabel(nextLabel);
} else {
//no more labels
return -1;
}
}




trace("key after Label1 = " + getNextKeyLabel("label1"));  //key1
trace("key after Label2 = " + getNextKeyLabel("label2"));  //key2
trace("key after foo = " + getNextKeyLabel("foo"));  // -1
trace("key after key2 = " + getNextKeyLabel("key2"));  // -1

hopefully that helps you structure a function to find the key label before.

We have drastically reduced our Flash support and really only focus on bugs within the GSAP API (none to our knowledge) or questions surrounding basic usage.

  • Like 1
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...