淘宝flash查看图片代码 教程
淘宝flash查看图片代码 教程
代码如下:
/*作者:梦自在*/
var count_num:Number = 1;
var depth_num1:Number = 0;
var depth_num2:Number = 1.5;
/*画线*/
var isStates:Boolean=false;
/*创建遮照容器*/
var drawing:Boolean = true;
/*经过的时间*/
var time_num:Number = 0;
/*第几次按*/
var press_num:Number = 0;
var container_width:Number;
var container_height:Number;
onEnterFrame = function () {
/*drawing为真就画线*/
if (drawing) {
this.createEmptyMovieClip("container", depth_num1);
this.createEmptyMovieClip("mask", depth_num2);
pic_mc.setMask(container);
drawing = false;
depth_num1 += 1;
depth_num2 += 1;
}
};
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
/*第一次按下的时候*/
if (press_num == 0) {
isStates = true;
x0 = _root._xmouse;
y0 = _root._ymouse;
time_num = getTimer();
/*没碰到container按下*/
if (!container.hitTest(_root._xmouse, _root._ymouse)) {
press_num = 1;
}
}
if (press_num == 1) {
/*没碰到container第二次按下*/
if (!container.hitTest(_root._xmouse, _root._ymouse)) {
/*时间间隔小于100毫秒*/
if (getTimer()-time_num<100) {
count_num = 1;
press_num = 0;
/*如果执行count_num == 2步后再双击重来就要删去上面遮照的东西*/
for (var i in mask) {
mask[i].removeMovieClip();
}
} else {
/*时间间隔大于100毫秒就重新开始计算双击的间隔*/
press_num = 0;
}
}
}
};
mouseListener.onMouseMove = function() {
if (isStates) {
/*第一次按下移动就画个正方形*/
if (count_num == 1) {
var i = containner.getNextHighestDepth();
container.createEmptyMovieClip("mc"+i, i);
with (container["mc"+i]) {
lineStyle(2, 0x000000, 100);
beginFill(0x000000, 100);
moveTo(x0, y0);
x1 = _root._xmouse;
y1 = _root._ymouse;
lineTo(x1, y0);
lineTo(x1, y1);
lineTo(x0, y1);
lineTo(x0, y0);
endFill();
}
container_width = container["mc"+i]._width;
container_height = container["mc"+i]._height;
}
/*第二次按下移动就开始查除正方形*/
if (count_num == 2) {
var mask_depth:Number = mask.getNextHighestDepth();
mask.attachMovie("ball", "ball"+mask_depth, mask_depth);
mask["ball"+mask_depth]._x = _root._xmouse;
mask["ball"+mask_depth]._y = _root._ymouse;
}
/*第三次按下移动就拖动正方形*/
if (count_num == 3) {
container._x = mask._x=_root._xmouse-container._height;
container._y = mask._y=_root._ymouse-container._width;
}
/*第四次按下移动就开始缩放正方形*/
if (count_num == 4) {
mask._xscale = container._xscale=100*(_root._xmouse-container._x)/container_width;
mask._yscale = container._yscale=100*(_root._ymouse-container._y)/container_height;
}
}
};
mouseListener.onMouseUp = function() {
isStates = false;
count_num += 1;
/*到第5次后就重新开始画*/
if (count_num == 5) {
count_num = 0;
drawing = true;
}
};
Mouse.addListener(mouseListener);
补充:flash教程,动画技术