This is my setup:
1) Main timeline (I will call "game.swf") loads another flash movie (I will call room.swf)
2) using a series of addChilds, a function in game.swf sets the draw order of all of the items in the scene. This includes the background room that was contained in room.swf, the main character, the custom mouse pointers and so on.
3) there is an array in room.swf that has a list (I will call "FGitemsArray") of all of the items that should be drawn in front of the main character - like for instance there is a plant in the room and when the main character walks across the room I want him to appear behind it, despite the fact that it was loaded in a separate movie - I was delighted to find out that I could call addChild on everything in FGitemsArray from game.swf and the draw order would just work.
4) I want some of the items in room.swf to be able to call functions on the main timeline when they are clicked on. If an items is not in FGitemsArray, it is added to the display list by virtue of the fact that it is contained in room.swf. So this line of code embedded in an object in room.swf that looks like this:
(root.loaderInfo.loader.root as Object).showArrayEnd();
works just fine.
5) however when I set an item to be a foreground item, adding it to the display list separate from the room it's in I get the classic:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
6) if the item is not set to be a foreground object then I can use the previously mentioned reference to root.loaderInfo.loader.root just fine. It took me a while to figure out that this was the problem.
7) I obviously can't remove (root.loaderInfo.loader.root as Object) from the foreground object in room.swf, as the movie won't compile cause it can't find showArrayEnd().
8) how do I fix this.