5 Replies Latest reply on Apr 15, 2010 12:11 PM by henry_ford

    Why am I getting an error?


      So I have one drop box and 5 draggable items. Only 1 can match with the drop box because it contains the word target and the draggable item's name in the variable (i.e. targetitem1). So when the user drags anying but the 1st item to the box it will bounce back and tells them to try again. I am having the issue of, when the user drags the right answer to the box, the 'next' button appears, the user clicks on it and all of the dragable items are not visible. I did a debug and it gave me an error at the line after gotoAndPlay. What am I doing wrong? It was working earlier today.




      next_btn.visible = false;


      spots1a1.buttonMode = true;
      spots1a2.buttonMode = true;
      spots1a3.buttonMode = true;
      spots1a4.buttonMode = true;
      spots1a5.buttonMode = true;


      spots1a1.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
      spots1a1.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
      spots1a2.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
      spots1a2.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
      spots1a3.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
      spots1a3.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
      spots1a4.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
      spots1a4.addEventListener(MouseEvent.MOUSE_UP, dropIt2);
      spots1a5.addEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
      spots1a5.addEventListener(MouseEvent.MOUSE_UP, dropIt2);


      function pickUp2(event:MouseEvent):void {
          answerlabel.text = "";
          startX = event.target.x;
          startY = event.target.y;
      function dropIt2(event:MouseEvent):void {
          var myTargetName2:String = "target" + event.target.name;
          var myTarget2:DisplayObject = getChildByName(myTargetName2);
          if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget2){
              answerlabel.text = "Good Job!";
              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp2);
              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt2);
              event.target.buttonMode = false;
              event.target.x = myTarget2.x;
              event.target.y = myTarget2.y;
              next_btn.visible = true;
          } else {
              answerlabel.text = "Try Again!";
              event.target.x = startX;
              event.target.y = startY;
                import flash.events.MouseEvent;
                next_btn.addEventListener(MouseEvent.CLICK, powerClick28);
                function powerClick28(Event:MouseEvent):void {
                spots1a1.visible = false;
                spots1a2.visible = false;
                spots1a3.visible = false;
                spots1a4.visible = false;
                spots1a5.visible = false;


        • 1. Re: Why am I getting an error?
          Ned Murphy Adobe Community Professional & MVP

          What error are you getting?  Not that it should matter since all the code should execute, but you should take care of putting things away before you gotoAndPlay anywhere

          • 2. Re: Why am I getting an error?
            henry_ford Level 1

            The error is TypeError: Error #1009: Cannot access a property or method of a null object reference. at conflict_fla::MainTimeline/powerClick28( [conflict_fla.MainTimeline::frame1008:56]


            I'm looking at the debug and its pointing to the line after gotoAndPlay. What's the besy way to "hide" the draggable items?

            • 3. Re: Why am I getting an error?
              Ned Murphy Adobe Community Professional & MVP

              Which line is line 56 on frame 1008?

              • 4. Re: Why am I getting an error?
                henry_ford Level 1

                So I think Flash has a mind of it's own...I got rid of the items that I want visible and left only the one that needs to disappear and it works now. At first you needed all of the items to clear the stage or they will show up on the next frame. I rebooted Flash and then tested the section and it works fine now, no errors. You drag the correct statement to the drop box and it tell you, congrats, you click on the 'next' button and then the new frame shows up with the new statments....

                • 5. Re: Why am I getting an error?
                  henry_ford Level 1

                  So the script is causing something weird to occur... If I don't select the correct answer first and drag over but rather drag everything

                  else and then the right answer to the drop box, the incorrect statemtns stick on the stage and are still visible on the next frame. How can I get them to clear. Do you want to see any error codes?


                  EDIT: I am using the same code in a previous frame and there is no error occuring there. How come?