A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Problems targeting swf loaded with loadClip()

  1. #1
    flash grasshopper
    Join Date
    Feb 2005
    Posts
    156

    Problems targeting swf loaded with loadClip()

    Hi everyone,

    I'm having a really weird problem that I hope someone will be able to help me with. I'm using Actionscript 2.0.

    Basically, I have a main .swf, into which I am loading another .swf using loadClip(), on the click of a button. It loads into an empty movie clip on the timeline of the main .swf called container_mc. So far so good, this works.

    The problem comes when I am trying to control a movie clip that lives on the timeline of the external .swf. This clip has the instance name test_mc, and I'm trying to control it using the reference _level0.container_mc.test_mc. I have also tried just plain old container_mc.test_mc.

    Neither of these work, though when I apply a trace to test_mc with Actionscript on the timeline of the external swf (test_mc.onRelease = function () { trace(this); }), it returns the path _level0.container_mc.test_mc (when clicked on after being loaded into the main movie, obviously).

    Can anybody give me any ideas as to what is going wrong here? I've attached a couple of files demonstrating the problem I'm having.

    Cheers for any assistance!
    Attached Files Attached Files

  2. #2
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    What is it you are trying to make test_mc do, exactly?

    it loads, and it traces when you click it. It goes to the stop(); frame... but I see nothing else it should be doing.

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  3. #3
    flash grasshopper
    Join Date
    Feb 2005
    Posts
    156
    Well I'm trying to access it from within the main_swf file. So if you look in main_swf.fla, you will see that I am just trying (for an example) to set the alpha of test_mc to 20, by going _level0.container_mc.test_mc._alpha = 20; which doesn't work.

    I also have the line of code container_mc._alpha = 20; which does work. However, I'm really wanting to control test_mc itself, rather than the whole thing by referencing container_mc, because I will (in future) have other stuff (buttons, movie clips) within external_swf which I don't want to be affected.

    So basically I need to know how to tell test_mc that I'm talking to it - I thought it should just be the path that gets traced when you click on it, but this refuses to work.

  4. #4
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Okay. I will have a look with a button or so added and let you know here in a little bit.

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  5. #5
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    Okay, got it worked out for you. I have attached a zip of the example.

    Open main.swf and click "photos" button at bottom. This will load the extern.swf file into the main.swf stage. You will see a red box.

    Click the "do things" button and you will see the alpha of the red box go to 20.

    click the exit button to unload the movie.

    What we are doing here is using the loadMovieNum method and placing the extern movie on a specific level. From there we can simply call the level the movie is loaded onto do do specific things (in this case, changing alpha to 20).

    Check out the code on main.fla to see the code itself (on actions layer).
    Main thing to remember is to export for actionscript each item and also to give each item an instance name.

    Enjoy

    ~MoN
    Attached Files Attached Files
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  6. #6
    flash grasshopper
    Join Date
    Feb 2005
    Posts
    156
    Thanks very much for the effort you have put into this. Unfortunately loadMovieNum() doesn't really work with the rest of my code (the example I posted was just to illustrate the problem, the actual thing is much more complicated), but thanks for trying anyway, I appreciate the time you've taken to help.

  7. #7
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    I don't see why it wouldn't work. If your using loadMovie(), loadMovieNum() will work just as well. In my example I have the "exit" button to empty the container clip, in your movie you can put this on an onPress function and put the loadMovieNum code on the onRelease function of the same button.

    Anyway, if you want to control an external SWF with buttons from another swf you have to tell Flash what level the controlled MC is on. loadMovie won't allow for this, and everything will report as _level0 (root) because that's where it is interpreted at, not where it actually is.

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

  8. #8
    flash grasshopper
    Join Date
    Feb 2005
    Posts
    156
    Thanks mate, but actually I am not using loadMovie anywhere. I am in fact using the MovieClipLoader class, with the method loadClip(), which does a similar thing, but isn't quite commensurate.

  9. #9
    Eternal Newbie
    Join Date
    Apr 2006
    Location
    Bitter cold Hell of the crappy NW
    Posts
    392
    In that case you need to create a child mc inside a parent mc, all dynamically and on and on... basically...

    Code:
     // Parent movie clip
      myMC.createEmptyMovieClip("container", getNextHighestDepth());
     
      // Child movie clip
      myMC.container.createEmptyMovieClip("contentMC",5);
     
      // Loader
      var loader:MovieClipLoader = new MovieClipLoader();
      loader.loadClip("external.swf", myMC.container.contentMC);
     
      // Function
      myMC.container.onPress = function() {
         trace("Here I Am!");
      };
    Hope that helps. But seriously.. I would just rewrite and use the loadMovieNum method, it is so much simple and easier...

    ~MoN
    If I am wrong, please just correct me and move on.. there is no need for all that pointing and laughing! ~MoN

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center