Define Path with Mouse and Draw Line


Clip | Source

An ActionScript Snippet Example by birdy1976

// STEP 1
// run this script and press the
// mouse button to record your path
var i = 0;
var flagRecord = false;
var flagPlay = false;
var arrXPos = new Array();
var arrYPos = new Array();
// 
// STEP 2
// copy and paste the mouse positions
// from the output window below here.
// an example how it might look like:
// arrXPos[0] = 534;
// arrYPos[0] = 46;
// arrXPos[1] = 540;
// arrYPos[1] = 50;
// ...
// delete all the values of the arrays
// if you want to record a new path!
// 
// STEP 3
// there is no step three...
// 
// - - - - -
// do not touch the code below here
// unless you know what you are doing
// - - - - -
// when mouse button is pressed record
_root.onMouseDown = function() {
  flagRecord = true;
};
_root.onMouseUp = function() {
  flagRecord = false;
};
// check if a path has been defined
if (arrXPos.length>0) {
  flagPlay = true;
}
// record or playback one frame at a time
_root.onEnterFrame = function() {
  // print out the path of the mouse
  if (flagPlay && i+1<arrXPos.length) {
    with (_root.clpDraw) {
    lineStyle(2, 0x000000, 100);
    moveTo(arrXPos[i], arrYPos[i]);
    lineTo(arrXPos[i+1], arrYPos[i+1]);
  }
  i++;
  } else {
    // record the current position of the mouse
    if (flagRecord) {
      trace("arrXPos["+i+"] = "+Math.round(_xmouse)+";");
      trace("arrYPos["+i+"] = "+Math.round(_ymouse)+";");
      i++;
    }
  }
};

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.