【发布时间】:2016-12-07 01:54:46
【问题描述】:
我找到了一个 swf 文件,它可以做我想做的事情。所以我下载了它并反编译了它,这样我就可以学习如何正确地做到这一点。然后把它应用到我正在做的事情上。 应该有很多项目,个人将其拖放到正确的类别中。如果释放时正确,则保留,如果不正确,则返回开始。What it looks like
我对原始文件进行了一些更改,因为它不起作用。您可以在 (onClipEvent) 中看到原始代码的位置。 我似乎已经解决了大多数问题,但我无法将拖动的项目释放到正确的位置。 我还为精灵添加了动作脚本。每个彩色三角形从左到右从 1 到 5 编号(希望这是正确的) 谢谢你的帮助。一个沮丧的科学老师。
// Action script…
// [onClipEvent of sprite 2 in]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, this.loading);
function loading(e:Event)
{
this.numItems = 2;
}
// [onClipEvent of sprite 2 in]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}
// [onClipEvent of sprite 2 in]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}
// [onClipEvent of sprite 8 in]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
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
}
// [onClipEvent of sprite 8 in frame 1]
//on (press)
this.addEventListener(MouseEvent.MOUSE_DOWN, pressed);
function pressed(event:Event){
if (this.noDrag != true)
{
startDrag (this, false);
} // end if
}
// [onClipEvent of sprite 8 in frame 1]
//on (release)
this.addEventListener(MouseEvent.MOUSE_UP, relea);
function relea(event:Event){
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
}
// [onClipEvent of sprite 2 in frame 1]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 2;
}
// [onClipEvent of sprite 2 in frame 1]
//onClipEvent (load)
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event){
this.numItems = 3;
}
// [Action in Frame 1]
answername = Array();
answerdest = Array();
answername[0] = "gravel";
answerdest[0] = "1";
answername[1] = "water";
answerdest[1] = "2";
dbCount = 0;
dbutton.duplicateMovieClip("dbutton" + dbCount,dbCount * 100);
dbutton.visible = false;
dbutton0.answer = answerdest[dbCount];
dbutton0.theText.text = answername[dbCount];
【问题讨论】:
-
"我无法将拖动的项目释放到正确的位置。"这无助于我们理解问题。告诉我们与您观察到的情况相比究竟发生了什么。有错误信息吗?您是否尝试使用调试器运行它?此外,听起来您想要的目标是一个非常简单的目标。为什么要反编译这个?从头开始制作脚本执行您所描述的操作很容易。我会从头开始,而不是对别人的代码进行逆向工程。但任何适合你的。
-
当我释放鼠标时,它不会将拖动的项目放到目标上。相反,它与鼠标保持一致。其次,我想从头开始,但找不到如何将三个项目设置为一个目标并将另一个不同的 3 个项目设置为不同目标的示例。这是我能找到的最接近的例子。我在动作脚本编码方面相对较新。
标签: actionscript-3 drag-and-drop targets