用了BitmapData.getPixel();来做的.原理:路径为一像素的纯色的不规则的曲线(如红色),用getPixel();记录曲线上的所有坐标.
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
import flash.display.BitmapData;
import flash.geom.Point;
var pointArr:Array = [];
var ypos:Number = 200;
var curve:MovieClip = this.createEmptyMovieClip("curve", 10);
with (curve) {
lineStyle(1, 0xFF0000);
moveTo(0, ypos);
for (var i:Number = 0; i<550; i += 6) {
lineTo(i, ypos+i/10*Math.sin(i/20));
}
}
var X:Number = curve._width;
var Y:Number = ypos+curve._height;
var copyBitmap:BitmapData = new BitmapData(X, Y, true, 0);
copyBitmap.draw(curve);
var color:Number = Number(0xFF0000);
for (var i:Number = 0; i<X; i += 10) {
for (var j:Number = 0; j<Y; j++) {
if (copyBitmap.getPixel(i, j) == color) {
pointArr.push(new Point(i, j));
break;
}
}
}
copyBitmap.dispose();
var ball:MovieClip = this.createEmptyMovieClip("ball", 20);
with(ball){
lineStyle(20);
moveTo(0, 0);
lineTo(.2, 0);
}
this.onEnterFrame = function() {
ball._x = pointArr[0].x;
ball._y = pointArr[0].y-10;
pointArr.shift();
if (pointArr.length == 0) {
delete this.onEnterFrame;
trace("over");
}
};