我发现一个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];
“我无法将拖动的物品放到正确的位置。”这无助于我们理解问题。告诉我们与你观察到的事情相比究竟发生了什么。是否有错误讯息?你有没有试过用调试器来运行它?此外,这听起来像你想要的目标是一个非常简单的目标。为什么要反编译这个?做一个脚本做你所描述的很容易从头开始。我会从一开始就开始,而不是对其他人的代码进行逆向工程。但无论适合你。 –
当我释放鼠标时,它不会将拖动的项目拖放到目标上。相反,它保持与鼠标。其次,我想从头开始,但找不到如何将三个项目设置为一个目标,将另一个不同的三个项目设置为不同目标的示例。这是我能找到的最接近的例子。我在动作编码方面相对较新。 – user7259892