我發現一個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