# Took working code from timeline 2 external class and now trouble

**URL:** <https://forum.kirupa.com/t/took-working-code-from-timeline-2-external-class-and-now-trouble/308733>\
**Category:** Uncategorized\
**Created:** [April 29, 2010, 2:54am UTC](https://forum.kirupa.com/t/took-working-code-from-timeline-2-external-class-and-now-trouble/308733 "2010-04-29T02:54:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rimacy](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@rimacy](https://forum.kirupa.com/u/rimacy)\
**Post date:** [April 29, 2010, 2:54am UTC](https://forum.kirupa.com/t/took-working-code-from-timeline-2-external-class-and-now-trouble/308733/1 "2010-04-29T02:54:49Z")

</div>

[COLOR=Navy]Hi guys,

I had this ship working in the timeline and then took it into an .as file for a custom class and now it won’t work…  
it is saved as Ship.as  
[/COLOR]

> public class Ship extends MovieClip  
> {  
> public function Ship():void  
> {

```
            var gravityConstant:Number=0;
            var uForce:Number=0;
            var lForce:Number=0;
            var rForce:Number=0;
            this.addEventListener(KeyboardEvent.KEY_DOWN,moveShip);

            this.addEventListener(Event.ENTER_FRAME, addForceVectors)
            function addForceVectors(event:Event)
                {
                    this.x +=rForce-lForce;
                    this.y +=gravityConstant -uForce;
                    gravityConstant +=.1;
                    if (gravityConstant&gt;15)
                        {
                            gravityConstant=15;
                        }
                    if (uForce&gt;0)
                        {
                            uForce=(uForce-(uForce*.25));//diminishThrustMomentum
                        }
                    if(uForce&gt;gravityConstant)
                        {
                            gravityConstant=0;//lets thrust momentum occur
                        }
        
                    trace(this.gravityConstant)
                    trace(this.uForce)
                }

            function moveShip(evt:KeyboardEvent):void
                {
                    switch (evt.keyCode)
                        {
                            case Keyboard.UP:
                                uForce +=5;
                                burn();
                                break;
            
                            case Keyboard.LEFT:
                                lForce +=1;
                                burn();
                                break;
                            case Keyboard.RIGHT:
                                rForce+=1;
                                burn();
                                break;
                            default:
                                trace("keyCode:",evt.keyCode);
                        }
    

                }
            function burn():void
                {
                trace("burn")
                }
            }
}

```

}  
[COLOR=Navy]the traces are coming up undefined with no errors  
the timeline frame 1 actions code is…[/COLOR]

> var ship\_mc:Ship= new Ship;  
> addChild (ship\_mc);
