Итак, я пытаюсь заставить несколько видеоклипов следовать за его предшественником, а последний - за мышью. Проблема в том, что я создаю их из кода, а не использую интерфейс, и, поскольку я не эксперт, я не могу заставить их работать.
Все, что у меня есть в библиотеке, это MovieClip(linkage:"LETRA"), который содержит textField внутри(имя экземпляра:"myTextField").
Вот что у меня есть:
import flashx.textLayout.operations.MoveChildrenOperation;
import flash.display.MovieClip;
import flash.events.Event;
//this are the letters that will be following the mouse
var phrase:Array = ["H","a","c","e","r"," ","u","n"," ","p","u","e","n","t","e"];
//variable to spread them instead of creating them one of top of each other
var posXLetter:Number = 0;
//looping through my array
for (var i:Number = 0; i < phrase.length; i++)
{
//create an instance of the LETRA movieclip which contains a text field inside
var newLetter:MovieClip = new LETRA();
//assing a letter to that text field matching the position of the phrase array
newLetter.myTextField.text = phrase[i];
//assign X position to the letter I'm going to add
newLetter.x = posXLetter;
//add properties for storing the letter position
var distx:Number = 0;
var disty:Number = 0;
//add the listener and the function which will move each letter
newLetter.addEventListener(Event.ENTER_FRAME, moveLetter);
function moveLetter(e:Event){
distx = newLetter.x - mouseX;
disty = newLetter.y - mouseY;
newLetter.x -= distx / 10;
newLetter.y -= disty / 10;
}
//add each letter to the stage
stage.addChild(newLetter);
//increment the next letter's x position
posXLetter += 9;
}
С этим кодом только одна буква следует за мышью («E»), а остальные остаются там, где я их добавил, используя addChild и переменную posXLetter.
Кроме того, я пытаюсь заставить его вести себя как след, поэтому, если я буду двигаться вверх, буквы будут отставать подо мной; если я двинусь влево, буквы будут отставать вправо, но я думаю, что при моем нынешнем подходе они будут либо А) двигаться все вместе в одно и то же место, либо Б) всегда будут висеть слева от курсора.
Спасибо за любую возможную помощь.