2016-12-09 5 views
0

複数のアイテムを同じターゲットに配置するドラッグアンドドロップ操作を行っています。メインタイムラインにアクションコードがあり、スプライトにコードが付加されています。リリース時にオブジェクトが元の位置に戻らないcs4

問題:

  1. 私はオブジェクトを解放すると、それが正しいかどうかは、そのセクションの先頭にスナップしなければなりません。それが間違っていれば、元の向きに戻って再び拾うべきです。残念ながら、それは私が置いた場所にとどまり、間違っていると元の場所に戻らない。私はコードがメインタイムラインまたはスプライトにあるはずですが、このフラッシュファイルで他の問題を修正しましたが、オブジェクトが解放された後には効果がないようです。スクリプトの終わり近くに_root.rlamp1.gotoAndPlay(1)があります。これは、応答が間違っている場合に消えるブザーです。これは正しく動作しています。

  2. これは関連する項目なのかどうかわかりませんが、正しい配置が指定されていれば、元の位置から開始しますが、元の位置ではなくマウスの位置から開始します。私は比較的新しいコーディングをしています。私の科学クラスのための活動をして、彼らが概念を理解しているかどうかを知るための瞬時のフィードバックを得ることを試みています。

ありがとうございました。

// [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 
    } 
+0

本当にactionscript 3ですか? –

+0

特に怪しげに見えるコードは 'onClipEvent(load)'と 'on(press)'と 'on(release)'です。これはAS3の構文ではありません。あなたはどこからそれを手に入れましたか?それらの行は狂ったエラーを投げないのですか?それは私がAS2から覚えているもののようです。エラーが発生していないので、デバッガ版のフラッシュを使用していないと推測しています。 ctrl + Shift + enterでコードを実行してデバッグモードで実行し、エラーの原因を教えてください。 –

+0

私はctrl + shift + enterを使用して実行しましたが、エラーは発生しません。私の目的に合うようにアイテムを変更したいコードを見つけたら、swfファイルを逆コンパイルしてコードを取得します。 – user7259892

答えて

0

問題は、スプライトコードにスペルミスのある変数名とプロパティがあることです。

これらの行にそれらのライン

this._x = this.defx; 
this._y = this.defy; 

this.X = this.defX; 
this._Y = this.defY; 

を交換し、あなたのコードは動作するはずです。

関連する問題