MJurcic / Final Exam / Picture Drag


See the Picture Drag

Open a new document and set its width and height to 400 each. Make the background a solid color different from white.

1:  Drag Buttons:
On the main stage, rename layer1 as button

Make a new button symbol and name it button. In the button edit mode, draw a square (50 by 50 pixels) on the Up state.  Then, add a keyframe in the Hit state.

Make another new symbol - a movie clip with name dragMovie.

In dragMovie symbol edit mode, drag the button symbol on to the stage. Right Click on the button, select Action (Expert Mode) and add the following code:

on (press) {
   this.startDrag(false);
}

on (release) {
  stopDrag();
}

2:  Main Stage:
Go back to the main stage (Scene 1) and drag two instances of the dragMovie from the Library on to the button layer. Select one of them, open the Instance Panel and name it drag1; do the same for the other and name drag2.  Lock the button layer.

Play the movie now. You should be able to drag the two squares around. See it here.

3:  The Image:
Make a new movie symbol and name it imageMovie. In the imageMovie symbol edit mode, insert an image on to the stage ( File / Import).

Select the image and use the Align Panel to Align left edge and Align top edge.

Go back to the main stage, make a new layer called image, and drag an instance of the imageMovie on to the layer. Select the imageMovie, open the Instance Panel and name it iMovie.

 

4:  The Control movie:

Make a new movie clip symbol ( Insert / New Symbol) and  name it control. This movie will have nothing in it.

Go back to the main stage, make a new layer control and drag an instance of the control movie from the Library. 

It should just be a small black dot. Select the dot, go to the Action Panel (Windows / Panels), and paste this code (Expert Mode):

onClipEvent (enterFrame) {
_root.drawLine ()
}

5: The Actions:

On the main stage, make a new layer and call it action, and add this code to the first frame:

iMovie.scaley = 100 / iMovie._height;
iMovie.scalex = 100 / iMovie._width;
function drawLine () {
iMovie._x = drag1._x;
iMovie._y = drag1._y;
iMovie._xscale = (drag2._x - drag1._x) * iMovie.scalex;
iMovie._yscale = (drag2._y - drag1._y) * iMovie.scaley;
}


Play the movie. The picture should resize when you drag the squares.

 
 
 

  MJurcic / Final Exam / Picture Drag