AS3这段代码有什么问题?

时间:2012-03-08 10:24:50

标签: actionscript-3

大多数情况都有效,即使出现错误,它仍然可以继续工作:

// Make PostItNote MC draggable and keep ON TOP
mcMXredBox.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);

var q:int = 1;

// Add multiple copies of PostItNote when used
function fl_ClickToDrag(event:MouseEvent):void
{
    event.currentTarget.parent.startDrag();
    event.currentTarget.parent.parent.setChildIndex(DisplayObject(event.currentTarget.parent),87);
    var my_PIN = new postItNote();
    my_PIN.name = "my_RTC" + q; // Doesn;t like this line
    this.parent.addChild(my_PIN);
    trace("my_PIN = " + my_PIN);
    this.my_PIN[q].x = 1388.05; // Doesn't like this line
    this.my_PIN[q].y = 100;
    q++;
}

错误是

TypeError: Error #1010: A term is undefined and has no properties.
    at postItNote/fl_ClickToDrag()[postItNote::frame1:71]"

1 个答案:

答案 0 :(得分:1)

  

my_PIN.name =“my_RTC”+ q; //不喜欢这一行

这意味着name不是postItNote类的属性。

  

this.my_PIN [q] .x = 1388.05; //不喜欢这一行

您似乎在使用错误的语法。你想要的只是:

my_PIN.x = 1388.05; // In this context, my_PIN already refers to the movie clip named '"my_RTC" + q'