Action Script 3.0引用多个数组

时间:2013-08-07 05:21:44

标签: actionscript-3

我正在尝试在Flash cs6(Actionscript 3.0)中创建一个拼图游戏,这是我的代码:

import flash.events.Event;
import flash.events.MouseEvent;

addEventListener(Event.ENTER_FRAME,onenter);
stop();

function pickupObject(event:MouseEvent):void
{
    event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
    event.target.stopDrag();
}
function dropTarg(event:MouseEvent):void
{
    event.target.stopDrag(x,y);
}

function onenter(event:Event)
{

    var pieces = [p1,p2,p3,p4,p5,p6];
    var targets = [target1,target2,target3,target4,target5,target6]
    var targ = [p1.targ1,p2.targ2,p3.targ3,p4.targ4,p5.targ5,p6.targ6]
    var xcoord = [241.00,374.40,529.85]
    var ycoord = [224.65,224.65,224.65]

    for each (var i in pieces)
    {
        i.buttonMode = true;
        i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
        i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
            if (targets[i].hitTestObject(i.targ[i]))
            {

            //i.removeEventListener(MouseEvent.MOUSE_UP,dropObject);
            i.x = xcoord[i];
            i.y = ycoord[i];
            //i.addEventListener(MouseEvent.MOUSE_UP,dropObject);
            }
}
}

我想要实现的基本上是,如果用户点击说p1(此对象在其图层中有另一个称为targ)并且targ命中相应的目标,那么该对象将在x,y坐标处捕捉到播放

我得到的错误是 TypeError:错误#1010:术语未定义且没有属性。     在JigSawWithArrays_fla :: MainTimeline / onenter()

这让我相信我没有正确引用/访问数组。

这可行吗?我是Flash cs6的新手,并希望得到一些指导。

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试代替每个

for, for each difference

for (var i:int = 0; i < pieces.length; i++) {

   var piece:MovieClip = pieces[i] as MovieClip;
   piece.buttonMode = true;
   piece.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
   piece.addEventListener(MouseEvent.MOUSE_UP, dropObject);

   if (targets[i].hitTestObject(targ[i]))
   {
        piece.x = xcoord[i];
        piece.y = ycoord[i];
   }
}