2 Replies Latest reply on Aug 29, 2010 10:13 AM by Fumph

    display current speed

    Fumph Level 1

      I have actionscript to control my car. It uses the arrow keys for steering and exceleration and braking. What my question is, do you know how to display my cars current speed. If you want to see my code just ask. Thank you!

        • 1. Re: display current speed
          Ned Murphy Adobe Community Professional & MVP

          You need to show your code if you want someone to help with it.

          • 2. Re: display current speed
            Fumph Level 1

            heres the code on my car:

             

            onClipEvent (load)
            {
                var speed = new Number(0);
                _root.createEmptyMovieClip("drawing", 1);
                this.swapDepths(_root.drawing);
                _root.clearBtn.swapDepths(this);
                hi = Math.sin(_rotation * 1.745329E-002) * 10;
                ip = Math.cos(_rotation * 1.745329E-002) * 10;
                iks = _x - ip;
                ips = _y - hi;
                iks2 = _x + ip;
                ips2 = _y + hi;
            }
            onClipEvent (enterFrame)
            {
                if (Key.isDown(38) & !Key.isDown(17))
                {
                    speed = speed + 1.500000E+000;
                } // end if
                if (Key.isDown(40) & !Key.isDown(17))
                {
                    speed = speed - 7.500000E-001;
                } // end if
                if (Key.isDown(17))
                {
                    speed = speed - speed / 10;
                    if (Key.isDown(39))
                    {
                        setProperty("", _rotation, _rotation + speed / 2);
                    } // end if
                    if (Key.isDown(37))
                    {
                        setProperty("", _rotation, _rotation - speed / 2);
                    } // end if
                } // end if
                if (Key.isDown(39))
                {
                    if (speed < 5 && speed >= 0)
                    {
                        setProperty("", _rotation, _rotation + 2 * speed);
                    }
                    else if (speed < 0)
                    {
                        setProperty("", _rotation, _rotation + 7.500000E+000 * speed / 15);
                    }
                    else
                    {
                        setProperty("", _rotation, _rotation + 7.500000E+000);
                    } // end else if
                    speed = speed * 9.500000E-001;
                } // end if
                if (Key.isDown(37))
                {
                    if (speed < 5 && speed >= 0)
                    {
                        setProperty("", _rotation, _rotation - 2 * speed);
                    }
                    else if (speed < 0)
                    {
                        setProperty("", _rotation, _rotation - 7.500000E+000 * speed / 15);
                    }
                    else
                    {
                        setProperty("", _rotation, _rotation - 7.500000E+000);
                    } // end else if
                    speed = speed * 9.500000E-001;
                } // end if
                if (Math.abs(speed) > 20)
                {
                    speed = 20;
                } // end if
                if (speed < -10)
                {
                    speed = -10;
                } // end if
                speed = speed * 9.800000E-001;
                g = Math.sin(_rotation * 1.745329E-002) * speed;
                m = Math.cos(_rotation * 1.745329E-002) * -speed;
                setProperty("", _x, _x + g);
                setProperty("", _y, _y + m);
                hi = Math.sin(_rotation * 1.745329E-002) * 10;
                ip = Math.cos(_rotation * 1.745329E-002) * 10;
                _root.k1 = hi;
                _root.k2 = ip;
                if (Key.isDown(17))
                {
                    _root.drawing.lineStyle(3, 0x000000, 95);
                }
                else
                {
                    _root.drawing.lineStyle(3, 0x888888, 80);
                } // end else if
                //delete remaining forward slashes below to leave tire tracks
                _root.drawing.moveTo(iks, ips);
                _root.drawing.lineTo(_x - ip, _y - hi);
                _root.drawing.moveTo(iks2, ips2);
                _root.drawing.lineTo(_x + ip, _y + hi);
                iks = _x - ip;
                ips = _y - hi;
                iks2 = _x + ip;
                ips2 = _y + hi;
            }

             

            Ok so theres my car code, again on my frame I want to display the current speed of my car.