Hey, everyone
I’m trying to migrate some stuff to AS 3.0 but there are some things I can’t figure out how to do in 3.0.
I’ve found out how to declare a function (In AS 2.0, I used somename = function(){stuff})
However, I can’t figure out how to make the function work as a 1-time thing (or in an “if” statement). I can do onEnterFrame, but not much else.
This code is in the frame of a movieclip on the stage.
//Variable Declarations
var t0:Number = getTimer()/1000;
var t:Number;
var thisy:Number = 0;
var vy:Number;
var vy0:Number = 0;
var y0:Number = 0;
var ymin:Number = 350;
//**Function Declarations**
//Gravity Variable Reset
**function resetytime (event:Event) {
vy0 = (980 * t - vy0) *.5;
t0 = getTimer () / 1000;
y0 = ymin;
if (vy0 < 20) {
this.y = ymin;
removeEventListener (Event.ENTER_FRAME, gravitate);
}
}**
//Move Object downward
function gravitate (event:Event) {
t = (getTimer () / 1000) - t0;
thisy = 490 * t * t - vy0 * t + y0;
if (thisy >= ymin) {
**vy0 = (980 * t - vy0) *.5;
t0 = getTimer () / 1000;
y0 = ymin;
if (vy0 < 20) {
this.y = ymin;
removeEventListener (Event.ENTER_FRAME, gravitate);
}**
}
this.y = thisy;
}
//Actions
addEventListener (Event.ENTER_FRAME, gravitate);
link to the fla: http://www.freewebs.com/gathalimay/Gravity.fla[URL=“http://www.freewebs.com/gathalimay/Gravity.fla”]
link to the swf: http://www.freewebs.com/gathalimay/Gravity.swf
The code works as it is now, but I want to swap out the bolded parts in the “gravitate” function by dispatching the “resetytime” function instead. How can I do this?
Thanks in advance!