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?
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);
}...
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.
精彩评论