3 Replies Latest reply: Apr 1, 2010 1:40 PM by Ned Murphy RSS

    Button in draggable MC

    Shed Simas Community Member

      Hey everyone,

       

      I'm working on a project where I have cards that need to be moved around and flipped. The cards themselves are on individual movie clips. I originally intended for a double-click to flip the card, and a click-and-drag to movem them around. That just wouldn't work; for some reason the double click wouldn't work even thogh I had doubleClickEnabled set to true. So what I'm currently trying is to have a button that flips the cards within the card movie clip; however that is also not working. Somehow, the button stays in place instead of being moved with the rest of the MC.

       

      Unfortunately I'm not on a computer with Flash, so I can't post the code, but I'll do that tomorrow. For now, does anyone have any suggestions?

       

      Thank you!

        • 1. Re: Button in draggable MC
          Ned Murphy CommunityMVP

          Just on a hunch I'd say you need to use 'currentTarget' instead of 'target for the drag code'.  Beyond that, you'll be in a better position to get help when you post your code and explain how things are put together and where your code is.

          • 2. Re: Button in draggable MC
            Shed Simas Community Member

            Thanks! That did work.

             

            I was hoping you might be able to help me with my previous attempt, where click-and-drag moves the card and double-clicking flips it. I would prefer to use this method over the flip button if possibel. Here's the code I was using:

             

            TVmc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
            TVmc.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
            TVmc.addEventListener(MouseEvent.DOUBLE_CLICK, flipCard);
            TVmc.doubleClickEnabled = true;
            
            function flipCard(myEvent:MouseEvent):void {
                 TVmc.gotoAndPlay(currentFrame+1);
            }
            
            function startDragging(myEvent:MouseEvent):void {
                 myEvent.currentTarget.startDrag();
            }
            function stopDragging(myEvent:MouseEvent):void {
                 myEvent.currentTarget.stopDrag();
            }
            
            

             

            The flipping animation is within TVmc. Each of the two states in TVmc (face up and face down) has a variation of the following code, changing only the movie clip instance name and the finction name:

            stop();
            
            TVfront.addEventListener(MouseEvent.DOUBLE_CLICK, flipFront)
            TVfront.doubleClickEnabled = true;
            
            function flipFront (myEvent:MouseEvent): void {
                      gotoAndPlay(currentFrame+1); }
            

             

            The code half-works. If the card is face up, it flips properly; however, if it is face down, the animation plays from the beginning (ie. from the face up state instead of from the current face down state).

            • 3. Re: Button in draggable MC
              Ned Murphy CommunityMVP

              It may just be a case of targeting the wrong timeline:

               

              TVmc.gotoAndPlay(TVmc.currentFrame+1);

               

              Though I'm not sure which object is supposed to be animating