恩, 替楼主完善一点代码, 顺便发现了flash cs3脚本解释器的一个bug
flash 效果不错, 但编码上有点漏洞, 导致如果因为rollover使mc移动而触发rollout事件, 同时因为rollout而又引起相邻的mc的rollover事件, 从而这两个mc开始疯狂跳动。 以下代码增加了一点逻辑处理这种情况, 效果看上去好些了; 同时发现cs3脚本引擎一个bug, 多半是player 线程同步没有做好, 脚本设置 enable = false后, 在极短时间内, mc仍然可接收到事件通知, 从而导致无法预见的后果, 因此代码内增加了额外判断以修补这个bug.
4年多没有玩flash了, 今天玩得还算尽兴, 呵呵。
var myXML = new XML();
var onIndex = -1;
myXML.ignoreWhite = true;
myXML.load("Photos.xml");
myXML.onLoad = function(success) {//装载xml文件
if (success) {
var myList = myXML.firstChild.childNodes;
var PhotoNum=myList.length-1;
var vx=30,vy=20,va=.9,vs=.96;
var vxs=50,vys=100,vas=100,vss=100;
for(i=0;i<=PhotoNum;i++)
{
_root.attachMovie("MC_photo","MC_photo"+i, 100-i);
setProperty("MC_photo"+i,_x,vxs);
setProperty("MC_photo"+i,_y,vys);
//setProperty("MC_photo"+i,_alpha,vas);
setProperty("MC_photo"+i,_xscale,vss);
setProperty("MC_photo"+i,_yscale,vss);
_root["MC_photo"+i].LoadName=myXML.childNodes[0].childNodes.attributes.imgURL;
_root["MC_photo"+i].gotoAndStop(2);
_root["MC_photo"+i].tx=_root["MC_photo"+i]._x;
_root["MC_photo"+i].ty=_root["MC_photo"+i]._y;
_root["MC_photo"+i].ts=_root["MC_photo"+i]._xscale;
_root["MC_photo"+i].td=100-i;
_root["MC_photo"+i].onRollOver=function()
{
// cs 3 bug, 设置enable = false后极短时间内仍然可接收到事件通知, 因此会进入到这里, 把 onEnterFrame 指针给改掉, 因此必须加以判断进行保护
if(!this.enabled){
return;
}
this.onEnterFrame=function()
{
if(onIndex != -1 && onIndex != this){
onIndex.onRollOut();
}
onIndex = this;
d=this.tx+100*(this._xscale/100)-this._x;
if(d<=0.1){
delete this.onEnterFrame;
if(onIndex == this){
onIndex = -1;
}
}
this._x+=d/4;
}
}
_root["MC_photo"+i].onRollOut=function()
{
if(!this.enabled){
return;
}
this.onEnterFrame=function()
{
d=this.tx-this._x;
if(Math.abs(d)<=0.1){delete this.onEnterFrame; }
this._x+=d/30;
}
}
_root["MC_photo"+i].onPress=function()
{
this.enabled=false;
trace(this + "1");
this.swapDepths(101)
this.onEnterFrame=function()
{
dx=300-this._x;
dy=120-this._y
if(Math.abs(dx)<=0.1 and Math.abs(dy)<=0.1)
{
if(Math.abs(200-this._xscale)<1)
{
delete this.onEnterFrame;
this._xscale=200;
this._yscale=200;
this.onMouseDown=function()
{
delete this.onMouseDown;
this.onEnterFrame=function()
{
if(Math.abs(this._x-this.tx)<.1 and Math.abs(this._y-this.ty)<.1)
{
delete this.onEnterFrame;
this.swapDepths(this.td);
this.enabled=true;
}
this._x+=(this.tx-this._x)/2
this._y+=(this.ty-this._y)/2
this._xscale+=(this.ts-this._xscale)/2;
this._yscale+=(this.ts-this._yscale)/2;
}
}
}
this._xscale+=(200-this._xscale)/2;
this._yscale+=(200-this._yscale)/2;
}
this._x+=dx/2
this._y+=dy/2
}
}
vx*=1;
vy*=0.65;
vxs+=vx;
vys-=vy;
vas*=va;
vss*=vs;
}
}
else
{
trace("Error!!!");
}
}