Child .swf problem
Hello I was hoping someone may be able to help me with a problem I have been having and unloading external .swfs, Ill try to explain this as best I can.
I have two .swf files, both of which are connected to an external .as file. One is the main, the other is the child being loaded into the main .swf file. The user clicks a button in the main .swf firing off a function contained in the .as file which loads the child .swf.
Now I have a boolean variable in the child .swf, that gets set to true at a certain part of the movie, this variable is then sent to the .as file, and caught firing off a function via ENTER_FRAME to unload the movie(unloadAndStop()). The problem I think I am having is the sprite container(which is being created in the .as file), is not being recognized as a child, thus will not unload. However if I create a CLICK MouseEvent, and aim it towards the sprite the unloadAndStop() function works fine, but would like to avoid this if possible. This is what I have in the .as file:
(endFind is the boolean value being set in the child .swf, and the loadSWF() is being called by a button in the main .swf)
import flash.events.Event;
var url:String = "objectSearch.swf";
var _Req:URLRequest = new URLRequest(url);
var _swfLoader:Loader = new Loader();
var _swfContent:Sprite = new Sprite();
var endFind:Boolean;
function loadSWF():void {
_swfLoader.load(_Req);
_swfContent.addChild(_swfLoader);
addChild(_swfContent);
setupListeners(_swfLoader.contentLoaderInfo);
}
function setupListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, addSWF);
}
function addSWF(event:Event):void {
event.target.removeEventListener(Event.COMPLETE, addSWF);
_swfContent = event.target.content;
}
function unloadSWF():void {
_swfLoader.unloadAndStop();
trace("unloadSWF: ",_swfLoader.unloadAndStop());
//!!!!!!removeChild is throwing ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.//!!!!!!
//removeChild(_swfContent);
//_swfContent = null;
}
//Adding a mouseEvent to the sprite seems to work ok
_swfContent.addEventListener(MouseEvent.CLICK,endCheck);
function endCheck(e:MouseEvent){
trace("click");
unloadSWF();
}
//This does not because of the unloadAndStop() method.
//addEventListener(Event.ENTER_FRAME,endCheck);
/*function endCheck(e:Event){
if(endFind==true){
unloadSWF();
}
}*/
if you need any more clarification please let me know. I greatly appreciate everybodys help and feedback.
