大元件上面的小元件也可以飞
-
/**
-
* ...
-
* @author ...
-
*/
-
-
class CFSFlyWin extends MovieClip
-
{
-
var mChildArray:Array;
-
var mChildNameArray:Array;
-
var mChildTextArray:Array;
-
var mChildPosXArray:Array;
-
var mChildPosYArray:Array;
-
var mChildInterval:Number = 0;
-
var mTargetX:Number = 0;
-
var mTargetY:Number = 480;
-
var mSpeedX:Number = 0;
-
var mSpeedY:Number = 0;
-
var mPublicChildsX:Number = 0;
-
var mNewChildAddedNum:Number = 0;
-
var mChildsMaxLen:Number = 0;
-
var mFlyUnitNum:Number = 1; //parent本身就是1
-
var mFlyingUnitNum:Number = 0;
-
-
public function CFSFlyWin()
-
{
-
trace("CFSFlyWin()");
-
this._x = 0;
-
this._y = 960;
-
mChildArray = new Array();
-
mChildNameArray = new Array();
-
mChildTextArray = new Array();
-
mChildPosXArray = new Array();
-
mChildPosYArray = new Array();
-
}
-
-
public function setStartPos(x, y)
-
{
-
trace("CFSFlyWin setPos()");
-
this._x = x;
-
this._y = y;
-
}
-
-
public function setTargetPos(x, y)
-
{
-
trace("CFSFlyWin setTargetPos()");
-
this.mTargetX = x;
-
this.mTargetY = y;
-
}
-
-
public function addOneChild(elemName)//, textName, x, y)
-
{
-
if (mFlyingUnitNum > 0)
-
{
-
return;
-
}
-
mNewChildAddedNum = mNewChildAddedNum + 1;
-
mChildNameArray.push(elemName);
-
mFlyUnitNum = mFlyUnitNum + 1;
-
}
-
-
//mc是要执行fly动作的obj,x、y是起始地址,tX、tY是目标地址,
-
//times是帧数, 帧数=帧频*时间,比如flash 30帧/s,想用0.3秒执行fly动作,帧数=30*0.3=9
-
public function _mcFly(mc, x, y, tX, tY, times)
-
{
-
trace("CFSFlyWin _mcFly() " + mc);
-
-
if ((x == tX) && (y == tY))
-
{
-
return;
-
}
-
-
mc._x = x;
-
mc._y = y;
-
var speedX:Number = (tX - x) / times;
-
var speedY:Number = (tY - y) / times;
-
-
mc.onEnterFrame = function()
-
{
-
times = times - 1;
-
this._x = this._x + speedX;
-
this._y = this._y + speedY;
-
if (times <= 0)
-
{
-
this._x = tX;
-
this._y = tY;
-
-
if (mFlyingUnitNum == undefined)
-
{
-
_parent.mFlyingUnitNum = _parent.mFlyingUnitNum - 1;
-
}
-
else
-
{
-
mFlyingUnitNum = mFlyingUnitNum - 1;
-
}
-
-
mc.onEnterFrame = null;
-
}
-
}
-
}
-
-
//mc是要执行fly动作的obj,x、y是起始地址,tX、tY是目标地址,
-
//parent_frames是parent飞行帧数,child_interval是child飞行帧数差
-
public function mcFly(mc, x, y, tX, tY, parent_frames, child_interval)
-
{
-
trace("CFSFlyWin mcFly()");
-
if ((x == tX) && (y == tY) || (mFlyingUnitNum > 0))
-
{
-
return;
-
}
-
mFlyingUnitNum = mFlyUnitNum;
-
-
var child;
-
var child_x:Number = 0;
-
var child_y:Number = 0;
-
-
this._mcFly(mc, x, y, tX, tY, parent_frames);
-
-
for (var i = 0; i < mChildArray.length; i++)
-
{
-
child = this.mChildArray[i];
-
child_x = mChildPosXArray[i];
-
child_y = mChildPosYArray[i];
-
this._mcFly(child, child_x + x - tX, child_y + y - tY, child_x, child_y, parent_frames + child_interval*(i+1));
-
}
-
}
-
-
public function caculateInterval()
-
{
-
mChildInterval = this._height;
-
-
for (var i = 0; i < this.mChildArray.length; i++)
-
{
-
mChildInterval = mChildInterval - mChildArray[i]._height;
-
}
-
mChildInterval = mChildInterval / (mChildArray.length + 1);
-
}
-
-
public function loadChilds()
-
{
-
trace("CFSFlyWin loadChilds()");
-
if (mNewChildAddedNum <= 0)
-
{
-
trace("..........");
-
return;
-
}
-
-
for (var i = mChildArray.length; i < this.mChildNameArray.length; i++)
-
{
-
var child = attachMovie(this.mChildNameArray[i], "" + this + this.mChildNameArray[i], this.getNextHighestDepth());
-
mChildArray.push(child);
-
mChildPosXArray.push(0);
-
mChildPosYArray.push(0);
-
-
if (mChildsMaxLen < child._width)
-
{
-
mChildsMaxLen = child._width;
-
}
-
}
-
-
//计算各child间隔高度
-
caculateInterval();
-
-
//所有child以最大长度居中左对齐
-
mPublicChildsX = (this._width - mChildsMaxLen) / 2;
-
-
var yChild:Number = this.mChildInterval;
-
for (var i = 0; i < mChildArray.length; i++)
-
{
-
mChildArray[i]._x = mPublicChildsX;
-
mChildArray[i]._y = yChild;
-
mChildPosXArray[i] = mPublicChildsX;
-
mChildPosYArray[i] = yChild;
-
yChild = yChild + this.mChildInterval + this.mChildArray[i]._height;
-
}
-
-
//load完毕,新child数量重置为0
-
mNewChildAddedNum = 0;
-
}
-
}
改进版本,gameswf解析到c++可用,上面的flash里用as2.0可以跑,但是gameswf解析到c++里跑步起
-
/**
-
* ...
-
* @author ...
-
*/
-
-
class CFSFlyWin extends MovieClip
-
{
-
var mChildArray:Array;
-
var mChildNameArray:Array;
-
var mChildTextArray:Array;
-
var mChildPosXArray:Array;
-
var mChildPosYArray:Array;
-
var mChildInterval:Number = 0;
-
var mTargetX:Number = 0;
-
var mTargetY:Number = 480;
-
var mSpeedX:Number = 0;
-
var mSpeedY:Number = 0;
-
var mPublicChildsX:Number = 0;
-
var mNewChildAddedNum:Number = 0;
-
var mChildsMaxLen:Number = 0;
-
var misFlying:Boolean = false; //parent本身就是1
-
var mFlyFrames:Number = 0;
-
-
public function CFSFlyWin()
-
{
-
trace("CFSFlyWin()");
-
this._x = 0;
-
this._y = 960;
-
mChildArray = new Array();
-
mChildNameArray = new Array();
-
mChildTextArray = new Array();
-
mChildPosXArray = new Array();
-
mChildPosYArray = new Array();
-
}
-
-
public function setStartPos(x, y)
-
{
-
trace("CFSFlyWin setPos()");
-
this._x = x;
-
this._y = y;
-
}
-
-
public function setTargetPos(x, y)
-
{
-
trace("CFSFlyWin setTargetPos()");
-
this.mTargetX = x;
-
this.mTargetY = y;
-
}
-
-
public function addOneChild(elemName)//, textName, x, y)
-
{
-
if (this.misFlying == true)
-
{
-
return;
-
}
-
for (var i = 0; i < this.mChildArray.length; i++)
-
{
-
if (this.mChildArray[i].isFlying == true)
-
{
-
return;
-
}
-
}
-
-
mNewChildAddedNum = mNewChildAddedNum + 1;
-
mChildNameArray.push(elemName);
-
}
-
-
public function caculateInterval()
-
{
-
this.mChildInterval = this._height;
-
for (var i = 0; i < this.mChildArray.length; i++)
-
{
-
this.mChildInterval = this.mChildInterval - this.mChildArray[i]._height;
-
}
-
mChildInterval = mChildInterval / (mChildArray.length + 1);
-
}
-
-
public function loadChilds()
-
{
-
-
if (mNewChildAddedNum <= 0)
-
{
-
trace("..........");
-
return;
-
}
-
-
for (var i = mChildArray.length; i < this.mChildNameArray.length; i++)
-
{
-
var child = attachMovie(this.mChildNameArray[i], "" + this + this.mChildNameArray[i], this.getNextHighestDepth());
-
child._x = 0;
-
child._y = 0;
-
mChildArray.push(child);
-
mChildPosXArray.push(0);
-
mChildPosYArray.push(0);
-
-
if (mChildsMaxLen < child._width)
-
{
-
mChildsMaxLen = child._width;
-
}
-
}
-
-
//计算各child间隔高度
-
caculateInterval();
-
-
//所有child以最大长度居中左对齐
-
mPublicChildsX = (this._width - mChildsMaxLen) / 2;
-
-
var yChild:Number = this.mChildInterval;
-
for (var i = 0; i < mChildArray.length; i++)
-
{
-
mChildArray[i]._x = mPublicChildsX;
-
mChildArray[i]._y = yChild;
-
mChildPosXArray[i] = mPublicChildsX;
-
mChildPosYArray[i] = yChild;
-
yChild = yChild + this.mChildInterval + this.mChildArray[i]._height;
-
}
-
-
//load完毕,新child数量重置为0
-
mNewChildAddedNum = 0;
-
}
-
-
//mc是要执行fly动作的obj,x、y是起始地址,tX、tY是目标地址,
-
//times是帧数, 帧数=帧频*时间,比如flash 30帧/s,想用0.3秒执行fly动作,帧数=30*0.3=9
-
public function mcFly(x, y, tX, tY, frames)
-
{
-
if ((x == tX) && (y == tY) || (this.misFlying == true))
-
{
-
return;
-
}
-
-
this.misFlying = true;
-
-
this._x = x;
-
this._y = y;
-
this.mTargetX = tX;
-
this.mTargetY = tY;
-
this.mFlyFrames = frames;
-
this.mSpeedX = (this.mTargetX - this._x) / this.mFlyFrames;
-
this.mSpeedY = (this.mTargetY - this._y) / this.mFlyFrames;
-
-
this.onEnterFrame = function()
-
{
-
this.mFlyFrames = this.mFlyFrames - 1;
-
this._x = this._x + this.mSpeedX;
-
this._y = this._y + this.mSpeedY;
-
-
if (mFlyFrames <= 0)
-
{
-
this._x = this.mTargetX;
-
this._y = this.mTargetY;
-
this.misFlying = false;
-
this.onEnterFrame = null;
-
}
-
}
-
}
-
-
//mc是要执行fly动作的obj,x、y是起始地址,tX、tY是目标地址,
-
//parent_frames是parent飞行帧数,child_interval是child飞行帧数差
-
public function mcFlyAll(x, y, tX, tY, parent_frames, child_interval)
-
{
-
trace("CFSFlyWin mcFlyAll()");
-
if ((x == tX) && (y == tY) || (this.misFlying == true))
-
{
-
return;
-
}
-
-
for (var i = 0; i < this.mChildArray.length; i++)
-
{
-
if (this.mChildArray[i].isFlying == true)
-
{
-
return;
-
}
-
}
-
-
this.mcFly(x, y, tX, tY, parent_frames);
-
-
var child;
-
var child_x:Number = 0;
-
var child_y:Number = 0;
-
-
for (var i = 0; i < mChildArray.length; i++)
-
{
-
child = this.mChildArray[i];
-
child_x = mChildPosXArray[i];
-
child_y = mChildPosYArray[i];
-
child.mcFly(child_x + x - tX, child_y + y - tY, child_x, child_y, parent_frames + child_interval*(i+1));
-
}
-
}
-
}
阅读(1712) | 评论(0) | 转发(0) |