Class #16 - Tuesday, June 3rd, 2008

Modifying the A L I C E picture puzzle game code.


  1. Here are two examples of a picture puzzle game that involves Dragging and Dropping movie clips:

    • BGP Beginning Game Programming with Flash textbook Chapter 6 Koala Bear PUZZLE GAME example.


    • The March 6th, 2008 A L I C E bookcover puzzle game created during spring of 2008 semester for Flash Animation class.

      STUDY THE CHANGES MADE ON MONDAY and TUESDAY:

      Here are the Frame #2 code improvements:

      // Assign names done NOW using a FOR loop to each element in the myClip array.
      // VIP: Also recording the clipNumber 0, 1, 2, 3, 4, 5, 6 or 7 with each object.
                                 ----------
      
      for (var p:int = 0; p < numClips; p++) {
      
           myClip[p].name = "piece" + p;
      
           myClip[p].clipNumber = p;
      }
      
      ...
      
      // Generate random location (x and y positions) for the 8 movie clip puzzle pieces.
      
      for (var i:int = 0; i <= 7; i++) {
      
             myClip[i].x = Math.random() * 225 + 320;
             myClip[i].y = Math.random() * 310;
      }
      

      Here is the payoff, still in Frame #2. Note that the ActionScript code now does NOT even have a for loop and there is NO NEED to go search through all of the 8 puzzle pieces in the else if when the DROP occurs (i.e. when the evt.type is == to "mouseUP").
      //function pieceMove triggers the startDrag and stopDrag methods on mouseDown and mousep
      function pieceMove(evt:Event):void {
      
      	if (evt.type == "mouseDown") {
      
      		evt.target.startDrag();
      
      	} else if (evt.type == "mouseUp") {
      
      		evt.target.stopDrag();
      
      		var theClipNumber:int = evt.target.clipNumber;
      
      		if ( evt.target.hitTestObject( nph[theClipNumber] ) ) {
      
      			trace("Target clipNumber " + evt.target.clipNumber);
      
      			removeChild( myClip[theClipNumber] );
      			
      			nph[theClipNumber].alpha = 0;   //set alpha of the little rectangle to 0 
      			
      			tpg[theClipNumber].alpha = 100;  //set alpha of the old puzzle piece to 100
      
      			score++;
      
      		} else {
      
      			evt.target.x = Math.random() * 215 + 320;
      			evt.target.y = Math.random() * 310;
      		}
      	}
      	
      	scor.text = score.toString();
      
      	if (score == 8) {
      
      		msgbox_txt.text = "Way to go, " + theName + "!";
      
      		timer.stop();
      		gotoAndStop(3);
      	}
      }
      
      
      

    • Note about the Puzzle Game: A L I C E is an animation programming language, thus the book cover that was cut up and turned into 8 separate movie clips using Flash. Play the game, then study some of the ActionScript 3.0 code and comments, then play the game a few more times.

  2. You will be given an assignment to create a picture puzzle game as your 3rd Flash project.

  3. Chapter 5 assignment: Assignment Two links and example pages.

  4. Chapter 6 Arrays and Movie Clip Methods *********************** STUDY CHAPTER SIX *********************

    • Create and use arrays
    • Use movie clip methods
    • Add child
    • Remove child
    • Stop drag
    • Use the for loop

    ********************************************* STUDY CHAPTER SIX *********************************************

  5. How do you Drag and Drop on the Flash stage? The methods are listed and explained on page 120 of the BGP book.