Hi,
I badly need someone help,Plzzzzzz
I am new to as3.
I have converted an As2 code into As3. Am not given any errors when exporting, but the final result is not the same as when I exported the coding in As2.
Can someone plzz plzz plzzz hlp me,this is for my final year project and am stuck with this part.
[U]As3:(What I did)[/U]
var mc5:redfish5=new redfish5();
addChild(mc5);
this.x = Math.floor(Math.random()* 550);
this.y = Math.floor(Math.random()* 400);
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
this.addEventListener(MouseEvent.CLICK, clickmovie);
var dy:int;
var dx:int;
var distance:int;
var angleToMouse:int;
var xVel:int;
var yVel:int;
this.xVel = 0;
this.yVel = 0;
var xAcc:int;
var yAcc:int;
this.xAcc = 0;
this.yAcc = 0;
function enterFrameHandler(event:Event):void
{
this.x += this.xVel;
this.y += this.yVel;
this.xVel += this.xAcc;
this.yVel += this.yAcc;
this.xVel *= 0.95;
this.yVel *= 0.95;
if (this.x > stage.width)
{
this.x -= stage.width;
} else if (this.x < 0)
{
this.x += stage.width;
}
if (this.y > stage.height)
{
this.y -= stage.height;
} else if (this.y < 0)
{
this.y += stage.height;
}
calcAcceleration();
}
function calcAcceleration():void
{
dx = this.mouseX - this.x;
dy = this.mouseY - this.y;
if (Math.abs(dx) > stage.width / 2)
{
if (dx > 0) {
dx -= stage.width;
} else {
dx += stage.width;
}
}
if (Math.abs(dy) > stage.height/2)
{
if (dy > 0) {
dy -= stage.height;
} else {
dy +=stage.height;
}
}
angleToMouse= Math.atan2(dy, dx);
distance = Math.sqrt(dx * dx + dy * dy);
this.xAcc = -100 * Math.cos(angleToMouse)/distance;
this.yAcc = -100 * Math.sin(angleToMouse)/distance;
}
function clickmovie(e:Event):void{
trace(“Mouse Click”);
}
As2 Code:
var mc5 = _root.attachMovie(“redfish5”, “p”+_root.getNextHighestDepth(), _root.getNextHighestDepth());
mc5._x = random(Stage.width);
mc5._y = random(Stage.height);
mc5.xVel = 0;
mc5.yVel = 0;
mc5.xAcc = 0;
mc5.yAcc = 0;
mc5.onEnterFrame = function()
{
this._x += this.xVel;
this._y += this.yVel;
this.xVel += this.xAcc;
this.yVel += this.yAcc;
this.xVel *= 0.95;
this.yVel *= 0.95;
if (this._x > Stage.width)
{
this._x -= Stage.width;
} else if (this._x < 0)
{
this._x += Stage.width;
}
if (this._y > Stage.height)
{
this._y -= Stage.height;
} else if (this._y < 0)
{
this._y += Stage.height;
}
this.calcAcceleration();
}
mc5.calcAcceleration = function()
{
var dx = _root._xmouse - this._x;
var dy = _root._ymouse - this._y;
if (Math.abs(dx) > Stage.width/2)
{
if (dx > 0) {
dx -= Stage.width;
} else {
dx += Stage.width;
}
}
if (Math.abs(dy) > Stage.height/2)
{
if (dy > 0) {
dy -= Stage.height;
} else {
dy += Stage.height;
}
}
var angleToMouse = Math.atan2(dy, dx);
var distance = Math.sqrt(dx*dx + dy*dy);
this.xAcc = -100 * Math.cos(angleToMouse)/distance;
this.yAcc = -100 * Math.sin(angleToMouse)/distance;
}
Plzzz help.
God Bless,thnxs…