jeudi 8 décembre 2016

Object does not return to original position when released cs4

I am making a drag and drop activity where multiple items are to be placed at the same target. I have action code on the main time line and then code attached to a sprite. 1) problem 1) When I release the object if it is correct it should snap to the top of that section. If it is incorrect it should return to its original orientation to be picked up again, Unfortunately it stays where I placed it, and does not move back to original place when it is incorrect. I have fixed other issues with this flash file as to if code is supposed to be on the main time line or in the sprite, but this does not seem to have an effect after the object is released. Near the end of the script there is _root.rlamp1.gotoAndPlay(1) this is a buzzer that goes off if the answer is incorrect. This is working correctly 2) problem 2) I do not know if these are related Items but if the correct placement is given I want the next item to start in the original position, but it is starting where my mouse is instead of the original position. I am relatively new to coding and am trying to make an activity for my science class to get instant feedback to see if they understand to concept. Thanks for your help.

  // [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);
                trace (dbcount);
            }
            else
            {
                this.X = this.defX;
                this._Y = this.defY;
                _root.rlamp1.gotoAndPlay(1);
            } // end if
        } // end else if
    }

Aucun commentaire:

Enregistrer un commentaire