下面时课件《认识时分》的一个环节,要求将上方带时刻的图标拖动到钟面上,并判断正确与否,如果正确显示红勾并播放短暂悦耳音乐,如果错误则自动返回到原来的位置上。
课件《认识时分》
FlASH实现拖动并判断区域是否正确代码如下:
var n:Number = 0;
var c:Number = 0;
for (var d:Number = 5; d>0; d--) {
this["mc"+d].xpos = this["mc"+d]._x;
this["mc"+d].ypos = this["mc"+d]._y;
this["mc"+d].num = d;
this["mc"+d].onPress = function() {
n = this.num;
delete this.onEnterFrame;
this.startDrag();
c=1;
};
}
onMouseUp = function () {
stopDrag();
if (this["mc"+n].hitTest(this["a_mc"+n])) {
if(c==1)
{
attachMovie("g_mc", "g_mc", 100, {_x:this["a_mc"+n]._x, _y:this["a_mc"+n]._y});
c=0;
} }else {
c=0;
this["mc"+n].onEnterFrame = function() {
this._x += (this.xpos-this._x)/5;
this._y += (this.ypos-this._y)/5;
Math.abs(this.ypos-this._y)<1 ? delete this.onEnterFrame : Thank~u;
};
};
};