![](/img/trans.png)
[英]PySide: Movable labels snap back to original position when released. Trying to make them move freely
[英]Object does not return to original position when released cs4
我正在進行拖放活動,其中將多個項目放置在同一目標上。 我在主時間軸上有操作代碼,然后將代碼附加到sprite。
問題:
當我釋放對象時,如果它是正確的,則應對齊該部分的頂部。 如果不正確,則應返回其原始方向以再次拾取。 不幸的是,它留在了我放置的位置,並且當它不正確時並沒有移回到原始位置。 我已解決了此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
}
問題在於,sprite代碼中的變量名稱和屬性拼寫錯誤。
替換這些行
this.X = this.defX;
this._Y = this.defY;
用那些線
this._x = this.defx;
this._y = this.defy;
並且您的代碼應該可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.