vasion
vasion

Reputation: 1247

reference parent class function in AS 3.0

I am trying to run a function of the main class, but even with casting it does not work. I get this error

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at rpflash.communication::RPXMLReader/updateplaylist()
at rpflash.communication::RPXMLReader/dataHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::XMLSocket/scanAndSendEvent()

this is the main class code

package{
import flash.display.MovieClip;
import rpflash.communication.RPXMLReader;

public class Main extends MovieClip{

    var reader:RPXMLReader = new RPXMLReader(); 

    public function Main(){
        trace('Main actionscript loaded');

        }

    public function test(){
        trace('test worked');}

}
}

and this is the function trying to call it:

private function updateplaylist(){
        //xml to string
        var xmls:String= xml.toXMLString();
        trace('playlist updated debug point');
        MovieClip(this.parent).test();}

what am i doing wrong?

Upvotes: 1

Views: 448

Answers (2)

Allan
Allan

Reputation: 3314

The reader class is not part of the display list, to add something to a display list you need to call addChild on the soon to be parent display object and pass the soon to be child display object as the parameter.

In any case this is a really bad way to try and communicate between classes. Really you should be dispatching an event from the RPXMLReader and then listen for it in your Main class.

Upvotes: 1

Reuben
Reuben

Reputation: 1202

It looks like your RPXMLReader doesn't have a parent... assuming RPXMLReader extends MovieClip (or Sprite, or DisplayObject etc), you need to add it as a child of your Main class - otherwise its parent property will be null:

public class Main extends MovieClip{
     var reader:RPXMLReader = new RPXMLReader(); 

    public function Main(){
        addChild(reader);
    }...

Upvotes: 1

Related Questions