[fmx]text effect

I created an extra variable:


var startX = 100;

and changed a line in the onEnterFrame:


_root["char"+i]._x += ((((i - myArray.length/2)*spacing) - _root["char"+i]._x)/speed) + startX;

Hope you like it :slight_smile:

thank you, that is it!

if i can do for you something, let me know!!!

but, i wil ask 1 thing more, euh, 2 thing

  1. can you explain me the script, i will learn it
  2. where can i put an apha en can i create more line whith the same effect?

new code (including random alpha change):


var speed = 2;          
var pause = 2000;
var spacing = 10;
var startX = 100;
var myAlpha = 100;
var myText = "Virusdoder";

myArray = myText.split("");

for(i=0; i<myArray.length; i++){
	character = _root.attachMovie("myMC", "char"+i, i);
	character._x = i*10;
	character.myChar.text = myArray*;
}
function changeSpacing(){
	spacing = Math.random()*40 + 10;
	myAlpha = Math.random()*95 + 5;
}
_root.onEnterFrame = function(){
	for(i=0; i<myArray.length; i++){
		_root["char"+i]._x += ((((i - myArray.length/2)*spacing) - _root["char"+i]._x)/speed) + startX;
		_root["char"+i]._alpha += (myAlpha - _root["char"+i]._alpha)/speed;
	}
}
setInterval(changeSpacing,pause);

In order to work properly you also have to embed the font outline. Go into myMC and in the Properties panel of the textfield, click on Character. Make sure that the option ‘All Characters’ is ticked.

As for the explanation:


var myText = "Virusdoder";

This is the text that is to be animated


myArray = myText.split("");

This line breaks the variable myText into separate characters and puts them into an array.
In this case the resulting array is {v,i,r,u,s,d,o,d,e,r}


for(i=0; i<myArray.length; i++){
	character = _root.attachMovie("myMC", "char"+i, i);
	character._x = i*10;
	character.myChar.text = myArray*;
}

With this loop you place an instance of myMC on stage and give it a unique instancename and in it’s own level.
E.g. you get char0 on level 0, char1 at level 1 etc.

Note: to be able to use attachMovie() you need to export the mc for actionscript: rightclick on the mc in the library and choose Linkage. Then tick the option ‘Export for Actionscript’.

By assigning the attachMovie() to the variable ‘character’ I can set properties such as the _x and the content of the textfield within the loop by using e.g ‘character._x’.

Then the actual function:


function changeSpacing(){
	spacing = Math.random()*40 + 10;
	myAlpha = Math.random()*95 + 5;
}

This sets a variable called 'spacing to a random value. Math.random() generates a value between 0 and 1. By multiplying by 40 and then adding 10, you get a value between 10 and 50.
In the same way, myAlpha gets a value between 5 and 100.


_root.onEnterFrame = function(){
	for(i=0; i<myArray.length; i++){
		_root["char"+i]._x += ((((i - myArray.length/2)*spacing) - _root["char"+i]._x)/speed) + startX;
		_root["char"+i]._alpha += (myAlpha - _root["char"+i]._alpha)/speed;
	}
}

onEnterFrame means that this is executed at the framerate of the movie, in this case 24 times per second.
Again, there is a loop, in which every mc that was created with the attachMovie() command gets a new _x and _alpha.
This is actually based on the easing motion tutorial found here

the last part:


setInterval(changeSpacing,pause);

just says to execute the changeSpacing function with a time-interval of the amount of milliseconds specified by the variable ‘pause’.

I think that’s about it.

Just let me know if my explanation isn’t clear at any point. :slight_smile:

thank you very much.

i understand everything
when you have a problem, let me now

:wink:

Cheers.

…and the only problem I’m having is that I don’t have a Flash-related job. If you could help me with that… (-: