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
import flash.events.Event;
import classes.TestMover;
addEventListener(Event.ENTER_FRAME,Test);
function Test(event:Event) {
TestMover.WhatThe();
}
And the class itself:
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:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at classes::TestMover$/WhatThe()
at TestingClasses_fla::TestCube_1/Test()