Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:59:49+00:00 2026-05-31T19:59:49+00:00

Got a question for you all! I’m trying to make a navigation system for

  • 0

Got a question for you all! I’m trying to make a navigation system for my website where each nav item is loaded as an external .swf. Thanks to another user on this site, I was able to get that functionality in place. The problem is I want to add a preloader for these external swfs as well.

The code I’m working with is this:

var loadedSWF:Loader = null;

/**
 * Loads an SWF and adds it to container once complete
 * @param file The URL to the SWF to load
 * @param container The container to add the SWF to
 */
function loadSWF(file:String, container:MovieClip=null):void
{   
    if(container == null) container = MovieClip(root);

    // removes the previously loaded SWF
    if(loadedSWF != null)
    {
        if(loadedSWF.parent) loadedSWF.parent.removeChild(loadedSWF);
    }

    var req:URLRequest = new URLRequest(file);
    loadedSWF = new Loader();
    loadedSWF.load(req);

    addChild(loadedSWF);
}



menu_mc.test_btn.addEventListener(MouseEvent.CLICK, _click);
function _click(e:MouseEvent):void
{
    loadSWF("testmovie.swf");
    loadedSWF.x = 0;
    loadedSWF.y = 125;
    var otherindex = getChildIndex(Border);
    setChildIndex(loadedSWF, otherindex + 1);
}

So far everything I’ve tried has come up short. I can get a preloader working if I don’t use a null loader, but when I do that I’m not sure how to get it to remove the assets being used when loading another .swf – everything just stacks and bogs down the site. If I try and put together a preloader attached to the above code, I get errors because I’m making calls to a null object. Sorry to be such a newbie, I’ve only just begun to wrap my head around flash. I appreciate any help!

Edit: Here’s a quick look at my somewhat jumbled version that includes a preloader, but doesn’t work due to the null loader:

var loadedSWF:Loader = null;

/**
 * Loads an SWF and adds it to container once complete
 * @param file The URL to the SWF to load
 * @param container The container to add the SWF to
 */
function loadSWF(file:String, container:MovieClip=null):void
{   
    if(container == null) container = MovieClip(root);

    // removes the previously loaded SWF
    if(loadedSWF != null)
    {
        if(loadedSWF.parent) loadedSWF.parent.removeChild(loadedSWF);
    }

    loadedSWF.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    loadedSWF.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
    var req:URLRequest = new URLRequest(file);
    loadedSWF = new Loader();
    loadedSWF.load(req);

    function loadProdComplete(e:Event):void {
    trace("swf file loaded");   
    //remove the preloader from container clip
            removeChild(preLoader);

           // add the loaded swf to container clip
    addChild(loadedSWF);    

    currentSWF = MovieClip(loadedSWF.content);
    currentSWF.gotoAndPlay(1);

    currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);

function checkLastFrame(e:Event):void { 

if (currentSWF.currentFrame == currentSWF.totalFrames) {
     currentSWF.stop();
    // trace("stopped");     
   }

   }   

}

var preLoader:loader = new loader();

//position the loading bar
preLoader.x = 155;
preLoader.y = 185;

addChild(preLoader);

function onProgressHandler(event:ProgressEvent){

var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
preLoader.bar.scaleX = dataAmountLoaded/100;
preLoader.lpc.text= int(dataAmountLoaded)+"%";

trace(preLoader.bar.scaleX );

   }

}

var currentSWF:MovieClip = new MovieClip();


menu_mc.test_btn.addEventListener(MouseEvent.CLICK, _click);
function _click(e:MouseEvent):void
{
    loadSWF("testmovie.swf");
    loadedSWF.x = 0;
    loadedSWF.y = 125;
    var otherindex = getChildIndex(Border);
    setChildIndex(loadedSWF, otherindex + 1);
}

Edit #2: Functional code, but now receiving the following output error whenever I hit the button. The swfs load and unload just fine, but if anyone knows how I could clean it up to avoid the output error I’d like to get it as smooth as possible!:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at MethodInfo-8()

var container:MovieClip = new MovieClip();
var currentSWF:MovieClip = new MovieClip();
var swfLoader:Loader = new Loader();

function launchSWF(vBox, vFile):void{   

//vBox.addChild(swfLoader);
var swfURL:URLRequest = new URLRequest(vFile);

swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);

swfLoader.load(swfURL);

function loadProdComplete(e:Event):void {
    trace("swf file loaded");   
    vBox.removeChild(preLoader);
    vBox.addChild(swfLoader);   

    currentSWF = MovieClip(swfLoader.content);
    currentSWF.gotoAndPlay(1);


    currentSWF.addEventListener(Event.ENTER_FRAME , checkLastFrame);

function checkLastFrame(e:Event):void { 

    if (currentSWF.currentFrame == currentSWF.totalFrames) {
     currentSWF.stop();
    // trace("DONE");     
   }

   }   

}

var preLoader:loader = new loader();
preLoader.x = 155;
preLoader.y = 185;

vBox.addChild(preLoader);

function onProgressHandler(event:ProgressEvent){

var dataAmountLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
preLoader.bar.scaleX = dataAmountLoaded/100;
preLoader.lpc.text= int(dataAmountLoaded)+"%";

trace(preLoader.bar.scaleX );

   }    

}

test_btn.addEventListener(MouseEvent.CLICK, _load); 

function _load(e:Event):void{

     swfLoader.unloadAndStop();
     var swfFile:String = 'test.swf';
     launchSWF(container, swfFile);
     //put it on stage
     addChild(container);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:59:51+00:00Added an answer on May 31, 2026 at 7:59 pm

    Dont use null , just use the unload method of the Loader class.

    Loader.unload()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to PHP first of all .. My question is once I got
Hi i got a question to ask u all Here is my codding string
I've got a fairly simple question for all the Razor experts out there. I'm
First of all, I got a question in .asp page Class clsTesting Function hash_call
I am new here and got a question that is tricking me all day
I´ve got a question similar to this one: How to find all foreign keys?
Hey all, I've got a question about IIS7 rewrite. I'm wondering if there is
Got question. If i make query to server i use something like this: mysql_query(select
I got a question about Constructors.I think constructors are all just our convenience instead
I got this question for homework, and all I can think of is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.