Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 Unloading external SWF piling up problem

New Here ,
Jun 24, 2014 Jun 24, 2014

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");

  }

  

  

  }

TOPICS
ActionScript
700
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2014 Jun 24, 2014

apply unloadAndStop() to all your loaders just prior to executing all loads:

function unloadAllF():void{

if(loader1.content){

loader1.unloadAndStop();

}

//etc

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2014 Jun 24, 2014

Thanks Kglad for your time and quick reply.

I have just tried this, but due to limited knowledge of AS3  I am sure I am doing something wrong.

can you please explain in the code above where and how should I apply this function?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2014 Jun 24, 2014

just prior to executing all loads:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2014 Jun 24, 2014

This is how I applied

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---------------------------------

function unloadAllF():void{

if(myLoader_Screen_Saver.content){

myLoader_Screen_Saver.unloadAndStop();

trace("ss unloaded");

}

if(myLoader_Map_1.content){

myLoader_Map_1.unloadAndStop();

trace("map_1 unloaded");

}

if(myLoader_Map_2.content){

myLoader_Map_2.unloadAndStop();

trace("map_2 unloaded");

}

//etc

}

ScreenSaver();

  function ScreenSaver():void{

  var url_ss:URLRequest = new URLRequest("screensaver.swf");

  unloadAllF();

  myLoader_Screen_Saver.load(url_ss); 

  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_map_1:URLRequest = new URLRequest("Map_1.swf");

  unloadAllF();

  myLoader_Map_1.load(url_map_1);

  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_map_2:URLRequest = new URLRequest("Map_2.swf");

  unloadAllF();

  myLoader_Map_2.load(url_map_2);

  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");

  }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 24, 2014 Jun 24, 2014

you need to add all your loaders to unloadAllF and you need to remove the other unloadAndStops.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2014 Jun 25, 2014

I have tried as suggested, applied unloadAllF prior to all loaders and call this function inside the button function just before loader and removed all other unloadAndStops, but still problem is there.

Also then added all loaders inside unloadAllF  function but no success.


Is there something I have to stop, remove or unload from loaded SWFs first?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2014 Jun 25, 2014

copy your code and paste it here.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2014 Jun 25, 2014

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 url_SS:URLRequest = new URLRequest("screensaver.swf");

var url_Map_1:URLRequest = new URLRequest("Map_1.swf");

var url_Map_2:URLRequest = new URLRequest("Map_2.swf");


var Ss:Boolean = false;

var Maps:Boolean = true;

//--------------------Unload ALL---------------------------------


function unloadAllF():void{

  if(myLoader_Screen_Saver.content){

  myLoader_Screen_Saver.unloadAndStop();

  }

  if(myLoader_Map_1.content){

  myLoader_Map_1.unloadAndStop();

  }

  if(myLoader_Map_2.content){

  myLoader_Map_2.unloadAndStop();

  }

}

//--------------------Screen Saver---------------------------------

ScreenSaver();

  function ScreenSaver():void{

  unloadAllF();

  myLoader_Screen_Saver.load(url_SS); 

  addChild(myLoader_Screen_Saver);

  setChildIndex(myLoader_Screen_Saver, 1);

  Maps = false;

  Ss = true;

  }

//--------------------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{

  unloadAllF();

  myLoader_Map_1.load(url_Map_1);

  myLoader_Map_1.alpha = 1;

  addChild(myLoader_Map_1);

  setChildIndex(myLoader_Map_1, 2);

  Maps = true;

  Ss = false;

  MC_Maps_Btns.Btn_Map_1.visible = false;

  MC_Maps_Btns.Btn_Map_2.visible = true;

  }

//--------------------Map 2 ---------------------------------

MC_Maps_Btns.Btn_Map_2.addEventListener(MouseEvent.CLICK,OpenMap2);


function OpenMap2(e:MouseEvent):void {

  unloadAllF();

  myLoader_Map_2.load(url_Map_2);

  myLoader_Map_2.alpha = 1;

  addChild(myLoader_Map_2);

  setChildIndex(myLoader_Map_2, 2);

  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){

  unloadAllF();

  }

  else{

  trace("No Maps");

  }

  if (Ss == false ){

  ScreenSaver();

  MPclose();

  }

  else{

  trace("ScreenSaver already loaded");

  }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2014 Jun 26, 2014
LATEST

that looks good.

now make sure that code only executes once.  ie, it's not in a frame that repeatedly executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines