2 Replies Latest reply on Jan 15, 2007 11:44 AM by organicdigital

    XML based drag and drop

    organicdigital
      ok, im not new to any of this really. Im simply stuck and cant figure out why my drop targets arent working. my variables are tracing directly before the drop target is evaluating.... its just not returning that it is droped on the target.

      the specific problem:

      btn.onRelease = function(){
      stopDrag();
      target_ = _root["t_"+ a_num];
      droper = _root["d_"+ a_num];
      trace(droper + "//" + target_);
      //////--------------------THE PROBLEM--------------------///////
      if (eval(droper._droptarget) == target_) {
      trace("Success");
      }else{
      trace("failure")
      }
      }



      here is the code in full:


      //sets animation begin point variables
      for(i = 0;i< 10; i++){
      tx = i*125;
      ty = i*125;
      dx = 180;
      dy = i*125;
      }
      //loading animations and non-xml text loads//
      obs_box.top_.tex_1 = "Drag and Drop Exercise";
      obs_box.stg_.slideTo(obs_box.stg_._x, -467.5, 1, "easeOutQuad");
      obs_box.top_.slideTo(obs_box.top_._x, -525, .75, "easeInOutQuad", .25);
      side_bg.slideTo(side_bg._x, 175, 1, "easeOutQuad");
      //load xml//
      var terms_xml = new XML();
      terms_xml.ignoreWhite = true;
      terms_xml.onLoad = function(success){
      //end loading of data//
      if (success){
      var main_ob:Array = new Array();
      var main_trgt:Array = new Array();
      var term_:Array = new Array();
      var titl_ = terms_xml.firstChild.firstChild.childNodes;
      var term_ = terms_xml.firstChild.childNodes;
      header_.title_text = titl_;
      list_amount = term_.length -1;
      for (var i=0; i < list_amount; i++){
      main_ob = term_.nextSibling.firstChild.childNodes;
      main_trgt = term_.nextSibling.firstChild.nextSibling.childNodes;
      }
      }
      //attaches the drop target movie clip (t_1) and created text fields//
      amount = main_trgt.length;
      for(x=0;x<amount;x++){
      ypos = x*25;
      _root.attachMovie("target_", "t_"+x,x,{_x:tx, _y:ypos});
      //determines position of drop targets//
      if(x>3){
      ypos =135+130;
      xpos = 662.5-(amount+125) * (x-4);
      }else{
      ypos = 135;
      xpos = 662.5-(amount+125) * x;
      }
      //drop target positions are set now time to move them there (**originating position of the drop targets are set throught
      //tx & ty variables in the top of this document
      var tgt = _root["t_"+x];
      var ob_t =tgt.t_tex;
      tgt.scaleTo(0, .001, "ease");
      tgt.scaleTo(100, 1.75, "easeInOutBack", x/5);
      tgt.slideTo(xpos,ypos,.75,"easeOutQuad",x/75);
      tgt.alphaTo(50, 1, "easeOutQuad");
      ob_t.text = main_trgt[x];
      }
      //attaches the movie clip that will be droped onto the target (d_1) and created text fields//
      amount = main_ob.length;
      var ypos = new Array();
      var btn:Array = new Array;
      for(v = 0; v<amount;v++){
      ypos[v] =300/amount*v+25;
      }
      _ypos = ypos.randomize();
      for(j=0;j<amount;j++){
      _root.attachMovie("drop", "d_"+j,j+ 8,{_x:90, _y:_ypos});
      //determines position of object//
      //object positions are set now time to move them there (**originating position of the drop targets are set throught
      //dx & dy variables in the top of this document
      btn = _root["d_"+j];
      var btn_t = btn.d_tex;
      btn.scaleTo(0, .001, "ease");
      btn.scaleTo(100, 1.75, "easeInOutBack", j/5);
      btn.slideTo(83,250,.75,"easeOInutQuad",j/amount);
      btn.slideTo(83,_ypos[j],.75,"easeInOutQuad",j/amount+1);
      btn.alphaTo(95, 1, "easeOutQuad");
      btn_t.text = main_ob[j];

      //begin button actions when interacted with//
      btn.onRollOver = function(){
      ovr(this);
      }
      btn.onRollOut = function(){
      ndr(this);
      }
      btn.onPress = function(){
      drg(this);
      }
      btn.onRelease = function(){
      var que:String = quest;
      _que = new String(quest);
      q_num = _que.substr(10,1);
      var _par:String = this;
      _par_str = new String(_par);
      numer = _par_str.substr(10,1);
      ans = _par;
      var ans:String = ans;
      _ans = new String(ans);
      a_num = _ans.substr(10,1);
      stopDrag();
      target_ = _root["t_"+ a_num];
      droper = _root["d_"+ a_num];
      trace("----------------->>");
      trace(droper + "//" + target_);
      trace("<<--------------------");
      if (eval(droper._droptarget) == target_) {
      trace("Success");
      }else{
      trace("failure")
      }
      }
      btn.releaseOutside = function(){
      }
      }
      MovieClip.prototype.ovr = function(ob){
      ob.alphaTo(75,1, "easeOutQuad");
      ob.btn_cover.slideTo(btn_cover._x, -15, .75, "easeOutQuad");
      ob.btn_cover.brightnessTo(50, .25, "easeInOutQuad",.25);
      ob.btn_cover.brightnessTo(60, .25, "easeInOutQuad",1);

      }
      MovieClip.prototype.ndr = function(ob){
      ob.alphaTo(100,1, "easeOutQuad");
      ob.btn_cover.slideTo(btn_cover._x, -40, 1, "easeOutQuad");
      ob.btn_cover.brightnessTo(0, 1, "easeInOutQuad",1);
      }
      MovieClip.prototype.drg = function(ob){
      ob.startDrag(ob);
      }

      //final closer "}" below. Everything must reside above this unless its a prototype(function)
      //or the xml.load call//
      }
      //COMMITS THE XML LOAD FUNCTION ABOVE//
      terms_xml.load("dnd.xml");
      //Randomize the answers on the left//
      Array.prototype.randomize = function() {
      var i = this.length;
      if (i == 0) return;
      while (--i) {
      var j = Math.floor(Math.random()*(i+1));
      var tmp1 = this ;
      var tmp2 = this[j];
      this
      = tmp2;
      this[j] = tmp1;
      }
      return this;
      }