2 Replies Latest reply on Apr 18, 2006 7:32 AM by kevmedia.com

    problem targeting a loaded MC (easy answer?)

    kevmedia.com Level 1
      Hi, thanks in advance. I'm lame and can't figure out how to target an external swf that I've loaded via AS. I have one main swf, and in that swf I'm creating an empty movie clip (called 'countryClip') and loading an external swf ('usa.swf'). So far, so good, the swf loads and it looks great. But when I try to click on the loaded swf, I get nothing. My usa.swf ('countryClip.usa'?) is just unclickable, and that's my problem. Any ideas why? What am I overlooking?

      [begin code]
      _root.createEmptyMovieClip("countryClip", 1);
      countryClip.loadMovie("usa.swf");
      // everything above works great. but then...

      _root.countryClip.onPress = function() {
      // has no effect at all.

      // so I put this into frame 1 of usa.swf
      onClipEvent (enterFrame) {
      trace(this._target);
      }

      // and that showed me this output:
      "/countryClip/usa" (no quotes)

      // which led me to believe that the following
      // should work...
      _root.countryClip.usa.onPress = function() {
      trace("pressed");
      }

      // but it does not work. Why?
      [/end code]
        • 1. Re: problem targeting a loaded MC (easy answer?)
          blemmo Level 1
          Hi,

          the loaded swf is accessible via the instance name of the MC that loaded it, so _root.countryClip.onPress should work. Now when you look at the Flash Help for loadMovie(), you'll find this:

          quote:

          Using event handlers with MovieClip.loadMovie() can be unpredictable. If you attach an event handler to a button by using on(), or if you create a dynamic handler by using an event handler method such as MovieClip.onPress(), and then you call loadMovie(), the event handler does not remain after the new content is loaded.

          So this should be the reason it's not working. One solution would be checking the loading progress, and assign the event when the clip is fully loaded. You can use something like the attached code, or use the MovieClipLoader class to load the swf and use it's events (e.g. onLoadInit) to assign the onPress event.

          greets,
          blemmo

          • 2. Re: problem targeting a loaded MC (easy answer?)
            kevmedia.com Level 1
            Blemmo, you rock. You've jogged my memory, I think I remember hearing something about that before. Having MC's 'forget' event handlers that were set before an external swf load seems like a really unintuitive 'feature', though. Is this considered to be a bug in Flash or is this really the way it's supposed to work? (understanding the logic behind this would make it easier to remember.)

            Thanks much for your sample code, I'll try it out this morning.