I have a Harbor_mc.AS file which adds several ship_mc's dynamically to its container on stage making sure I used a listener for ADD_TO_STAGE. From the Main Timeline the user inputs a name in a input textfield for his ship which calls a public function ShipBuy decalred in the Harbor_MC. This accepts the String argument. The only way I could get this function to work as public was placing it outside the harbor_mc function:
Code:
package {
import flash.display.*;
import flash.text.*;
import flash.events.*;
import Ship;
public class HarborFleet_MC extends Sprite {
//variables go here
public function HarborFleet_MC( ) {
//all dynamically added mc's done here with their addedEventListeners
//and functions
}
public function ShipBuy(playerShipName:String):void {
shipLabel_txt.text = playerShipName;
ship_mc.removeEventListener(MouseEvent.CLICK, onClick); //not working!
}
}
}
from main timline:
Code:
MovieClip(root).harbor_mc.portFleet.onShipBuy(shipName); //this works
It seems that I can access all variables declared above but cannot remove listeners from mc's. As a test I removed listeners inside the public function HarborFleet( ) brackets and it works but from the public function ShipBuy it gives me the grey screen of death.
1. How do I make a publicly accessible function within the class Harbor_MC function?
2. Or how to remove the listeners from mc's from a public function declared outside of the main function?
I hope I am making this clear while tying to keep this brief on the concept.
Basically I want the user to click on various mc's placed on the stage via external AS, view them, buy one of them, rename it and send the name back to Harbor_MC where the unselected mc's have their addEventListeners removed but still be on the stage.
Thanks in advance for gotcha's I'm missing or a better solution all-together.