The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


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