0 Replies Latest reply on Dec 30, 2008 3:15 PM by german01

    Drag & Drop with Multiple MC

    german01 Level 1
      Hello:

      I'm building a game like a puzzle using action script 2.0. There will be 23 small puzzles, each in its own movie clip. This is one of 23. This has 14 movie clips, each representing a piece of the puzzle. I have duplicated each movie clip. For example av_1 has its copy av_1_1 and so for.
      I would like the user drag and drop each copy, for example av_1_1 onto av_1.

      A MOVIE CLIP called av_puzzle has all this information. This is the movie that will be placed on the MAIN stage.

      All movies (like av_1) are placed on the stage of the movie clip (av_puzzle) and given an alpha=1 (so that user can't see them).

      Original movies are on layer 3 (i.e. av_1)
      Copies are on layer 4 (i.e. av_1_1).

      movie clips used = av_puzzle (where all movie clips are stored. This is the movie that is placed on the stage)
      av_1 .. av_14 (each original piece)
      av_1_1.. av_14_1 (corresponding copies of each original)


      I have used the following code to drop each copy movie clip (i.e. av_1_1) onto the corresponding original (i.e. av_1). If av_1_1 finds av_1 the piece would take av_1 x,y values, if not, av_1_1 would come back to its position with the original size and x,y values.

      ALL ACTION SCRIPT IS ON FRAME ONE OF THE MOVIE CLIP av_puzzle

      PROBLEMS

      There are going to be 23 movies built in similar way. For that reason, av_puzzle contains the code for its own puzzle.

      When using this.startDrag only one movie clip responds to this code.
      When using _root.av_puzzle.av_1_1 the movie doesn't come back to its original place

      PLEASE SUGGEST WAYS TO IMPROVE THE ACTION SCRIPT OR DIFFERENT WAYS TO APPROACH THIS PROJECT.

      //piece av_1//

      origX = av_1_1._x;
      origY = av_1_1._y;

      _root.av_puzzle.av_1_1.onPress=function (){
      _root.av_puzzle.av_1_1.startDrag();
      _root.av_puzzle.av_1_1._width = 183.3;
      _root.av_puzzle.av_1_1._height = 202.5;

      };
      _root.av_puzzle.av_1_1.onRelease=_root.av_puzzle.av_1_1.onReleaseOutside=function(){
      _root.av_puzzle.av_1_1.stopDrag();
      if (eval(av_1_1._droptarget)==av_1){
      _root.av_puzzle.av_1_1._x=93.6;
      _root.av_puzzle.av_1_1._y=90;
      checkAnswer.gotoAndStop("p2");
      }else {
      _root.av_puzzle.av_1_1._x=origX;
      _root.av_puzzle.av_1_1._y=origY;
      _root.av_puzzle.av_1_1._width=30;
      _root.av_puzzle.av_1_1._height=40;
      }
      };

      //piece av_2//
      origX_1 = av_2_1._x;
      origY_1 = av_2_1._y;


      _root.av_puzzle.av_2_1.onPress=function (){
      _root.av_puzzle.av_2_1.startDrag();
      _root.av_puzzle.av_2_1._width=101;
      _root.av_puzzle.av_2_1._height=93.5;

      };
      _root.av_puzzle.av_1_1.onRelease=_root.av_puzzle.av_2_1.onReleaseOutside=function(){
      _root.av_puzzle.av_2_1.stopDrag();
      if (eval(av_2_1._droptarget)==av_2){

      _root.av_puzzle.av_2_1._x=407.9;
      _root.av_puzzle.av_2_1._y=78.8;
      checkAnswer.gotoAndStop("p2");
      }else {
      _root.av_puzzle.av_2_1._x=origX_1;
      _root.av_puzzle.av_2_1._y=origY_1;
      _root.av_puzzle.av_2_1._width=37;
      _root.av_puzzle.av_2_1._height=38;
      }
      };


      Thanks in advance.