0
votes

I'm attempting to set up a saving and loading system for a flash game I am creating. At the moment I decided to attempt to get the Save File Selection part of my new game menu to work before I proceeded any further with it. I drew up the 'DifficultySelect' screen (which contains save file selection as well as a few other things) in flash, then converted it into a symbol. I made 10 save file symbols inside of this, and created base actionscript files for them. The entire 'DifficultySelect' becomes a child of my 'Main.as' once you proceed through the title screen. I am trying to have my save file data inside of my Main.as, such as levels, health, progress, etc, as well as which save file is currently in use. However, I am unable to create a way for my Main.as to access a MouseClick function for the save file, as I can't simply have a Savefile0.MouseEvent.CLICK event in my Main.as file, as I am not creating a variable to add it to the stage.

I suppose the tl;dr question version of my situation is: How can I get my Main.as to activate one of its functions when SaveFile0 has been clicked? Also, how do I refer to a child from a parent class?

2

2 Answers

0
votes

You ask how to refer to a child from parent, but since the child usually "knows" its parent, I suggest following solution:

Your child (SaveFile) should listen for the event (MouseEvent). Once the event is dispatched, you have two options. Either you can dispatch a custom event on parent or directly invoke a public function of the parent.

0
votes

This is assuming your SaveFile is a MovieClip added to Main:

Inside SaveFile:

var _parentMC:MovieClip = this.parent as MovieClip;
_parentMC.functionToCall();

The best practice, however is to dispatch a custom event in SaveFile, and listen for it in main:

Inside SaveFile:

var customEvent:Event = new Event("customEvent");
this.dispatchEvent(customEvent);

Inside Main:

saveFile.addEventListener("customEvent",functionToCall();

functionToCall(e:Event):void{

}