Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: Accessing MC instances inside loaded SWF

  1. #1

    Accessing MC instances inside loaded SWF

    Ok... I feel like an idiot. Although I've been working with AS3 since the start... and for the life of me I can't seem to access a movie clip instance inside a loaded SWF! I've searched high and low. Help is much appreciated.

    Here's what I have: An external SWF named map.swf. Inside that is a movie clip instance named "portland_mc". Here's my code that doesn't work:

    Code:
    private var _mapLoader :Loader;
    private var _mapLoaded :Boolean = false;
    private var _myMap :MovieClip = new MovieClip();
    
    public function LoadMap() :void
    {
       _mapLoader = new Loader();
       _mapLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, DoneLoading);
       _mapLoader.contentLoaderInfo.addEventListener("ioError", ErrorLoading);
       _mapLoader.load(new URLRequest("assets/UI/map.swf"));
    
       function DoneLoading(evt :Event) :void
       {
          trace("Done loading map!");
         _mapLoaded = true;
         _myMap = MovieClip(_mapLoader.content);
         addChild(_myMap);
         _myMap.portland_mc.gotoAndStop(1); // doesn't work!!!!      
       }
    
       function ErrorLoading(evt :Event) :void
       {
          trace("Error! - Could not load external map SWF file!");
       }
    }
    
     // Assume the nav button event has been declared and bound to this handler
    public function MapButtonOnClick(evt :MouseEvent) :void
    {
       // Make sure map content is loaded
       if (_mapLoaded)
       {
          // Play animation of portland_mc (a MC instance inside the loaded SWF)
          _myMap.portland_mc.gotoAndPlay(2); // doesn't work either!!!!
       }     
    }
    Again, any help is appreciated.

  2. #2
    Ok... I found the answer. Never underestimate the power of isolated testing! hehe

    The problem is that the Loader.content is NOT the loaded SWF itself!; .content is a container (of type DisplayObject). This container HAS inside it the loaded SWF movie. So my hierarchy referencing was wrong. I was trying to access an embedded MC instance "portland_mc" inside the .content object. Duh!

    Here's the solution, albeit ugly.

    Code:
    ...
       function DoneLoading(evt :Event) :void
       {
          trace("Done loading map!");
         _mapLoaded = true;
         var contentContainer :MovieClip = MovieClip(_mapLoader.content);
         _myMap = (MovieClip(contentContainer.getChildAt(0))); // grabs the actual SWF
         addChild(_myMap);
         _myMap.portland_mc.gotoAndPlay(2); //access to embedded MC instance WORKS!!!     
       }
    ...
    Any solutions that are more elegant are welcomed.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012