错误使用数组更改movieclip的x和y位置

时间:2013-10-19 08:35:02

标签: arrays actionscript-3 movieclip

我正在尝试使用Action Script 3.0创建一个程序,我单击一个元素,单击另一个元素,第一个元素转到第二个元素。

这是我的代码:

import flash.display.MovieClip;
import flash.display.SimpleButton;
import  flash.display.MovieClip;
import  flash.events.MouseEvent;

stop();

var Plchange:MovieClip;
var As:Array = new Array(A1,A2,A3,A4,A5,A6,A7,A8,A9);
var Bs:Array = new Array(B1,B2,B3,B4,B5,B6,B7,B8,B9);
var Cs:Array =new Array(C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12);
var Cs1:Array=new Array(C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24);

for ( var i:int =0; i<=8 ;i++)
{   
As[i].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ gotoPlace(me, As[i])});
Bs[i].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ gotoPlace(me, Bs[i])});


}
for ( var Y:int =0; i<=12 ;Y++)
{   
Cs[Y].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ Set(me, Cs[Y])});
Cs1[Y].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ Set(me,      Cs1[Y])});
}
function gotoPlace(event:MouseEvent, boing:MovieClip)
{
boing = Plchange;
}
function Set(event:MouseEvent, clip:MovieClip)
{
Plchange.x = clip.x;
Plchange.y = clip.y;
}

我收到了一个错误:

  

TypeError:错误#1010:术语未定义且没有属性。   在NineMen_fla :: MainTimeline / frame1()

我哪里错了?请告诉我。

1 个答案:

答案 0 :(得分:0)

首先,在gotoPlace中,您应该输入Plchange = boing;,而不是相反。其次,您必须检查Plchange是否在函数Set()内分配了值。像这样:

var Plchange:MovieClip=null;
function gotoPlace(event:MouseEvent, boing:MovieClip)
{
    Plchange = boing;
}
function Set(event:MouseEvent, clip:MovieClip)
{
    if (!Plchange) return; // Plchange is not assigned
    Plchange.x = clip.x;
    Plchange.y = clip.y;
}