I did a lot of search and can't find the answer, please kindly help me. So I created one flash game called Snake Games and then another Flash which I use UILoader to load the snake game, however when I try to run that Flash game and check whether that flash will load the snake game, I encountered error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main/addFood()
at Main/init()
at Main()
Here's the Main.as script inside the Snake Games http://pastebin.com/raw/Z5ZBtLQn
Please kindly help me.
Thank you.
In your case the source of null error is "Stage is unavailable". You need to alter your snake game constructor to first check stage, then call init()
like this:
public function Main(){
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE,init);
}
function init(e:Event=null):void {
removeEventListener(Event.ADDED_TO_STAGE,init);
// rest of init() code