5 Replies Latest reply on Jul 27, 2010 6:14 AM by Randy_Cates

    All work but one yet same naming

    Randy_Cates

      This is the code for a drag and drop exercise:

       

      stop();

       

      var startX:Number;
      var startY:Number;
      var counter:Number = 0;

       

      bmw_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      bmw_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      coke_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      coke_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      disney_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      disney_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      genelec_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      genelec_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      hallmark_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      hallmark_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      homedepot_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      homedepot_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      levis_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      levis_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      starbucks_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      starbucks_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
      target_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
      target_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);

       

      function pickUp(event:MouseEvent):void {
          event.target.startDrag(true);
          reply_txt.text = "";
          event.target.parent.addChild(event.target);
          startX = event.target.x;
          startY = event.target.y;
      }
      function dropIt(event:MouseEvent):void {
          event.target.stopDrag();
          var myTargetName:String = "target" + event.target.name;
          var myTarget:DisplayObject = getChildByName(myTargetName);
          if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
              reply_txt.text = "Good Job!";
              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
              event.target.buttonMode = false;
              event.target.x = myTarget.x;
              event.target.y = myTarget.y;
              counter++;
          } else {
              reply_txt.text = "Try Again!";
              event.target.x = startX;
              event.target.y = startY;
          }
          if(counter == 9){
              reply_txt.text = "Congratulations, you're finished!";
          }
      }
      bmw_mc.buttonMode = true;
      coke_mc.buttonMode = true;
      disney_mc.buttonMode = true;
      genelec_mc.buttonMode = true;
      hallmark_mc.buttonMode = true;
      homedepot_mc.buttonMode = true;
      levis_mc.buttonMode = true;
      starbucks_mc.buttonMode = true;
      target_mc.buttonMode = true;

       

      I don't understand why two things aren't working (I'm new to all this).

       

      1. Although all files are named the same and formatted the same, the genelec_mc won't recognize the target (same naming convention as all other targets)

       

      2. I'm getting no reply text when the dragged elements are dropped on their correct targets.

       

      As always any help is most appreciated.

      Thank you

       

      Frustrated (the sequal)

        • 1. Re: All work but one yet same naming
          funkysoul Level 4

          are you sure that the genetec_mc and reply_txt have the correct instance names?

          • 2. Re: All work but one yet same naming
            Randy_Cates Level 1

            Stand by checking....

             

            TY

            • 3. Re: All work but one yet same naming
              Randy_Cates Level 1

              OK, this is a drag and drop with logos that will associate themselves with slogans or logo bugs by dragging the logo over the appropriate slogan (a branding exercise).

               

              Following are the naming conventions for the BMW logo (which works - snaps to the target) followed by the same for the General Electric logo which will no snap to the target.

               

              BMW:

              Imported =           symbol20

              Instance name =  bmw_mc

              (Instance of mcBMW)

              Target name =     mcBmwTarget

               

              General Electric:

              Imported =          symbol69

              Instance name = genelec_mc

              (instance of mcGenelec)

              Target name =     mcGenelecTarget

               

              The BMW logo works the General Electric doesn't. Neither (or any of the 9) will instigate a reaction from the Reply Text box which is set to dynamic text and the text box instance name is "reply_txt" - no quotes.

               

              Thank you

              Frustrated (but hopeful)

              • 4. Re: All work but one yet same naming
                Karthikeyan Ramasamy Level 2

                Hi,

                 

                Your code works perfectly for me.

                 

                Target instance name should start with "target", since you are appending (inside actionscript) 'target' infront of instance names to get target display object using getChildByName.

                 

                i.e for BMW movie clip

                 

                Instance name =  bmw_mc

                Target instance name =  targetbmw_mc

                 

                Thanks,

                Karthikeyan R.

                • 5. Re: All work but one yet same naming
                  Randy_Cates Level 1

                  Outstanding, I'll give it a try and see what I get. I wonder how the

                  tutorial I got this from manages to work with it the way I have it - plus

                  all the others "except" the general electric logo work as is. Far be it from

                  me to question, like I said, this is all new to me.

                   

                  Thank you so much. I'll post my results.

                  Frustration subsiding (wink)