Jump to content
GreenSock

eco_bach

SplitTextField but picking random character

Recommended Posts

I'd like to apply the SplitTextField effect to characters in a textfield but instead of the effect being applied in a sequential manner, I want the characters to be chosen at random. Can anyone show me how I would do this?

Link to comment
Share on other sites

You could randomize the splitText.textFields Array by passing it into shuffling / randomizing function like shown here: http://www.snorkl.tv/2011/09/actionscript-3-shuffle-array-and-loop-through-children/#more-1417

 

But I'd probably take an easier approach with the same end result.

When you loop through your Array of textfields just create tweens that have randomized delays. So all the tweens will virtually be created in order of the Array, but they will run at random times.

import com.greensock.text.SplitTextField;import com.greensock.*;


var stf:SplitTextField = new SplitTextField(myText, "characters");
var textCount:int = stf.textFields.length;
for(var i:int = 0; i < textCount; i++){
TweenLite.to(stf.textFields[i], 1, {y:100, alpha:0, delay:Math.random() * 3})
}

If you want to add each tween to TimelineLIte so you can pause(), reverse(), restart() etc just randomize the position parameter

 

import com.greensock.text.SplitTextField;
import com.greensock.*;


var stf:SplitTextField = new SplitTextField(myText, "characters");
var textCount:int = stf.textFields.length;
var timeline:TimelineLite = new TimelineLite();
for(var i:int = 0; i < textCount; i++){
timeline.to(stf.textFields[i], 1, {y:100, alpha:0}, Math.random() * 3)
}

Both code blocks above can be pasted into an FLA with a TextField with instance name of myText.

 

Does that help?

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