I have two buttons on main SWF what loads and Unload two external SWFs back and forth.
Also one timer function is calling external Screen saver SWF and unload the existing one when no interaction found.
I am using unloadAndStop() function to unload the external SWFs.
But after loading and unloading external SWFs, I am facing piling up or stack overflow problem.
Any help will be highly appreciated.
Thanks
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.MovieClip;
import caurina.transitions.*;
import flash.utils.Timer;
import flash.events.*;
var myLoader_Map_1:Loader = new Loader();
var myLoader_Map_2:Loader = new Loader();
var myLoader_Screen_Saver:Loader = new Loader();
var Ss:Boolean = false;
var Maps:Boolean = true;
//--------------------Screen Saver---------------------------------
ScreenSaver();
function ScreenSaver():void{
var url:URLRequest = new URLRequest("screensaver.swf");
myLoader_Screen_Saver.load(url);
addChild(myLoader_Screen_Saver);
setChildIndex(myLoader_Screen_Saver, 1);
Maps = false;
Ss = true;
}
function ScreenSaver_Unload():void{
myLoader_Screen_Saver.unloadAndStop();
}
//--------------------Map Buttons---------------------------------
function MPstart():void{
Tweener.addTween(MC_Maps_Btns,{alpha:1, x:778.25, y:1070.65, time:1, delay:1, transition:"easeOutCubic"});
setChildIndex(MC_Maps_Btns, 2);
MC_Maps_Btns.Btn_Map_1.visible = true;
MC_Maps_Btns.Btn_Map_2.visible = true;
}
function MPclose():void{
Tweener.addTween(MC_Maps_Btns,{alpha:0, x:778.25, y:1179.85, time:1, transition:"easeOutCubic"});
}
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_1.addEventListener(MouseEvent.CLICK,OpenMap1);
function OpenMap1(e:MouseEvent):void{
var url:URLRequest = new URLRequest("Map_1.swf");
myLoader_Map_1.load(url);
myLoader_Map_1.alpha = 1;
addChild(myLoader_Map_1);
setChildIndex(myLoader_Map_1, 2);
myLoader_Map_2.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_1.visible = false;
MC_Maps_Btns.Btn_Map_2.visible = true;
}
//--------------------Map 1 ---------------------------------
MC_Maps_Btns.Btn_Map_2.addEventListener(MouseEvent.CLICK,OpenMap2);
function OpenMap2(e:MouseEvent):void {
var url:URLRequest = new URLRequest("Map_2.swf");
myLoader_Map_2.load(url);
myLoader_Map_2.alpha = 1;
addChild(myLoader_Map_2);
setChildIndex(myLoader_Map_2, 2);
myLoader_Map_1.unloadAndStop();
ScreenSaver_Unload();
Maps = true;
Ss = false;
MC_Maps_Btns.Btn_Map_2.visible = false;
MC_Maps_Btns.Btn_Map_1.visible = true;
}
//--------------------Timer ---------------------------------
var inactiveTime:int = 10000;
var t:Timer = new Timer(inactiveTime);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown1);
t.addEventListener(TimerEvent.TIMER, onTimer);
t.start();
function onMouseDown1(e:MouseEvent):void {
t.reset();
t.start();
trace("Interaction detected");
}
function onTimer(e:TimerEvent):void {
handleInactivity();
}
function handleInactivity():void {
trace('You\'re inactive.');
if (Maps == true){
myLoader_Map_1.unloadAndStop();
myLoader_Map_2.unloadAndStop();
}
else{
trace("No Maps");
}
if (Ss == false ){
ScreenSaver();
MPclose();
}
else{
trace("ScreenSaver already loaded");
}
}