Issue

When loading custom classes on the Stage or as a document class, TLF throws reference errors. Below is an example of a possible reference error that you can encounter.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at cursor()
    at flash.display::Sprite/constructChildren()
    at flash.display::Sprite()
    at flash.display::MovieClip()
    at start_fla::MainTimeline()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at start_fla::MainTimeline/frame1()

Solution

Make sure that you use the Event.ADDED_TO_STAGE event properly during the application initialization.

Correct

public function cursor() {
    // constructor code
    stop();
    addEventListener(Event.ADDED_TO_STAGE, Init);
}

private function Init(e:Event){
    removeEventListener(Event.ADDED_TO_STAGE, Init);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, followMouse);
    stage.addEventListener(MouseEvent.MOUSE_DOWN, shotFood);
}

Incorrect

public function cursor() {
    // constructor code
    stop();
    stage.addEventListener(MouseEvent.MOUSE_MOVE, followMouse);
    stage.addEventListener(MouseEvent.MOUSE_DOWN, shotFood);
} 

Keywords: cpsid_83815

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy