【发布时间】:2017-04-24 09:32:14
【问题描述】:
我正在做一个拖放活动,其中多个项目将被放置在同一个目标上。我在主时间线上有动作代码,然后代码附加到一个精灵。
问题:
当我释放对象时,如果它是正确的,它应该会捕捉到该部分的顶部。如果不正确,则应返回其原始方向以再次拾取。不幸的是,它停留在我放置的位置,并且当它不正确时不会移回原来的位置。我已经修复了此 flash 文件的其他问题,即代码是否应该位于主时间线或精灵中,但这似乎在对象被释放后没有效果。在脚本的末尾有
_root.rlamp1.gotoAndPlay(1)这是一个蜂鸣器,如果答案不正确,它会响起。这工作正常。我不知道这些是否是相关的项目,但如果给出了正确的位置,我希望下一个项目从原始位置开始,但它从我的鼠标所在的位置而不是原始位置开始。我对编码比较陌生,正在尝试为我的科学课制作一项活动,以获得即时反馈,看看他们是否理解概念。
感谢您的帮助。
// [Action in Frame 1]
answername = Array();
answerdest = Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "nuts and bolts";
answerdest[1] = "1";
answername[2] = "oxygen";
answerdest[2] = "2";
answername[3] = "helium";
answerdest[3] = "2";
answername[4] = "gold";
answerdest[4] = "2";
dbCount = 0;
dbutton.duplicateMovieClip("dbutton" + dbCount,dbCount * 100);
dbutton.visible = false;
dbutton0.answer = answerdest[dbCount];
dbutton0.theText.text = answername[dbCount];
// This code is on the sprite and not on the main actionscript
onClipEvent (load)
{
this.defx = _x;
this.defy = _y;
if (this.theText.text.length > 20)
{
this.theText._height = 31;
this.theBox._height = 27;
}
else
{
this.theText._height = 19;
this.theBox._height = 19;
} // end else if
}
on (press)
{
if (this.noDrag !=true)
{
startDrag (this,false);
}
}
on (release)
{
if (this.noDrag != true)
{
stopDrag ();
if(this.hitTest(_root["dz" + this.answer]))
{
totalHeight = 0;
for (v = 0; v < _root.dbCount; v++)
{
if (_root["dbutton" + v].answer == this.answer)
{
totalHeight = totalHeight + _root["button" + v].theBox._height ;
} // end if
} // end of for
++_root.dbCount;
this .duplicateMovieClip("dbutton" + _root.dbCount, _root.dbCount * 100);
_root["dbutton" + _root.dbCount]._x = this.defX;
_root["dbutton" + _root.dbCount]._y = this.defY;
_root["dbutton" + _root.dbCount].answer = _root.answerdest[_root.dbCount + 1];
_root["dbutton" + _root.dbCount].theText.text = _root.answername[_root.dbCount +1];
if (_root["dbutton" + _root.dbCount].theText.text == "undefined")
{
_root["dbutton" + _root.dbCount].theText.text = "Finished!";
_root["dbutton" + _root.dbCount].noDrag = true;
} // end if
this.noDrag = true;
this._y = _root["dz" + this.answer]._y + totalHeight;
this._x = _root["dz" + this.answer]._x - _root["dz" + this.answer]._width / 2;
++_root["dz" + this.answer].numItems;
_root.glamp1.gotoAndPlay (1);
}
else
{
this.X = this.defX;
this._Y = this.defY;
_root.rlamp1.gotoAndPlay(1);
} // end if
} // end else if
}
【问题讨论】:
-
真的是actionscript 3吗?
-
看起来很可疑的代码是
onClipEvent (load)和on (press)和on (release)。这不是 AS3 语法。你从哪里得到那个的?这些行不会引发疯狂的错误吗?!它看起来像我从 AS2 中记得的东西。由于它没有抛出错误,我猜你没有使用闪存的调试器版本。尝试使用 ctrl+Shift+enter 运行您的代码以在调试模式下运行,并让我知道它会引发什么错误。 -
我已经使用 ctrl+shift+enter 运行它并且没有出现错误。该代码是通过反编译一个 swf 文件获得的,该文件可以执行我想要它执行的操作,一旦我弄清楚我想要更改项目以使其适合我的目的的代码。
-
我听取了人们的建议并从头开始,所以我将在新线程中发布我的进展。感谢您迄今为止的帮助。
标签: drag-and-drop position sprite actionscript-2 flash-cs4