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 783515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:33:37+00:00 2026-05-14T20:33:37+00:00

I am loading one swf into another using the Loader class, but when the

  • 0

I am loading one swf into another using the Loader class, but when the child swf finishes loading and is added to the display list, its Document Class is not instantiated. I have a few trace statements that should execute when the object is created, but nothing is happening when loaded into the parent SWF. When I compile the child SWF on its own, the Document Class runs as expected.

So I’m wondering… how do I associate a child SWF’s Document Class with Loader.content?

Code updated with a solution from Kishi below.

public class Preloader extends Sprite {
    import flash.net.*;
    import flash.display.*;
    import flash.events.*;

    // code in parent SWF's Document Class (Preloader.as)
    private var swfLoader:Loader;
    public var mainMovie:MovieClip;

    public function Preloader(){   
        swfLoader = new Loader();
        swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderDone);
        swfLoader.load(new URLRequest("mainmovie.swf"));
    }

    private function loaderDone(e:Event):void {
        // Cast Loader.content to MovieClip
        mainMovie = MovieClip(swfLoader.content);

        mainMovie.addEventListener(Event.ADDED_TO_STAGE, mainMovieAddedListener);

        addChildAt(mainMovie, 0);

    }
    private function mainMovieAddedListener(e:Event):void {
       // init() not necessary
    }
}

// MainMovie.as runs after casting swfLoader.content to MovieClip

public class MainMovie extends Sprite {

    public function MainMovie(){
        trace('MainMovie WHATTUP'); 
    }

    public function init():void {
        trace('init'); 
    }
}

Cheers!

  • 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-14T20:33:37+00:00Added an answer on May 14, 2026 at 8:33 pm

    The problem is how you are trying to access the swf instance.

    First, the document class instance is referred by Loader‘s content property. You’d reference it like this:

    var swf:DisplayObject = swfLoader.content;
    

    But, even then you’d have to cast the DisplayObject either to it’s real class (MainMovie, in this case) or a dynamic class (such as MovieClip), as you are trying to use a custom property, that’s not part of DisplayObject itself. Therefore, you could call MainMovie.init() like so:

    var swf:MovieClip = MovieClip(swfLoader.content);
    swf.init();
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 450k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Validators don't prevent the normal course of the asp.net lifecycle… May 15, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer You can access the app delegate through [[UIApplication sharedApplication] delegate]… May 15, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer First off...FORGET what Microsoft WANTS you to use, you should… May 15, 2026 at 8:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.