3 Replies Latest reply on Sep 28, 2011 2:41 PM by eg@CDW

    AS2 Drag and Drop Interaction help

    eg@CDW

      I am trying to create a reusable template for a drag and drop interaction.

       

      There are 7 drag objects, 7 targets.

      Based on a scenario we develop (which of the 7 services [drag objects] are the best solution, for example), I would like to create interactions where some of the drag drop combinations are correct answers and dragging/dropping other combinations would result in an "incorrect" answer.

       

      I am having issues with designating the correct and incorrect responses in the AS code, as well as how to provide the positive (correct answers) and negative (incorrect answers) feedback after a submit button is selected.

       

      Additionaly, I have a reset button that does not function the way I expected - move the drag objects back to the start position and allow the user to resubmit an answer.

       

      I am using Flash CS5, but need to use AS2 as the swf file is going to be inserted into an Articulate Presenter project (Articulate does not support AS3 yet).

       

      Thank you for any assistance or suggestions!

       

      Source file: https://www.dropbox.com/home/AS2%20D&D#:::68035214

       

      Current AS2 code:

       

      function dragSetup(clip, targ) {

      clip.onPress = function() {

      startDrag(this);

      this.beingDragged=true;

      };

      clip.onRelease = clip.onReleaseOutside=function () {

      stopDrag();

      this.beingDragged=false;

      if (eval(this._droptarget) == targ) {

      this.onTarget = true;

      _root.targ.gotoAndStop(2);

      } else {

      this.onTarget = false;

      _root.targ.gotoAndStop(1);

      }

      };

      //the variables below will store the clips starting position

      clip.myHomeX = clip._x;

      clip.myHomeY = clip._y;

      //the variables below will store the clips end position

      clip.myFinalX = targ._x;

      clip.myFinalY = targ._y;

      clip.onEnterFrame = function() {

      //all these actions basically just say "if the mouse is up (in other words - the clip is not being dragged)

      // then move the MC back to its original starting point (with a smooth motion)"

      if (!this.beingDragged && !this.onTarget) {

      this._x -= (this._x-this.myHomeX)/5;

      this._y -= (this._y-this.myHomeY)/5;

      //if the circle is dropped on any part of the target it slides to the center of the target

      } else if (!this.beingDragged && this.onTarget) {

      this._x -= (this._x-this.myFinalX)/5;

      this._y -= (this._y-this.myFinalY)/5;

      }

      };

      }

      dragSetup(drag1,drop1);

      dragSetup(drag2,drop2);

      dragSetup(drag3,drop3);

      dragSetup(drag4,drop4);

      dragSetup(drag5,drop5);

      dragSetup(drag6,drop6);

      dragSetup(drag7,drop7);

       

       

      //this code controls the reset button function and returns all of the drag objects to the start position.

      resetBtn.onRelease = function (){

      drag1.onTarget=false;

       

       

      drag1._x = drag1.myHomeX;

      drag1._y = drag1.myHomeY;

       

       

      drag2.onTarget=false;

      drag2._x = drag2.myHomeX;

      drag2._y = drag2.myHomeY;

       

       

      drag3.onTarget=false;

      drag3._x = drag3.myHomeX;

      drag3._y = drag3.myHomeY;

       

       

      drag4.onTarget=false;

      drag4._x = drag4.myHomeX;

      drag4._y = drag4.myHomeY;

       

       

      drag5.onTarget=false;

      drag5._x = drag5.myHomeX;

      drag5._y = drag5.myHomeY;

       

       

      drag6.onTarget=false;

      drag6._x = drag6.myHomeX;

      drag6._y = drag6.myHomeY;

       

       

      drag7.onTarget=false;

      drag7._x = drag7.myHomeX;

      drag7._y = drag7.myHomeY;

       

       

      }

      //This code controls the submitBtn and feedback for a correct and incorrect answer

      var groupID:Array = [0,0];

      var incorrectFeedback:String = "That isn't correct.";

      var correctFeedback:String = "Excellent good work.";

      var answerGroup:Array =  [

                                                                   [drag1,drop1],

                                                                   [drag2,drop2],

                                                                   [drag3,drop3],

                                                                   [drag4,drop4],

                                                                   [drag5,drop5],

                                                                   [drag6,drop6],

                                                                   [drag7,drop7]];

       

       

       

      //Enable all the stage items

      resetBtn.onRelease = function()

      {

                resetAll();

      }

       

       

      submitBtn.onRelease = function()

      {

       

                if(evaluateAnswers())

                {

                          feedbackTxt.text = correctFeedback;

                }

                else

                {

                          feedbackTxt.text = incorrectFeedback;

                }

      }