By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,027 Members | 841 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,027 IT Pros & Developers. It's quick & easy.

can you help make this drive() function work?

saputello
P: 9
hello, hello, hello

can anyone see the problem with this drive() function? i can't get it to work!

class Car {
// properties
public var mc:MovieClip;
private var acceleration:Number;
private var topSpeed:Number;
private var currentSpeed:Number;

public function Drive() {
if (currentSpeed<topSpeed) {
currentSpeed += acceleration;
mc._x -= currentSpeed;


} else if (currentSpeed>=topSpeed) {
currentSpeed == topSpeed;
}
}
/* ------------------------------------------------------------ */

// constructor
public function Car() {
var currentSpeed = 0;
var acceleration = Math.floor(Math.random()*3)+3;
var topSpeed = Math.floor(Math.random()*50)+50;

}
}


here's the script i have attached to the 1st frame of the movie:


var redCar:Car = new Car();
var yellowCar:Car = new Car();
var blueCar:Car = new Car();


// assign a movieclip to each car
redCar.mc = redCar_mc;
yellowCar.mc = yellowCar_mc;
blueCar.mc = blueCar_mc;


// go button functionality
go_btn.onRelease = function() {
_root.onEnterFrame = function() {
// tell all cars to Drive() forward, until one wins
redCar.Drive();
blueCar.Drive();
yellowCar.Drive();

if (redCar.mc._x <= finishLine_mc._x) Win("Red car");
if (blueCar.mc._x <= finishLine_mc._x) Win("Blue car");
if (yellowCar.mc._x <= finishLine_mc._x) Win("Yellow car");

}
}


function Win(whichCar:String) {
// stop all cars
_root.onEnterFrame = null;

// disable Go button
go_btn.onRelease = null;

// declare the victor!
win_txt.text = whichCar + " is the winner!";



thank you thank you thank you!
Apr 14 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.