# Executing a function in a class from timeline

**URL:** <https://forum.kirupa.com/t/executing-a-function-in-a-class-from-timeline/325632>\
**Category:** flash\
**Created:** [October 27, 2011, 12:41am UTC](https://forum.kirupa.com/t/executing-a-function-in-a-class-from-timeline/325632 "2011-10-27T00:41:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Setup56](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@Setup56](https://forum.kirupa.com/u/Setup56)\
**Post date:** [October 27, 2011, 12:41am UTC](https://forum.kirupa.com/t/executing-a-function-in-a-class-from-timeline/325632/1 "2011-10-27T00:41:43Z")

</div>

I have a class called TestMover and it has a function in it which changes its X position. I would like to execute that function from the main timeline. It worked when I used static function but it threw an error when I tried to change the value of X.

Here is what I tried based on a tutorial I found, it does not work:

TestingClasses.fla

```auto
import flash.events.Event;
import classes.TestMover;

addEventListener(Event.ENTER_FRAME,Test);

function Test(event:Event) {
    TestMover.WhatThe();

}

```

And the class itself:

```auto
package classes {
    
    import flash.display.MovieClip;
    
    import flash.events.Event;
    //import classes.TestCustomEvent;    
    

    public class TestMover extends MovieClip {
        
        public static var _INSTANCE:TestMover;
        
        public static var thisX:Number = 0;

        public function TestMover() {
            
            addEventListener(Event.ENTER_FRAME,Test);
            
            
        }
        
        public function Test(event:Event) {
            x=thisX;
            
        }
        
        
        public static function WhatThe() {
            _INSTANCE.x+=10;
            
            
            
        }
        
        public function Test2() {
            trace ("JACK");
            
        }
    }
    
}

```

What I need to achieve is that when you call the “WhatThe()” function from main timeline, it will move the movieclip this class is attached to on its X axis by a value of 10.

It must also be possible to call an internal function (like Test2()) from the WhatThe() function, right now when I did that it threw an error.

Error this code throws:

```auto
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at classes::TestMover$/WhatThe()
    at TestingClasses_fla::TestCube_1/Test()

```
