Home Contact RSS

Archive for February, 2007

Drag Line

Actionscript exercise with a line connecting movable movieClips.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

  1. // get x and y coordinates of the circles
  2. var ax = _root.point1._x;
  3. var ay = _root.point1._y;
  4. var bx = _root.point2._x;
  5. var by = _root.point2._y;
  6. var cx = _root.point3._x;
  7. var cy = _root.point3._y;
  8.  
  9. // draw line between them
  10. _root.createEmptyMovieClip ("line", 0);
  11. with (_root.line){
  12.   lineStyle (1, 0x999999, 100);
  13.   moveTo (ax, ay);
  14.   lineTo (bx, by);
  15.   lineTo (cx, cy);
  16.   lineTo (ax, ay);
  17. }

Source

Tags: , , , , ,

Multiple Targets

An actionscript exercise. Trying to get a movie clip to go to the closest dynamically created target. Click the button to make more targets. Draggable targets. Move the targets around to see the ball’s target change. Source file below.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Here’s the actioscript for the little ball:

  1. onClipEvent (load) {
  2.   //random placement
  3.   _x = Math.random()* 450;
  4.   _y = Math.random()* 450;
  5.   //speed is speed, higher number is slower movement
  6.   speed = (Math.random()*5)+7;
  7.   //x and y distance from target
  8.   xdist = 0;
  9.   ydist = 0;
  10. }
  11.  
  12. onClipEvent (enterFrame) {
  13.   //determine which target is closer a^2+b^2=c^2
  14.   //use a for loop to cycle through all targets,
  15.   //and assign the closest to be THE target
  16.   for (j=0; j <= _root.i; j++) {
  17.     //for the first automatically assign it as the closest
  18.     if (j == 0) {
  19.       xdist = _root.target0._x - _x;
  20.       ydist = _root.target0._y - _y;
  21.     }
  22.     //find the distance to next target
  23.     else {
  24.       //temporary distance variables
  25.       xdistT = _root["target"+j]._x - _x;
  26.       ydistT = _root["target"+j]._y - _y;
  27.       //if it is closer assign it to the closest, if not do nothing
  28.       if(Math.sqrt((xdist*xdist) + (ydist*ydist)) > Math.sqrt((xdistT*xdistT) + (ydistT*ydistT))) {
  29.         xdist = xdistT;
  30.         ydist = ydistT;
  31.       }
  32.     }
  33.   }
  34.  
  35.   //move toward the selected target
  36.   _x += xdist/speed;
  37.   _y += ydist/speed;
  38.  
  39.   //if target reached go to another random place
  40.   //if xdist is less than 2 and ydist is less than 2 and xdist is greater than 2 and ydist is greater than 2
  41.   if(xdist < 2 && ydist < 2 && xdist > -2 && ydist > -2) {
  42.     _x = Math.random() * 450;
  43.     _y = Math.random() * 450;
  44.   }
  45. }

Here’s the source flash file:
To Download the fla file.

Tags: , , , , ,

Road

road

Tags: ,

Talk

talk

Tags: ,

Look

look

Tags: ,

Imagine Everything

A ransom note style collage, quoting the Pearl Jam song Bee Girl, “Everything you imagine needn’t be stuck in your mind.” Made in photoshop as a typography exercise.

imagine everything

Tags: , ,

Ride

ride

Tags: ,

Night

night

Tags:
Next entries »