1 Reply Latest reply on Jul 25, 2006 1:02 PM by a.neko®

    Accessing MovieClip instances in a loaded SWF

    a.neko® Level 1
      The situationis as follows:

      loadedSWF.swf (published with Flash Player 8 AS2 or Flash Player 9 Alpha AS3), contains on stage symbols with instance names: clipA, clipB, clipC, etc... No ActionScript is included in the file.

      In a Flex Builder 2.0 project, a component extending mx.core.UIComponent loads loadedSWF.swf:

      // script
      var request:URLRequest = new URLRequest("loadedSWF.swf");
      var loaded:Loader = new Loader();
      loaded.load(request);
      addChildAt(loaded,0);


      loadedSWF.swf successfully appears in the component display list, but MovieClip instances it contains are impossible to access.

      It's existence is verified:

      // script
      trace(getChildAt(0)) // result: [object Loader]
      trace(getChildAt(0).root) // result: [object _system_mx_managers_SystemManager]

      However, even if getChildAt(0).root returns a mx.managers.SystemManager, and mx.managers.SystemManager supports numChildren property, trace(getChildAt(0).root.numChildren) throws error: 1119: Access of possibly undefined property numChildren through a reference with static type flash.display:DisplayObject.. Other methods, as getChildAt(), etc... are also impossible to call. Direct access with getChildAt(0).root.clipA also throws an error, etc...

      Is it possible to access MovieClip instances on a loaded SWF file's stage from a component that loads it? I would appreciate any advice on this issue.

      a.neko


      Note:
      The goal is to be able to load several MovieClips into a component in a single SWF file load, and then to instantiate them separately when required with addChild() & addChildAt() methods.
        • 1. Accessing MovieClip instances in a loaded SWF
          a.neko® Level 1
          Solution found:

          (Verified for loadedSWF.swf published with Adobe Flash Professional 9 Alpha Public)

          // script (extract from the Flex 2.0 AS3 component class)

          protected var clip:MovieClip = new MovieClip();

          protected final function requestSWF(value:String):void {
          var request:URLRequest = new URLRequest(value);
          var requested:Loader = new Loader();
          requested.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onRequestSWFComplete);
          requested.load(request);
          return;
          };

          protected final function onRequestSWFComplete(event:Event):void {
          event.stopPropagation();
          this.clip = event.target.content.clipA; // conversion to a local variable.
          this.addChild(this.clip);
          return;
          };

          this.requestSWF("loadedSWF.swf");


          Result: clipA is separately added to the component's display list.

          a.neko