Skip navigation
Currently Being Moderated

drag and drop to target simple errors, expecting identifier?

Dec 8, 2012 6:07 AM

Tags: #and #drop #cs5 #action_script_3 #drag #target

im creating a drag and drop. moving a guitarest name to a target e.g draging a movieclip called slash to a dynamic text box called box_slash this is my code and i get 2 stupid errors but have been up all night and cant figure it out!

flash cs5 actionscript 3, is this code for actionscript3 i found the base for it here: http://edutechwiki.unige.ch/en/Flash_drag_and_drop_tutorial any help would be incredible as it for an assignment and im new to flash

var hits = 0;

 

// Register mouse event functions

 

slash.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

slash.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

clapton.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

clapton.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

hendrix.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

hendix.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

 

 

 

// Define a mouse down handler (user is dragging)

function mouseDownHandler(evt:MouseEvent):void {

          var object = evt.target;

          // we should limit dragging to the area inside the canvas

          object.startDrag();

}

 

function mouseUpHandler(evt:MouseEvent):void {

          var obj = evt.target;

          // obj.dropTarget will give us the reference to the shape of

          // the object over which we dropped the circle.

          var target = obj.dropTarget;

          // If the target object exists the we ask the test_match function

          // to compare moved obj and target where it was dropped.

          if (target != null)

          {

                    test_match(target, obj);

          }

          obj.stopDrag();

}

 

function test_match(target,obj) {

          // test if either one of the four pairs match

          if ( (target == box_slash && obj == slash) ||

             (target == box_clapton && obj == clapton) ||

               (target == box_hendrix && obj == hendrix) || )

          {

                    // we got a hit

                    hits = hits+1;

                    textField.text = "Correct! :)";

                    // make the object transparent

                    obj.alpha = 0.5;

                    // kill its event listeners - object can't be moved anymore

                    obj.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

                    obj.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);

                    // Test if we are done

                    if (hits == 3)

                    {

                              textField.text = "Well Done";

                    }

          }

          else

          {

                    textField.text = "wrong! :(";

          }

}

 

the errors are: i have highlighted the lines

 

Scene 1, Layer 'Actions', Frame 1, Line 391084: Syntax error: expecting rightparen before leftbrace.
Scene 1, Layer 'Actions', Frame 1, Line 381084: Syntax error: expecting identifier before rightparen.
 
Replies
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 6:16 AM   in reply to elmop2005

        (target == box_hendrix && obj == hendrix) || )

     

    has a syntax error.  that should be:


        (target == box_hendrix && obj == hendrix)  )

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 6:32 AM   in reply to elmop2005

    that's not the best choice for a flash variable but, if you had a textfield named textField in the scope of your code when that code executed, you would not see an error message.

     

    so, change the name to something else (eg, feedback_tf) and make sure that variable name matches your code and the instance name in the properties panel.

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 7:00 AM   in reply to elmop2005

    copy and paste your edited code and attach a screen shot that shows your selected on-stage textfield and the properties panel.

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 7:09 AM   in reply to elmop2005

    sprites and movieclips can be dragged/dropped, not simple buttons.

     

    either use a movieclip button (so you can use startDrag with it) or use an enterframe loop that causes your simple button to follow the mouse (which will look like a startDrag).

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 7:32 AM   in reply to elmop2005

    no text should be in entered in a on-stage textfield unless you use static text.  ie, the only text in dynamic and input textfields should be added using actionscript.

     
    |
    Mark as:
  • kglad
    72,228 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 8, 2012 9:02 AM   in reply to elmop2005

    on your last main timeline frame attach:

     

    gotoAndStop(1);

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points