我正在为我的3D旋转木马项目工作..我的问题是当itemArray中的movieclip被点击它应该根据filesNames数组加载正确的swf ..但它没有..我已经运行了通过脚本,发现sortOn(“y”)是引起的...我知道它应该在那里为旋转木马正确旋转..有人请帮助我...
var centerX:Number = stage.stageWidth / 2;
var centerY:Number = stage.stageHeight / 2;
var radiusX:Number = 180;
var radiusY:Number = 50;
var speed:Number = 0.1;
var minSpeed:Number = -0.15;
var maxSpeed:Number = 0.15;
var rangeSpeed:Number = maxSpeed - minSpeed;
var minY:Number = centerY - radiusY;
var maxY:Number = centerY + radiusY;
var rangeY:Number = maxY - minY;
var minScale:Number = 0.5;
var maxScale:Number = 1.2;
var rangeScale:Number = maxScale - minScale;
var my_loader:Loader = new Loader();
var itemArray:Array =[perkhidmatan, misi, tentang, members];
var fileNames : Array = ["perkhidmatan.swf", "misi.swf", "tentang.swf","members.swf",];
var canvas:MovieClip = new MovieClip();
addChild(canvas);
for (var i:Number = 0; i < itemArray.length; i++)
{
canvas.addChild(itemArray[i]);
itemArray[i].buttonMode = true;
itemArray[i].addEventListener(MouseEvent.CLICK, goToURL);
itemArray[i].itemAngle = Math.PI * 2 / itemArray.length * i;
itemArray[i].addEventListener(Event.ENTER_FRAME, animate);
}
function goToURL(e:MouseEvent):void {
for (var i:int = 0; i < itemArray.length; i++) {
if (e.currentTarget == itemArray[i]) {
my_loader.load(new URLRequest(fileNames[i]));
trace(fileNames[i]);
trace(my_loader);
addChild(my_loader);
itemArray[i].mouseEnabled = false;
itemArray[i].alpha = 0.5;
} else {
itemArray[i].mouseEnabled = true;
itemArray[i].alpha = 1;
}
}
}
function animate(e:Event):void
{
speed = mouseX / stage.stageWidth * rangeSpeed + minSpeed;
e.currentTarget.x = Math.cos(e.currentTarget.itemAngle) * radiusX + centerX;
e.currentTarget.y = Math.sin(e.currentTarget.itemAngle) * radiusY + centerY;
e.currentTarget.itemAngle += speed;
itemArray.sortOn("y");
for(var i:Number = 0; i < itemArray.length; i++)
{
canvas.setChildIndex(itemArray[i], i);
var pct:Number = (itemArray[i].y - minY) / rangeY;
var scale:Number = pct * rangeScale + minScale;
itemArray[i].scaleX = itemArray[i].scaleY = scale;
}
}
答案 0 :(得分:0)
如果问题是您的阵列未正确排序,请尝试使用itemArray.sortOn("y", Array.NUMERIC)
。
看来您的实际问题是您正在对一个数组进行排序,然后尝试使用该数组中的索引来访问另一个数组中的元素。
您应该以{{1}}实例名称提供项目,而不是按索引查找项目,您可以取消包含文件名的数组,并执行类似的操作:
itemArray