8 Replies Latest reply on Jul 12, 2006 4:16 PM by Rothrock

    I really would love some feed back on this

    gregmax17 Level 1
      I developing a game and am calling two external .swf files on to the stage at the same time. How do I make these two communicate probably between one another from the stage without breaking down or crashing?

      I have on the stage a reapeated loop so when it receives an action, or variable, it will trigger one of the two external .swf files. But after the first trigger, it doesn't work again!! It will only play what I call taht one time and not again. I have tried deleting the variables, setting them back to default, etc.

      Let me know if this isn't enough clarification on my problem or question. Again, I am basically asking for a way to commuicate between two external .swf files smoothly and without a worry of it crashing.

      Please help
        • 1. Re: I really would love some feed back on this
          I think that when an external swf ix loaded, its _root becomes the _root of the movie that loaded them. so you could navigate between the 2 external mcs by passing thourgh _root.

          I'm not sure but it's worth a try
          • 2. Re: I really would love some feed back on this
            Rothrock Level 5
            Once the two clips are loaded in it is as if they were movieclips in the movie. So if they are both loaded into clips on the main timeline it would be just the same as if you had two clips on the same timeline. No worries of crashing.

            When you say "…a repeated loop…" that makes me think you have done something that will cause a crash or a slowdown. Loops are a notorious thing in Flash that don't work how people think they are going to.

            And to help with something that works once, but doesn't work again is probably going to require that you show us your code.
            • 3. I really would love some feed back on this
              fikshin Level 1
              There is this object called a LocalConnection. it allows two independent swf's to send variables to eachother. It may not work in this case because they are both inside of a third swf. the other catch is that the recieving swf has to be open first.
              oh yeah you could also maybe use that client-side object called a SharedObject to read and write from. so i dont know, just some thoughts
              • 4. I really would love some feed back on this
                gregmax17 Level 1
                Ok, this is great news to hear. However, let me be clear on what I am picking up: Once the external movies are loaded on the stage (I am assuming any number, but in this case I am using loading only 2), I call call them as if they were on the main timeline?

                So let's say I have an instance name "testing" in a external .swf file, and if I were to load this external .swf file I can call the instance name testing on the main timeline from which Ioaded it from?
                • 5. Re: I really would love some feed back on this
                  Rothrock Level 5
                  Well, yes and no. So I have my main timeline with holder1 and holder2. I load swf1 into holder1 and swf2 into holder2. Now if testing is on the main timeline swf2 you can get it like this from the original movie:


                  Or from holder1 in either of the following ways:


                  You said, "… call call them as if they were on the main timeline?" And the answer is yes, only if the clip you loaded into was on the main timeline, if you loaded swf2 into holder2, but holder2 was at _root.clip5.branchA.holder2 then it would be a very different story. Understand.

                  If you are having difficulty, try this in your testing environment. After the clips have loaded, go to the debug menu and list variables. This will show you the paths to where everything is located.
                  • 6. Re: I really would love some feed back on this
                    gregmax17 Level 1
                    Sorry, I don't quite understand. Here is what I have when loading my external .swf files:

                    //load enemy swf
                    createEmptyMovieClip("enemy_holder", 10);
                    enemy_holder.loadMovie(['enemies/enemy_0.swf'], 0);
                    enemy_holder._x = 0;
                    enemy_holder._y = 0;
                    if(enemy_holder.bytesLoaded == enemy_holder.bytesTotal) {
                    //load char swf
                    createEmptyMovieClip("char_holder", 9);
                    char_holder.loadMovie("char.swf", 0);
                    char_holder._x = 0;
                    char_holder._y = 0;
                    if(char_holder.bytesLoaded == char_holder.bytesTotal) {
                    //in the nextFrame I do all the magic stuff, right?

                    I have tried:

                    enemy_holder.enemy_0._x += 10; //and
                    enemy_0._x += 10;

                    And both don't work. What am I not catching?
                    • 7. Re: I really would love some feed back on this
                      gregmax17 Level 1
                      nevermind, I fount why. Thanks everyone!! I really appreciate your help
                      • 8. Re: I really would love some feed back on this
                        Rothrock Level 5
                        Cool. You didn't ask for it, but I'll give you just a couple more pointers.

                        createEmptyMovieClip returns a reference to your clip. So you can assign it to a variable and then just use that variable for future referencing. It can save you a lot of heart ache with typos and the like. So your code could become:

                        curEnemy=createEmptyMovieClip("enemy_holder", 10);
                        curEnemy.loadMovie(['enemies/enemy_0.swf'], 0);
                        curEnemy._x = 0;
                        curEnemy._y = 0;

                        Its subtle, but can be very helpful.

                        The next issue is that you have a conditional comparing the bytesLoaded and bytesTotal. I'm seeing several potential problems here. First, I think that there is no bytesLoaded property for the movieclip class. There is a getBytesLoaded() method, but that is different.

                        Next your code is probably working because both bytesLoaded and bytesTotal ARE equal since neither exist. So they will both need to be replace with the methods.

                        Finally if this project is going to be delivered over the web? If so your code will break when it goes online since it will take time for the external swf to load. Flash won't pause on the loadMovie line until the clip loads and then proceed. It will start loading and continue on with the rest of the code in the frame. Unless enemy_0.swf is tremendously small, by the time Flash gets to the loading test there won't be anything loaded and Flash will just skip to the end.

                        Of course I'm not sure why you have to wait for enemy to load before you start loading char.swf. But we will pretend for right now that it does.

                        Since you basically need to keep comparing the loaded and total over time until the file has finished. Your choice for this would be either onEnterFrame or setInterval. The first is easier to explain so I will start there.

                        if(curEnemy.getBytesLoaded() == curEnemy.getBytesTotal() && curEnemy._width>0){
                        //the clip is loaded and ready
                        //do what you want but be sure to do:
                        delete this.onEnterFrame

                        That is the basic way to wait until a clip has fully loaded. Don't forget to delete the onEnterFrame when completed or it will just keep on going and wasting your processor.

                        PS: I'm guessing what you found out was that since you are loading a swf into enemy_holder that the name of the swf was not important and that only the name of the container clip was? So the answer was:

                        enemy_holder._x +=10;

                        Unless of course on the main timeline inside of enemy_0.swf there also happened to be a movieclip with the instance name of enemy_0, in which case the first example you gave would also do something!