AS3 Unloading external SWF piling up problem

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

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

Similar Messages

  • Unable to unload external swf which is using runtime sharing

    Unable to unload external swf which is using runtime sharing of some symbols and classes.
    Due to this problem i am unable to load another swf or the same for the second time and getting errors at runtime.
    It works fine when the swf is opened in IE.
    Can anyone please help me in solving the issue.

    thank you
    i have tried to use   this.parent.Click_To_Close  but it gives compilation error
    i checked the tutorial about custom events i think its little complex for me now to understand the typeriter app.
    also i cheked the similer thread and tried to test that code myself..i found that the last block of main movie does not works and does not unload the loader2. however  all the trace are showing in the output windows that i added to check the code but last trace from the main movie is not showig...   
    trace("child removed from Main Movie") 
    so if this can work somehow i will use this method of event dispatch in my application that i am working...
    Thank you
    -----main movie ---------
    var loader1:Loader = new Loader();
    var loader2:Loader = new Loader();
    loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, assignMovie1Listener);
    loader1.load(new URLRequest("movie_1.swf"));
    loader2.load(new URLRequest("movie_2.swf"));
    addChild(loader1);
    addChild(loader2);
    function assignMovie1Listener(evt:Event):void {
          MovieClip(evt.currentTarget.content).addEventListener("eventTriggered", removeLoader2);
                trace("listner is listning..")
    function removeLoader2(evt:Event):void {
          loader2.unloadAndStop();
          removeChild(loader2);
             loader2 = null;
                trace("child removed from Main Movie")
    //------------- movie_1.swf code:
    removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
    function removeMovie2(event:MouseEvent):void
          dispatchEvent(new Event("eventTriggered"));
                trace("event triggered form Child Movie-1");
    as u can see when i click close button its triggering the trace from movie-1 but its not unloadign the movie2

  • Remove / unload external swf file(s) from the main flash file and load a new swf file and garbage collection from memory.

    I can't seem to remove / unload the external swf files e.g when the carousel.swf (portfolio) is displayed and I press the about button the about content is overlapping the carousel (portfolio) . How can I remove / unload an external swf file from the main flash file and load a new swf file, while at the same time removing garbage collection from memory?
    This is the error message(s) I am receiving: "TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/removeChild()
    at index_fla::MainTimeline/Down3()"
    import nl.demonsters.debugger.MonsterDebugger;
    var d:MonsterDebugger=new MonsterDebugger(this);
    stage.scaleMode=StageScaleMode.NO_SCALE;
    stage.align=StageAlign.TOP_LEFT;
    stage.addEventListener(Event.RESIZE, resizeHandler);
    // loader is the loader for portfolio page swf
    var loader:Loader;
    var loader2:Loader;
    var loader3:Loader;
    var loader1:Loader;
    //  resize content
    function resizeHandler(event:Event):void {
        // resizes portfolio page to center
    loader.x = (stage.stageWidth - loader.width) * .5;
    loader.y = (stage.stageHeight - loader.height) * .5;
    // resizes about page to center
    loader3.x = (stage.stageWidth - 482) * .5 - 260;
    loader3.y = (stage.stageHeight - 492) * .5 - 140;
    /*loader2.x = (stage.stageWidth - 658.65) * .5;
    loader2.y = (stage.stageHeight - 551.45) * .5;*/
    addEventListener(Event.ENTER_FRAME, onEnterFrame,false, 0, true);
    function onEnterFrame(ev:Event):void {
    var requesterb:URLRequest=new URLRequest("carouselLoader.swf");
    loader = null;
    loader = new Loader();
    loader.name ="carousel1"
    //adds gallery.swf to stage at begining of movie
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader.load(requesterb);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader);
    loader.x = (stage.stageWidth - 739) * .5;
    loader.y = (stage.stageHeight - 500) * .5;
    // stop gallery.swf from duplication over and over again on enter frame
    removeEventListener(Event.ENTER_FRAME, onEnterFrame);
    //PORTFOLIO BUTTON
    //adds eventlistner so that gallery.swf can be loaded
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    function Down(event:MouseEvent):void {
    // re adds listener for contact.swf and about.swf
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    //unloads gallery.swf from enter frame if users presses portfolio button in nav
    var requester:URLRequest=new URLRequest("carouselLoader.swf");
        loader = null;
    loader = new Loader();
    loader.name ="carousel"
    loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader);
    loader.x = (stage.stageWidth - 739) * .5;
    loader.y = (stage.stageHeight - 500) * .5;
    removeChild( getChildByName("about") );
    removeChild( getChildByName("carousel1") );
    // remove eventlistner and prevents duplication of gallery.swf
    MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
    //INFORMATION BUTTON
    //adds eventlistner so that info.swf can be loaded
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    function Down1(event:MouseEvent):void {
    //this re-adds the EventListener for portfolio so that end user can view again if they wish.
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    var requester:URLRequest=new URLRequest("contactLoader.swf");
    loader2 = null;
    loader2 = new Loader();
    loader2.name ="contact"
    loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader2.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader2);
    loader2.x = (stage.stageWidth - 658.65) * .5;
    loader2.y = (stage.stageHeight - 551.45) * .5;
    // remove eventlistner and prevents duplication of info.swf
    MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
    //ABOUT BUTTON
    //adds eventlistner so that info.swf can be loaded
    MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    function Down3(event:MouseEvent):void {
    //this re-adds the EventListener for portfolio so that end user can view again if they wish.
    MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
    var requester:URLRequest=new URLRequest("aboutLoader.swf");
    loader3 = null;
    loader3 = new Loader();
    loader3.name ="about"
    loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
    function ioError(event:IOErrorEvent):void {
    trace(event);
    try {
    loader3.load(requester);
    } catch (error:SecurityError) {
    trace(error);
    addChild(loader3);
    loader3.x = (stage.stageWidth - 482) * .5 - 260;
    loader3.y = (stage.stageHeight - 492) * .5 - 140;
    removeChild( getChildByName("carousel") );
    removeChild( getChildByName("carousel1") );
    // remove eventlistner and prevents duplication of info.swf
    MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
    stop();

    Andrei1,
    Thank you for the helpful advice. I made the changes as you suggested but I am receiving a #1009 error message even though my site is working the way I wan it to work. I would still like to fix the errors so that my site runs and error free. This is the error I am receiving:
    "TypeError: Error #1009: Cannot access a property or method of a null object reference."
    I'm sure this is not the best method to unload loaders and I am guessing this is why I am receiving the following error message.
         loader.unload();
         loader2.unload();
         loader3.unload();
    I also tried creating a function to unload the loader but received the same error message and my portfolio swf was not showing at all.
         function killLoad():void{
         try { loader.close(); loader2.close; loader3.close;} catch (e:*) {}
         loader.unload(); loader2.unload(); loader3.unload();
    I have a question regarding suggestion you made to set Mouse Event to "null". What does this do setting the MouseEvent do exactly?  Also, since I've set the MouseEvent to null do I also have to set the loader to null? e.g.
    ---- Here is my updated code ----
    // variable for external loaders
    var loader:Loader;
    var loader1:Loader;
    var loader2:Loader;
    var loader3:Loader;
    // makes borders resize with browser size
    function resizeHandler(event:Event):void {
    // resizes portfolio page to center
         loader.x = (stage.stageWidth - loader.width) * .5;
         loader.y = (stage.stageHeight - loader.height) * .5;
    // resizes about page to center
         loader3.x = (stage.stageWidth - 482) * .5 - 260;
         loader3.y = (stage.stageHeight - 492) * .5 - 140;
    //adds gallery.swf to stage at begining of moviie
         Down();
    //PORTFOLIO BUTTON
    //adds eventlistner so that gallery.swf can be loaded
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
    function Down(event:MouseEvent = null):void {
    // re adds listener for contact.swf and about.swf
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
    //unloads gallery.swf from enter frame if users presses portfolio button in nav
         var requester:URLRequest=new URLRequest("carouselLoader.swf");
         loader = new Loader();
         loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader.load(requester);
         } catch (error:SecurityError) {
         trace(error);
         this.addChild(loader);
         loader.x = (stage.stageWidth - 739) * .5;
         loader.y = (stage.stageHeight - 500) * .5;
    // sure this is not the best way to do this - but it is unload external swfs
         loader.unload();
         loader2.unload();
         loader3.unload();
    // remove eventlistner and prevents duplication of gallery.swf
         MovieClip(root).nav.portfolio.removeEventListener(MouseEvent.MOUSE_DOWN, Down);
    //INFORMATION BUTTON
         //adds eventlistner so that info.swf can be loaded
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         function Down1(event:MouseEvent = null):void {
         //this re-adds the EventListener for portfolio so that end user can view again if they wish.
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
         var requester:URLRequest=new URLRequest("contactLoader.swf");
         loader2 = null;
         loader2 = new Loader();
         loader2.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);    
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader2.load(requester);
    }      catch (error:SecurityError) {
         trace(error);
         addChild(loader2);
         loader2.x = (stage.stageWidth - 658.65) * .5;
         loader2.y = (stage.stageHeight - 551.45) * .5;
    loader.unload();
    loader2.unload();
    loader3.unload();
         // remove eventlistner and prevents duplication of info.swf
         MovieClip(root).nav.info.removeEventListener(MouseEvent.MOUSE_DOWN, Down1);
    //ABOUT BUTTON
         //adds eventlistner so that info.swf can be loaded
         MovieClip(root).nav.about.addEventListener(MouseEvent.MOUSE_DOWN, Down3, false, 0, true);
         function Down3(event:MouseEvent = null):void {
         //this re-adds the EventListener for portfolio so that end user can view again if they wish.
         MovieClip(root).nav.portfolio.addEventListener(MouseEvent.MOUSE_DOWN, Down, false, 0, true);
         MovieClip(root).nav.info.addEventListener(MouseEvent.MOUSE_DOWN, Down1, false, 0, true);
         var requester:URLRequest=new URLRequest("aboutLoader.swf");
         loader3 = null;
         loader3 = new Loader();
         loader3.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
         function ioError(event:IOErrorEvent):void {
         trace(event);
         try {
         loader3.load(requester);
    }      catch (error:SecurityError) {
         trace(error);
         addChild(loader3);
         loader3.x = (stage.stageWidth - 482) * .5 - 260;
         loader3.y = (stage.stageHeight - 492) * .5 - 140;
         loader.unload();
         loader2.unload();
         loader3.unload();
         // remove eventlistner and prevents duplication of info.swf
         MovieClip(root).nav.about.removeEventListener(MouseEvent.MOUSE_DOWN, Down3);
         stop();

  • As3 for unloading external swf

    I know this is a much covered subject but after spending two days trying different
    things I have to admit I'm baffled.
    Got two swf I want connected to one another to act like a portfolio gallery - parent is called "portfolio" child is "portfolio_flash_2"
    Both have animation at the start with the child having a skip button (cause its animation is 20 odd seconds long). after the animation the thumbnails appear for the larger images.
    On both swf's the buttons I'm using to load (parent to child) and unload (child back to parent) appear after the animation - I can get the child to load from the parent but having problems knowing what proper code to use on the child button "page2_btn" to return to the parent.
    The code I'm using for the parent button is called "cloud" ;
    var myLoader:Loader=new Loader ();
    cloud.addEventListener(MouseEvent.CLICK, portfolio);
    function portfolio(myevent:MouseEvent):void{
           var myURL:URL Request=new URLRequest("portfolio_flash_page2.swf"
           myLoader.load(myURL);
           addChild(myLoader);
    I did also try adding this to the above with out any code on the button of the child swf;
    myLoader.addEventListener(MouseEvent.CLICK, unloadcontent);
    function unloadcontent(myevent:MouseEvent):void{
           removerChild(myLoader);
    but after the animation (when the code in the timeline is written) just clicking anywhere on the child swf ( not just the button) made the parent appear.
    I have also tried (in two instances when the last code above was present and removed) adding this code to the "page2_btn" I made for the child page;
    page2_btn.addEventListener(MouseEvent.CLICK, removeSWF);
    function removeSWF(e:MouseEvent):void{
            removeChild(myLoader1);
            myLoader1 = null;
    But that just resulted in the skip button on the child not working and the larger images playing as if it was a movie.
    Most of this code I got from the classrom in a book and from threads on here, did try countless others from other google searches but when your stupid your stupid. So if any body could help out a learner I'd be most grateful.
    Paul

    cheers for your reply. got the decription and source faults below
    1061: Call to a possibly undefined method unloadAndStop through a reference with static type flash.display:DisplayObjectContainer. this.parent.unloadAndStop();  // if publishing  for fp 10,  else use unload()
    1059: Property is read-only.
    this.parent=null;  // this may not execute so it might be better to call a removeSWF function in the parent swf
    based on the code in the parent as shown in first thread, how would I include/call the "removeSWF function" into that script?
    To help sort this out I thought I'd include a photo of the timeline as there is three sets of script, and for all I know each might be conflicting with the other or something. (due to why the skip btn does not work for instance)
    in photo - the top layer contains the "skip" btn script where it skips to frame 216.
    the code highlighted is the "page2_btn" script and the script lower down is for the "showimage" function in ref's to the labels 1 to 4.
    I wish I was like you pro's and could see the problems instead of staying up til the late hours of the morning trying to solve stuff searching endless google searches - could you recommend a good book from learning the basic's of the AS3 - might help a great deal to learn them first but my first indention of using flash was for animation which I done for awhile without the AS.
    But I hope to display various animations I've done within external SWF such as this example so a book that covers it would be great.
    again cheers for any help.

  • AS3 load external swf problem, please help...

    Hey guys, I am really in need of an answer here. I would tremendously grateful if someone has the answer. I'll keep it simple and right to the point:
    1. I have created "index.swf" in AS3. Has it's own "MainClass" class.
    2. I created "holder.swf" which is the main landing page. Has 2 buttons, for the viewer to load the site in fullscreen or standard.
    3. In the timeline of "holder.swf" I have created 2 frames, 1st frame containing the buttons, second frame containing the AS3 external swf loader script.
    It does not seem to want to load my "index.swf".
    I have tested a million different ways, it load other swf's just fine, AS2 and AS3, but for some strange reason it just will NOT load "index.swf".
    This is driving me crazy, I have a feeling it has something to do with a class conflict. I have tried (import MainClass;) in the first frame of "holder.swf" and no luck.
    PLEASE GUYS, LET ME KNOW IF YOU KNOW THE ANSWER!
    THANK YOU SO MUCHO.
    Michael

    Hey kglad,
    Thanks for the quick reply!
    Well here is the problem... With the exception of a few things I need to update, as well as implementing some better preloaders etc... the site is running alright...
    About a week ago I decided that I wanted to site to start with the above landing page. A simple "holder.swf" which would give the viewer something to look at before entering the site... (ideally I want to find a script that will begin loading "index.swf" while the viewer is still on "holder.swf", but I'll figure that out later).
    Anyhow, I created "holder.swf" as I have many times before, and for some reason it does not seem to want to load "index.swf" into the second frame when instructed to do so... does that make sense?
    So... ideally I would like the site to start on the above graphic, then once the button is clicked, "index.swf" opens up...
    It's driving me crazy, because my code works on other swf's I've tested it with, just not with index.swf, which leads me to believe there is something in the MainClass.as file which is causing it not to load...
    What are your thoughts?
    Oh, and many thanks again!!!
    M

  • Transition_Manager and unloading external swf problems

    Hi there
    I´m having a few problems with my project which i although it work it has some unpleasant bugs that i´m trying to solve for days.
    When i load external swf´s they show up on top of the Menu button.Maybe because the button i´m pressing is inside the same movieclip as the Menu.
    Explaining better here´s a little diagram of my site:
    con2 MC (Instance of Menu) ---> cont3 MC (Instance of subMenu) and mainButton MC (Instance of Main)
    Here´s the general code which is inside the Painel.as
    package {
        import com.greensock.TweenLite;
        import com.greensock.TweenMax;
        import com.greensock.*;
        import com.greensock.easing.*;
        import flash.display.*;
        import flash.events.*;
        import flash.display.MovieClip;
        import fl.transitions.*;
        import fl.transitions.easing.*;
        import flash.net.URLRequest;
        import flash.display.Loader;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        public class Painel3 extends MovieClip
            private var inFocus:MovieClip;
            public function Painel3():void
                setupClips();
                addEventListener(Event.ENTER_FRAME, loop);
            private function setupClips():void
            con2.mainButton.addEventListener(MouseEvent.ROLL_OVER, onOver);
            con2.mainButton.addEventListener(MouseEvent.ROLL_OUT, onOut);
            con2.mainButton.addEventListener(MouseEvent.CLICK, onClick);
                var len:int = con2.cont3.numChildren;
                for(var i:int=0; i<len; i++)
                    var mc:MovieClip = MovieClip(con2.cont3.getChildAt(i));
                    mc.buttonMode = true;
                    mc.loc = [mc.x, mc.y];
                    mc.addEventListener(MouseEvent.CLICK, onClick);
                    con2.cont3.visible = false;
            private function onOver(e:MouseEvent):void
            private function onOut(e:MouseEvent):void
            private function onClick(e:MouseEvent):void
                con2.cont3.visible = true;
    TransitionManager.start(con2.cont3, {type:Wipe, direction:Transition.IN, duration:1, easing:None.easeNone, startPoint:5} );                       
            private function loop(e:Event):void
                var distx:Number = mouseX / 1400;
                var disty:Number = mouseY / 1400;
                TweenLite.to(con2, 2, {
                            rotationY:(-70 +(145*distx)),
                            rotationX:(70 -(145*disty)),
                            ease:Expo.easeOut
    And then inside the subMenu.as class for the movieclip subMenu i have the buttons that load the external swf´s:
    package  {
        import com.greensock.TweenLite;
        import com.greensock.TweenMax;
        import com.greensock.*;
        import com.greensock.easing.*;
        import flash.display.*;
        import flash.events.*;
        import flash.display.MovieClip;
        import flash.net.URLRequest;
        import flash.display.Loader;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        import fl.transitions.*;
        import fl.transitions.easing.*;
        public class subMenu extends MovieClip {
            public function subMenu() {
                // constructor code
                menu1.buttonMode = true;
                menu2.buttonMode = true;
                menu3.buttonMode = true;
                menu4.buttonMode = true;
                 menu1.addEventListener(MouseEvent.CLICK,link1);
                 menu2.addEventListener(MouseEvent.CLICK,link2);
                 menu3.addEventListener(MouseEvent.CLICK,link3);
                 menu4.addEventListener(MouseEvent.CLICK,link4);
            function link1(e:MouseEvent) {
               function startLoad()
                var mLoader:Loader = new Loader();
                var mRequest:URLRequest = new URLRequest("AugmentedReality_v1.swf");
                mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
                mLoader.load(mRequest);
    function onCompleteHandler(e:Event):void {
    var swf:DisplayObject = e.target.content;
    swf.x = -400;    
    swf.y = -300;    
    addChild(swf);
    function onProgressHandler(mProgress:ProgressEvent)
           var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
           trace(percent);
    startLoad();
            function link2(e:MouseEvent) {
                function startLoad()
                var mLoader:Loader = new Loader();
                var mRequest:URLRequest = new URLRequest("Fotos.swf");
                mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
                mLoader.load(mRequest);
    function onCompleteHandler(e:Event):void {
    var swf:DisplayObject = e.target.content;
    swf.x = -400;    
    swf.y = -300;    
    addChild(swf);
    function onProgressHandler(mProgress:ProgressEvent)
           var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
           trace(percent);
    startLoad();
            function link3(e:MouseEvent) {
            function link4(e:MouseEvent){
                function startLoad()
                var mLoader:Loader = new Loader();
                var mRequest:URLRequest = new URLRequest("Texto.swf");
                mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
                mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
                mLoader.load(mRequest);
    function onCompleteHandler(e:Event):void {
    var swf:DisplayObject = e.target.content;
    swf.x = -400;    
    swf.y = -300;    
    addChild(swf);
    function onProgressHandler(mProgress:ProgressEvent)
           var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
           trace(percent);
    startLoad();
    Like i said the swf´s show up on top of the Menu and i need it to dissapear.
    Also i want to unload the swf currently in scene so that when i load another one they don´t pile on top of each other.
    Pls help. Thanks

    Oh btw, i´m having an error 1069 Property TransitionManager not found in subMenu and there is no default value
    at fl.transitions::TransitionManager$/start()
        at Painel3/onClick()
    This doesn´t happen when i uncheck the Export for actionscript in the subMenu class but i can´t do that or else the buttons wont work.

  • Unloading external swf problem - deadline approaching

    Hi,
    We bought a component, and the developers are not real
    helpful so I thought I would try here. We have the well-known AS 3
    problem of events continuing to run even after you've unloaded a
    swf. Here is what we got:
    a main swf loads one of 7 secondary swfs, based on a button
    click. each of the secondary swfs contains the component (a 3D
    wall) that we purchased. we don't seem to have access to the code.
    we unload one swf load the next, and then after we do this a few
    times we get the following crash (output way below).
    The component does have a closeWall() function, which i'm
    assuming cleans things up. The problem is I don't know how to call
    a function on an externally loaded swf? Is that possible? In other
    words I want to say:
    var loader:Loader;
    function loadSwf(){
    loader = new Loader();
    var urlRequest:URLRequest = new URLRequest ("vidSub.swf");
    loader.load(urlRequest);
    addChildAt(loader, getChildIndex(holder));
    function unloadSwf(){
    // hey swf, close properly, before I unload you
    loader.closeWall();//or something like this
    loader.unload();
    Thanks so much if you can help.
    Doug
    Crash output:
    Error: Error #2094: Event dispatch recursion overflow.
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.display::Stage/dispatchEvent()
    at
    org.papervision3d.core.utils.virtualmouse::VirtualMouse/::handleUpdate()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at
    org.papervision3d.core.utils.virtualmouse::VirtualMouse/update()
    at
    org.papervision3d.core.utils.virtualmouse::VirtualMouse/setLocation()
    at
    org.papervision3d.core.utils::InteractiveSceneManager/org.papervision3d.core.utils:Intera ctiveSceneManager::handleMouseMove()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.display::Stage/dispatchEvent()
    at org.papervision

    I feel for you...
    You may want to try to instantiate the thing not through
    adding loader to display list but accessing application domain and
    creating an instance of its class. Some application will not do a
    thing if you just add them to display list and accessing their
    interfaces (I love doing that for one :-). In any case - I am not
    sure it is such a good idea to add the loader directly - not within
    INIT event listener.
    You may want to try accessing their application domain and
    loop through its properties to see which ones are enumerable. In
    the error stack you can see some their classes so you know already
    what to access. For instance there is
    org.papervision3d.core.utils.InteractiveSceneManager class.
    I don't say anything new but it looks like there is the same
    event flying around which is dispatched by some listener causing
    recursion. Can it be that your custom events have the same type as
    theirs? Try to listen to their events through making listener
    listen in capture phase by setting third parameter to true:
    blah.addEventListener("eventType", eventHandler, true) - you may be
    able to explicitly remove their event listener if you know which
    one. Or, perhaps, this is your mouse event that conflicts with
    theirs...
    Sorry I cannot be more helpful.

  • Unloading external swf

    Hello everyone,
    I'm kind of new to AS3
    I created a flash file and i have several buttons on the main
    stage.
    I have given the buttons instance names and whenever a button
    is clicked an external swf is loaded on the main stage.
    The problem which occurred is that ehenever i click on the
    same button again i can see a glimpse of the previous swf that was
    loaded meaning that i didnt get rid of the swf on the click of
    another button.
    What i want to achieve is to load the external swf and then
    when i click on another button i wish for it to unload.
    Here is the code.
    var externalSWF6:URLRequest = new URLRequest("dress6.swf");
    var myLoader6:Loader = new Loader();
    button6.addEventListener(MouseEvent.CLICK, onButtonClick6);
    myLoader6.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
    swfLoading6);
    myLoader6.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfComplete6);
    function onButtonClick6(event:MouseEvent):void
    myLoader6.load(externalSWF6);
    function swfComplete6(event:Event):void
    addChild(myLoader6);
    myLoader6.x = 0
    myLoader6.y = 0
    function swfLoading6(event:ProgressEvent):void
    var externalSWF7:URLRequest = new URLRequest("dress7.swf");
    var myLoader7:Loader = new Loader();
    button7.addEventListener(MouseEvent.CLICK, onButtonClick7);
    myLoader7.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
    swfLoading7);
    myLoader7.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfComplete7);
    function onButtonClick7(event:MouseEvent):void
    myLoader7.load(externalSWF7);
    function swfComplete7(event:Event):void
    addChild(myLoader7);
    myLoader.x = 0
    myLoader.y = 0
    myLoader7.addEventListener("UnloadMe", unloadFunction7); //
    <-- My line
    function unloadFunction7(event:Event):void {
    // event.target is the loader reference.. so cast it as
    Loader
    Loader(event.currentTarget).unload();
    function swfLoading7(event:ProgressEvent):void
    var externalSWF:URLRequest = new URLRequest("dress4.swf");
    var myLoader:Loader = new Loader();
    button4.addEventListener(MouseEvent.CLICK, onButtonClick);
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
    swfLoading);
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfComplete);
    function onButtonClick(event:MouseEvent):void
    myLoader.load(externalSWF);
    function swfComplete(event:Event):void
    addChild(myLoader);
    myLoader.x = 0
    myLoader.y = 0
    function swfLoading(event:ProgressEvent):void
    var externalSWF8:URLRequest = new URLRequest("dress8.swf");
    var myLoader8:Loader = new Loader();
    button8.addEventListener(MouseEvent.CLICK, onButtonClick8);
    myLoader8.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
    swfLoading8);
    myLoader8.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfComplete8);
    function onButtonClick8(event:MouseEvent):void
    myLoader8.load(externalSWF8);
    function swfComplete8(event:Event):void
    addChild(myLoader8);
    myLoader.x = 0
    myLoader.y = 0
    myLoader8.addEventListener("UnloadMe", unloadFunction8); //
    <-- My line
    function unloadFunction8(event:Event):void {
    // event.target is the loader reference.. so cast it as
    Loader
    Loader(event.currentTarget).unload();
    function swfLoading8(event:ProgressEvent):void
    var externalSWF9:URLRequest = new URLRequest("dress9.swf");
    var myLoader9:Loader = new Loader();
    button9.addEventListener(MouseEvent.CLICK, onButtonClick9);
    myLoader9.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
    swfLoading9);
    myLoader9.contentLoaderInfo.addEventListener(Event.COMPLETE,
    swfComplete9);
    function onButtonClick9(event:MouseEvent):void
    myLoader9.load(externalSWF9);
    function swfComplete9(event:Event):void
    addChild(myLoader9);
    myLoader.x = 0
    myLoader.y = 0
    function swfLoading9(event:ProgressEvent):void
    //you can do something here while the swf is loading... }
    button4.buttonMode = true;
    button6.buttonMode = true;
    button7.buttonMode = true;
    button8.buttonMode = true;
    button9.buttonMode = true;
    button4.addEventListener(MouseEvent.ROLL_OVER,buttonOver4);
    button4.addEventListener(MouseEvent.ROLL_OUT,buttonOut4);
    function buttonOver4(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("over4");
    function buttonOut4(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("out4");
    button6.addEventListener(MouseEvent.ROLL_OVER,buttonOver6);
    button6.addEventListener(MouseEvent.ROLL_OUT,buttonOut6);
    function buttonOver6(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("over6");
    function buttonOut6(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("out6");
    button7.addEventListener(MouseEvent.ROLL_OVER,buttonOver7);
    button7.addEventListener(MouseEvent.ROLL_OUT,buttonOut7);
    function buttonOver7(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("over7");
    function buttonOut7(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("out7");
    button8.addEventListener(MouseEvent.ROLL_OVER,buttonOver8);
    button8.addEventListener(MouseEvent.ROLL_OUT,buttonOut8);
    function buttonOver8(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("over8");
    function buttonOut8(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("out8");
    button9.addEventListener(MouseEvent.ROLL_OVER,buttonOver9);
    button9.addEventListener(MouseEvent.ROLL_OUT,buttonOut9);
    function buttonOver9(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("over9");
    function buttonOut9(e:MouseEvent):void
    e.currentTarget.gotoAndPlay("out9");
    If anyone can be of assistance i would greatly appreciate
    it:)

    Your choices for removing objects are removeChild() and
    removeChildAt().
    So you need some way of tracking the objects that are added
    so that they can be removed. IF the buttons are the only things
    that add new content while the movie is playing, then the last
    thing added will have an index = numChildren-1,
    So if you want to remove the last movie before the new movie
    is added, then use removeChildAt(numChildren-1)
    Now, for the first time you use this, it will remove the last
    element on the stage, which you don't want, so you should probably
    have a variable that is set when any button is clicked and a
    conditional that checks it....
    var buttonClicked:Boolean = false; // set to true when a
    button is clicked
    in the handler:
    if(buttonClicked){
    removeChildAt(numChildren-1)
    buttonClicked = true;
    There are other ways of targeting in the event the movie was
    not the last thing added to the stage when another button gets
    clicked, such as assigning name to the movie or capturing which
    index it has when it is loaded.

  • Load/ Unload external .swf

    ----------------------------------------
    vita | web | design | illustration
    "main" here
    I try to have external .swf on this "main" part of my flash
    design automatically using load actionscript.
    I have 3 different sets of actionscripts for load/unload.
    But, the problem is when I click vita or other menu on the
    top after loading "main" external .swf, they are overlapped.
    How can I unload the external .swf from the automatically
    loaded .swf?
    (As I know, there are mostly buttons to click on loading
    external .swf. But for my design, I want it loads automatically.)
    Thanks in advance for suggestions. Please let me know if my
    description/question is not clear to answer.

    Are you using AS2 or AS3. The approach is completely
    different for both.

  • UNLOADING EXTERNAL SWF. SOMEONE HELP!

    I have a menu in my site and i recently added a comment form that is loaded when you click one of the buttons of the menu.
    My problem is that when I click on a different menu button the external swf [comment form] its still there I've tried adding the unloadMovie
    option but its not working. Here is the code for both buttons.
    ---------------------HOME BTN:
    on (rollOver) {
    gotoAndPlay(2);
    on (rollOut) {
    gotoAndPlay(6);
    on (release) {
    if (_root.choose != "home" && _root._currentframe!=30) {
    _root.play();
    _root.choose = "home";
    //mysound = new Sound();
    //mysound.attachSound("soundClick");
    //mysound.start();
    --------------------COMMENT FORM BTN:
    on (rollOver) {
    gotoAndPlay(2);
    on (rollOut) {
    gotoAndPlay(6);
    on (release) {
    if (_root.choose != "contact") {
    _root.play();
    _root.choose = "contact";

    unloadMovie() will work if there's a movie clip to be referenced. If you have assigned a name to the loaded movie you can unload it with unloadMovie(). Another option is to call unloadMovie() from the clip itself like: my_loaded_mc.unloadMovie(this); In every case check for incorrect paths (if you load a movie and refer to _root - the root will be the root of the loader, not the movie itself)
    Emil Georgiev - Flash and Web Design

  • Unloading external swf file keeps memory usage growing up

    Hello everybody,
    The idea is very simple: I have a submain.swf with 5 buttons. Each button loads an external .swf file.
    com_loader.load(URLRequest);
    After playing first external swf, before I go to next one, I try to unload it:
    1. remove all its associated listeners:
    com_loader.contentLoaderInfo.removeEventListener(Event.INIT-PROGRESS-COMPLETE, idFunction);
    2. unload it:
    com_loader.unload();
    3. set to null:
    com_loader = null;
    and load next external swf file and so on.
    The problem is that the FireFox/IE8.0 Memory Usage in Task Manager is going up and I see no sign of GC activity even after 5 mins of playing. Can anyone light me up pls? This is the second week working around and no good news until now.
    Thanks in advance.
    P.S.
    If I try com_loader.unloadAndStop(); it gives me the error: Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.
    Vince.

    Hi Ice,
    The loaded swf file contains only a small photo, just for testing, with no listeners or other stuff in it.
    Vic.

  • Trouble unloading external swf's

    Hey, so firstly, I am completely new to Flash and know absolutely nothing :| But heres my problem:
    In one particular keyframe, I have five buttons on the left hand side of my stage, that when clicked, display an external swf on the right handside. It works perfect fine using the code below. However on this frame where all this is going on, I also have a back button that i want to link back to the home page. But I just CAN'T seem to get it to unload the external swfs as well as go back in the timeline Any assistance would be great! Cheers
    var Xpos:Number = 675;
    var Ypos:Number = 225;
    var swf:MovieClip;
    var loader:Loader = new Loader();
    var defaultSWF:URLRequest = new URLRequest("swfs/pacman1000.swf");
    loader.load(defaultSWF);
    loader.x = Xpos;
    loader.y = Ypos;
    loader.scaleX = 0.8;
    loader.scaleY = 0.8;
    addChild(loader);
    // Btns Universal function
    function btnClick(event:MouseEvent):void {
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = 690;
    loader.y = 275;
    loader.scaleX = 0.8;
    loader.scaleY = 0.8;
    addChild(loader);
    // Btn listeners
    pacman1000.addEventListener(MouseEvent.CLICK, btnClick);
    snake.addEventListener(MouseEvent.CLICK, btnClick);
    tetris.addEventListener(MouseEvent.CLICK, btnClick);
    spaceinvaders.addEventListener(MouseEvent.CLICK, btnClick);
    simon.addEventListener(MouseEvent.CLICK, btnClick);

    Oops sorry I forgot to put "function"!
    function onBackButtonClick(e:MouseEvent):void {
    Obviously your back button needs an event listener to call this function.
    Kenneth Kawamoto
    http://www.materiaprima.co.uk/

  • How to load and unload external .swfs in a main .fla then load another external .swf on top

    I know that the question sounds confusing. I am new to AS3 but a little dangerous with it.
    The project
    I'm putting together a website tour with has a main .fla with navigation buttons. The navigation buttons load external .swfs using X and Y properties. Every external .swf houses a scrubber bar, play pause buttons which calls to a movie clip which houses the animation.
    The problem:
    Everything was working great, until someone mentioned "Hey, what if at the end of each loaded external .swf, a button appears that says "go to next section".
    So basically we are trying to give the user another way to get to the next section in the left hand navigation once the animation ends, in addition to being able to click in the left hand navigation for the next section. It's kind of like when a youTube video ends and it displays a button to go to the next movie that's in line, but you can also do it in the thumnail navigation as well.
    Ok, let's try it. Well, after many nights, searching the web and trying everything I am waving the white flag. I went through the lynda.com book over and over but I get an error message when I add code related to the parent timeline. I can actually get the next section to load on top of the previously loaded .swf, but it's buggy and I think the previous section is showing through underneath. Plus the scrubber isn't really working right. Since every .swf has a scrubber to control it, shouldn't it just load on top of the previous .swf? Do I need to add coding related to the parent timeline?
    I don't know if I should paste my code here, I have a sample .fla too. Help is so greatly appreciated!!!! If this can work, I think it would be very useful for anyone else doing something like this - I would definitely share any knowledge gained!
    Thanks.
    Jen

    If you want to utilize that code as a starting point (hopefully you understand what it does, and that the code actually works), then you need to modify it such that the array at the start has your filenames instead of the three it now shows, and the three buttons it uses are changed to the next and previous buttons you intend to use.  Here are the functions you need to make adjustments to...
    function onCompletePreloading():void {
            _loadedSWFs = 0;
            contentContainer.addChild(_swfClipsArr[_loadedSWFs]);
            next_btn.addEventListener(MouseEvent.CLICK, setContent);
            prev_btn.addEventListener(MouseEvent.CLICK, setContent);
    function setContent(event:MouseEvent):void {
            var _swfToAdd:MovieClip;
            if(event.currentTarget.name == "next_btn") {
                _loadedSWFs += 1;
                if(_loadedSWFs == _swfClipsArr.length){
                       _loadedSWFs = 0;
            } else if(event.currentTarget.name == "prev_btn"){
                _loadedSWFs -= 1;
                if(_loadedSWFs == -1){
                       _loadedSWFs = _swfClipsArr.length-1;
            _swfToAdd = _swfClipsArr[_loadedSWFs];
            contentContainer.removeChildAt(contentContainer.numChildren-1);
            contentContainer.addChild(_swfToAdd);
            trace(_swfToAdd.customID);

  • How to Load/Unload external SWF

    Hey all, I'm in a desperate struggle to meet a deadline for college coursework. I am unable to UNLOAD an external SWF file that I have put inside another SWF file. The problem that is occurring is, although it loads successfully, when I attempt to navigate to another page after viewing the external SWF, I expect it to close as it goes on to another page however, it remains in place. If i then go back on to the page that it is loading from, it will start to keep adding more and more SWF's. The print screens should explain it easier... Below i'll post the code that I'm using currently. The external SWF I am trying to load/unload is an interactive hangman game (whether it being interactive has an effect I do not know), but any and all help with this would be seriously appreciated!
    The code currently being used is:
    var _swfLoader:Loader;
    var _swfContent:MovieClip;
    loadSWF("Real Hangman.swf");
    function loadSWF(path:String):void {
       var _req:URLRequest = new URLRequest();
       _req.url = path;
       _swfLoader = new Loader();
       setupListeners(_swfLoader.contentLoaderInfo);
       _swfLoader.load(_req);
    function setupListeners(dispatcher:IEventDispatcher):void {
       dispatcher.addEventListener(Event.COMPLETE, addSWF);
       dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
    function preloadSWF(event:ProgressEvent):void {
       var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
       // swfPreloader.percentTF.text = _perc + "%";
    function addSWF(event:Event):void {
       event.target.removeEventListener(Event.COMPLETE, addSWF);
       event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
       _swfContent = event.target.content;
       _swfContent.addEventListener("close", unloadSWF);
       addChild(_swfContent);
    function unloadSWF(event:Event):void {
       _swfLoader.unloadAndStop();
    removeChild(_swfContent);
       _swfContent = null;
    This printscreen is showing what it looks like in the Flash view (plain background and external SWF loads when this SWF is published)
    What it looks like when loaded as published swf
    Picture of the external SWF working inside the other SWF
    Picture of it not being able to unload when i navigate to another page!
    Finally, a picture of it doubling up when i proceed to go on the 'game' page again, it just keeps loading the SWF's rather than unloading them!

    for example, file1 consits of two buttons, and also considered as main page. As i click on these two buttons , it will lead me go to open the external file2.swf, and file3.swf respectively. (file2.swf and file3.swf could have other navigation buttons, however, i am just simplify here).
    the code you provided is working fine. but i want to totally remove/unlink the orginal file (file1.swf) when i click on either buttons which could lead me to other page (file1.swf or file2.swf).
    Besides that, in file2.swf and file3.swf could have another "back" button to turn it back to the main page (file1.swf). When the user click on that back button, the file2.swf will unloaded...and file1.swf will be called back again...
    can it  be done?
    so sorry if my poor explanation makes you confuse..
    thank you.

  • UNLOAD External SWF on Mouseclick

    All of my buttons load their respective external swf files. However, they load on top of each other. How do I set each button to UNLOAD the external swf's that have already been loaded by the previous buttons.
    Here is what I have now:
    movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF); 
    var fl_Loader:Loader; 
    //This variable keeps track of whether you want to load or unload the SWF 
    var fl_ToLoad:Boolean = true; 
    fl_ClickToLoadUnloadSWF(null); // load the swf at the start
    function fl_ClickToLoadUnloadSWF(event:MouseEvent):void 
        if(fl_ToLoad) 
            fl_Loader = new Loader(); 
            fl_Loader.load(new URLRequest("album1.swf")); 
            addChild(fl_Loader); 
            fl_ToLoad = false;
        else 
            fl_Loader.unload(); 
            removeChild(fl_Loader); 
            fl_Loader = null; 
            fl_ToLoad = true;
    movieClip_2.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_2);
    var fl_Loader_2:Loader;
    //This variable keeps track of whether you want to load or unload the SWF
    var fl_ToLoad_2:Boolean = true;
    function fl_ClickToLoadUnloadSWF_2(event:MouseEvent):void
        if(fl_ToLoad_2)
            fl_Loader_2 = new Loader();
            fl_Loader_2.load(new URLRequest("album2.swf"));
            addChild(fl_Loader_2);
        else
            fl_Loader_2.unload();
            removeChild(fl_Loader_2);
            fl_Loader_2 = null;
        // Toggle whether you want to load or unload the SWF
        fl_ToLoad_2 = !fl_ToLoad_2;
    movieClip_3.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3);
    var fl_Loader_3:Loader;
    //This variable keeps track of whether you want to load or unload the SWF
    var fl_ToLoad_3:Boolean = true;
    function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
        if(fl_ToLoad_3)
            fl_Loader_3 = new Loader();
            fl_Loader_3.load(new URLRequest("album3.swf"));
            addChild(fl_Loader_3);
        else
            fl_Loader_3.unload();
            removeChild(fl_Loader_3);
            fl_Loader_3 = null;
        // Toggle whether you want to load or unload the SWF
        fl_ToLoad_3 = !fl_ToLoad_3;

    Your code is too much bad , sorry to say.
    Please try the following code that I have made for you.
    Here the code is much too smaller than yours and also hope it will solve your problem.
    import flash.events.MouseEvent;
    import flash.display.Loader;
    movieClip_1.addEventListener(MouseEvent.CLICK, loadUnloadSWF); 
    movieClip_2.addEventListener(MouseEvent.CLICK, loadUnloadSWF);
    movieClip_3.addEventListener(MouseEvent.CLICK, loadUnloadSWF);
    var fl_ToLoad:Boolean = true; 
    var fl_Loader:Loader;
    var previous_btn:String;
    loadUnloadSWF(null);
    function loadUnloadSWF(event:MouseEvent):void
        try{
        var str:String = event.target.name.split("_")[1];
        }catch(e:Error){str="1";}
        try{
        fl_Loader.unload(); 
        }catch(e:Error){}
        if(previous_btn != str)
            fl_Loader = new Loader();
            fl_Loader.load(new URLRequest("album"+str+".swf")); 
            addChild(fl_Loader); 
        previous_btn = str;
    Regards
    Sazzad Ahmmed Mohon

Maybe you are looking for

  • FI-New GL Issue - Inconsistencies in time of creation in Table FAGLFLEXA an

    Hi, We are facing the following issue in ECC 5.0 with New GL Active When a journal entry is created, the current time is captured (EST) at the header level of the document and is available in the BKPF table. The same document is also updated in FAGLF

  • Visio 2013 Drawing pages do not open

    Hi, I have a .vsdx file with 13 pages - there are two modified stencils in it.  when the drawing opens it opens these two modified stencils first then opens the main drawing with the pages. Now the drawing opens to the first stencil and does not open

  • Problems with Yahoo! business email since 3.0

    iPhone 3G My business email, which is served by Yahoo, is not longer able to send messages from the phone. I can receive, but when the phone tries to load the Sent message folder, I get an error. Also, when I send a message, it makes the "sent sound"

  • Packet is not sent

    Hi, I write tftp client. I am trying to send packet to tftp server using the following command : sock.send(new DatagramPacket(message,length,ip,tftpPort)); When I run this on windows and some linux it works OK but in other linux is not. I see that th

  • Delete response doesn't work in my automation

    Hello all, Has anybody else come across problems with the 'delete' response, or have any suggestions for me? I've setup a watcher automation that's very simple. 1. Copy and move the file to the library (no transcode), and 2. Delete. When I drag a fil