所以,我试图让一些电影剪辑跟随它的前身,并让最后一个跟随鼠标。问题是我是从代码而不是使用界面创建它们,而且由于我不是专家,我无法让它们工作。
我在库中只有一个 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 变量添加它们的位置。
另外,我试图让它表现得更像一条小路,所以如果我向上移动,字母会落后于我;如果我向左移动,字母将滞后于我的右侧,但我认为按照我目前的方法,它们要么 A)一起移动到同一个位置,要么 B)总是挂在光标的左侧。
感谢您提供任何可能的帮助。