A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Simple drag and drop

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1

    Simple drag and drop

    Hi,

    I am using Flash CS5.

    I am creating an intro to a site where the user drags an animated coin over to an old 1900s style movie viewing machine, which allows the user to enter the rest of the site.

    COIN:
    it consists of a MC with a label called 'red'. Within is a button that has this script on it:

    on(press){
    startDrag(this);

    }


    on(release){
    stopDrag();
    if (_root.yellow._droptarget == "/computer") {
    _root.gotoandStop("red");
    }

    }


    On the main timeline there is an invisible MC with the label 'computer'.

    When I drag the coin and drop it, it should go to the frame labeled 'red'. But it just stays at the current frame.

    Any thoughts would be appreciated. I apologize for not attaching the file but the coin animation on the button is too large a file.

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    1.) do NOT use object code (meaning stop putting/pasting code directly on movieclips, buttons..etc put ALL CODE in the timeline in the frame(s) where your objects are.

    2.) make sure you give EVERYTHING an instance name

    so you have you first frame.. (stop(); action)..

    with your coin movieClip (call it coin_mc)

    and your dropTarget clip.. (it is called 'yellow'?)

    and do not use _droptarget..but instead use hitTest()..


    code:

    coin_mc.onPress = function(){
    this.startDrag();
    }

    coin_mc.onRelease = function(){
    stopDrag();
    if(this.hitTest(_root.yellow){
    _root.gotoAndStop("red");
    }
    }

  3. #3
    Member
    Join Date
    Jul 2004
    Location
    New Haven, CT
    Posts
    79
    Here is some classic drag and drop code that should help you.
    Looks like you were missing some parenthesis and you should maybe get rid of that forward slash before the instance name of computer...


    Code:
    on (press) {
        //Start Dragging Movieclip Behavior
        startDrag(this);
        //End Behavior
    }
    
    
    on (release) {
        //Stop Dragging Movieclip Behavior
        stopDrag();
        //End Behavior
        if (eval(this._droptarget) == _root.computer) {
            _root.gotoAndStop("red");
        }
    }

    PS - keep in mind that this code (with the _root. part) is trying to send the main timeline to a frame label of "red" (not a frame label within a movie clip). If you want to affect the timeline of a movie clip (like coin_mc), you would add that like this:
    _root.coin_mc.gotoAndStop("red");
    Last edited by fademusic; 05-02-2011 at 10:21 PM. Reason: Adding mc instance name info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center