17 Replies Latest reply on Mar 17, 2009 10:21 AM by kglad

    Sound Objects no longer play external swf HELP!

    dani_paulo
      I have several flash games and quizzes that I now want to put together as a collection on a CD ROM as a bumper pack to buy.
      I wasn't sure of the best way to do that but I figured that I can create a flash file with individuals buttons on that when pressed loads that SWF's into the main page and plays which I'll export as a standalone player.

      Sound good that's just what I wanted, only problem now is that the sound objects that are in the various games no longer play!
      What do I need to do so that they will play as they do when I play each SWF on their own? (Hopefully without too much re-programming of the original games as there are quite a few)!

      Any help would be appreciated.
        • 1. Re: Sound Objects no longer play external swf HELP!
          .:}x-=V!P=-x{:. Level 3
          if you are loading them into a MC use lockRoot

          myMovieClip._lockroot = true;

          from help file:
          The _lockroot property is undefined by default. You can set this property within the SWF file that is being loaded or in the handler that is loading the movie clip.

          For example, suppose you have a document called Games.fla that lets a user choose a game to play, and loads the game (for example, Chess.swf) into the game_mc movie clip. Make sure that, after being loaded into Games.swf, any use of _root in Chess.swf refers to _root in Chess.swf (not _root in Games.swf). If you have access to Chess.fla and publish it to Flash Player 7 or later, you can add this statement to Chess.fla on the main Timeline:
          • 2. Re: Sound Objects no longer play external swf HELP!
            dani_paulo Level 1
            At the moment I haven't been loading them into an MC as they just wouldn't play! The only way I could get them to work was to use:

            loadMovieNum("chess.swf",1);

            so that it loads into a level and it then plays fine except for the sound objects? So can you think of a way doing it this way round or can you think of a reason why it won't load and play into an MC?

            I confess my understanding of actionscript and how to construct it is limited so I'm piecing things together from articles and tutorials from the web so there could be a better way or I'm just writing it wrong!

            Much appreciated.
            • 3. Re: Sound Objects no longer play external swf HELP!
              dani_paulo Level 1
              I've had another look and tried three ways of loading the external SWF's (i'm using chess.swf as my example which is held in the folder 'loadswf ' purely for tidyness!) into my Main.fla -

              Firstly into a level:

              loadMovieNum("loadswf/chess.swf",1);

              Secondly into an MC:

              loadMovie("loadswf/chess.swf", mytarget1);
              mytarget1._lockroot = true;

              Then Thirdly:

              this.createEmptyMovieClip("mytarget1", this.getNextHighestDepth());
              mytarget1._lockroot = true;
              mytarget1.loadMovie("loadswf/chess.swf");

              All of which now load and play the external chess.swf but still without playing the sound objects!
              What am I doing wrong, is there something I should be adding into the chess.fla I've tried:

              this._lockroot = true;

              in the main timeline of chess.fla but still no go?!
              • 4. Re: Sound Objects no longer play external swf HELP!
                .:}x-=V!P=-x{:. Level 3
                I would think your third try should have worked.
                hmmm ok well Ill try to think of another idea and get back to you.
                is your audio loading from a external source? if so it could be because your chess.swf is inside a loadswf folder. if that is the case try putting the main SWF inside the loadswf folder and load it from there.
                • 5. Re: Sound Objects no longer play external swf HELP!
                  dani_paulo Level 1
                  Hi I put all files in the same location and still no go. Any other thoughts?
                  Thanks in advance.
                  • 6. Re: Sound Objects no longer play external swf HELP!
                    kglad Adobe Community Professional & MVP
                    change your sound instantiation lines from (something like):

                    var s:Sound = new Sound();

                    to (something like):

                    var s:Sound = new Sound(this);
                    • 7. Re: Sound Objects no longer play external swf HELP!
                      dani_paulo Level 1
                      Hi guys, I'm re-looking at the codes in all the games as they're done differently and I'll try out your suggestions.

                      will report back.
                      Thanks
                      • 8. Re: Sound Objects no longer play external swf HELP!
                        kglad Adobe Community Professional & MVP
                        try mine first. it's the most likely cause of the problem. if that fails, try enabling the _lockroot property of your external swf's main timeline.
                        • 9. Re: Sound Objects no longer play external swf HELP!
                          dani_paulo Level 1
                          I tried yours kglad and yes brilliant the music is now playing however It's now given me another problem!
                          I wasn't sure whether to start another topic or not but as it's related I thought I'd keep it here.

                          All sound are now working but one of the game types a Jigsaw puzzle isn't playing correctly!
                          I've tried running it on it's own and it still works fine but when loaded into another swf, it's no go - I think it's one of those pesky _root. problems!!
                          The jigsaw puzzle is something that I've put together from tutorials I've seen etc. and I've never been 100% sure on what actionscript controls what but I'll break it down as best I can understand it! (It does work!) I'd be grateful if can you take a look and see if it's something obvious I'm just missing.

                          So I now have a MainButtons.swf that purely holds the selection buttons for each of the external game swf's the button goes to a frame that contains the actionscript:

                          //Loads revelevant game into an empty MC - jig01
                          this.createEmptyMovieClip("jig01_mc", this.getNextHighestDepth());
                          jig01_mc_lockroot = true; // not sure If I need this line or not?
                          jig01_mc.loadMovie("JIGSAW01.swf");

                          This works!

                          The Jigsaw puzzle has a a frame for the START, frame for the BEGIN and one for COMPLETED and END. It plays fine until the part where it checks to see if all pieces are placed correctly and then it should move to the COMPLETED and END frame but it doesn't it just stays there completed without moving on!!

                          The code works like this:
                          START frame
                          no actionscript just the instructions on how to play and the start button takes you to BEGIN frame.

                          BEGIN frame
                          on the main timeline is:

                          stop();
                          no_piece = 20;
                          success = 0;
                          for (i=1; i<=no_piece; i++) {
                          this["piece"+i]._x = random(230)+380;
                          this["piece"+i]._y = random(320)+120;
                          this["piece"+i]._xscale = 95;
                          this["piece"+i]._yscale = 95;
                          }


                          On each of the jigsaw pieces is:

                          on (press) {
                          this.swapDepths(_root.getNextHighestDepth());
                          this.startDrag();
                          }
                          on (release) {
                          jigObj = new Sound(this);
                          jigObj.attachSound("jig_Piece.aif");
                          stopDrag();
                          if (eval(this._droptarget) == _parent.target1) {
                          this._x = _parent.target1._x;
                          this._y = _parent.target1._y;
                          this._xscale = 100;
                          this._yscale = 100;
                          this.jigObj.start(0,0);
                          this.enabled = false;
                          _parent.success++;
                          if (_parent.success == _parent.no_piece) {
                          _root.gotoAndPlay("completed");
                          }
                          } else {
                          this._x = random(230)+380;
                          this._y = random(320)+120;
                          }
                          }

                          The target name changes from 1 to 20 and the target MCs also sits in this frame.

                          There is also a timer on this frame which has this actionscript attached:

                          onClipEvent(load) {
                          //staticPrefix = "Timer: ";
                          startTime = getTimer();
                          staticSuffix = " seconds";
                          }
                          onClipEvent(enterFrame) {
                          curTime = getTimer();
                          elapsed = curTime - startTime;
                          _root.secondsElapsed = Math.floor(elapsed / 1000);
                          //trace(secondsElapsed);
                          this.gameTime = /*staticPrefix +*/
                          _root.secondsElapsed + staticSuffix;
                          }


                          COMPLETED frame
                          the screen fades out and moves to the END frame the actionscript on the main timeline is:

                          //remove all puzzle pieces
                          for (i=1; i<=no_piece; i++) {
                          _root["piece"+i].removeMovieClip();
                          }

                          End Frame
                          This congratulates you and you have the option to restart or quit and also gives you the time elapsed!

                          stop();
                          cheerObj = new Sound(this);
                          cheerObj.attachSound("Kids_CheerAppl.aif");
                          cheerObj.start(0,0);

                          // get pieces
                          seconds = _root.secondsElapsed;
                          numAttempts = Math.floor(_root.attemptCount / 2)
                          // now print scoring
                          sumText = "You took " + seconds
                          + " seconds to complete this game"
                          _root.summary = sumText;
                          // stop stage
                          stop();

                          Does that make sense? Like I said it all works fine if I just run it in Flash Player just inside another swf!
                          Thanks for any insights.
                          • 10. Re: Sound Objects no longer play external swf HELP!
                            kglad Adobe Community Professional & MVP
                            you're latest problem is caused by a _root issue. add:

                            this._lockroot=true;

                            to the main timeline of your jigsaw fla.
                            • 11. Re: Sound Objects no longer play external swf HELP!
                              dani_paulo Level 1
                              I added the line as you suggested but now the jigsaw pieces no longer drop into place when they're dragged over the correct target area they just snap back to their starting place!!
                              • 12. Re: Sound Objects no longer play external swf HELP!
                                kglad Adobe Community Professional & MVP
                                you're missing some code that defines target1 for each of your puzzle pieces.
                                • 13. Re: Sound Objects no longer play external swf HELP!
                                  dani_paulo Level 1
                                  OK great, I know this sounds daft but as I said I'm a newbie actionscipter, why do I need to define the targets haven't I already done that? As I said the jigsaw is already working fine as a complete game on its own so what has made it change when running inside another swf?
                                  I am learning as I go!

                                  Should I place this new code, on the actual jigsaw pieces, target pieces or on the main timeline? Is it some kind of var ? I already use this code:

                                  if (eval(this._droptarget) == _parent.target1) {
                                  this._x = _parent.target1._x;
                                  this._y = _parent.target1._y;

                                  attached to each jigsaw piece and each of the target MCs have their name as target1 etc.
                                  I'm guessing that i've only telling the piece where it has to go but I haven't actually defined what these 'targets' are, is that right?
                                  Thanks in advance.
                                  • 14. Re: Sound Objects no longer play external swf HELP!
                                    dani_paulo Level 1
                                    OK great, I know this sounds daft but as I said I'm a newbie actionscipter, why do I need to define the targets haven't I already done that? As I said the jigsaw is already working fine as a complete game on its own so what has made it change when running inside another swf?
                                    I am learning as I go!

                                    Should I place this new code, on the actual jigsaw pieces, target pieces or on the main timeline? Is it some kind of var ? I already use this code:

                                    if (eval(this._droptarget) == _parent.target1) {
                                    this._x = _parent.target1._x;
                                    this._y = _parent.target1._y;

                                    attached to each jigsaw piece and each of the target MCs have their name as target1 etc.
                                    I'm guessing that i've only telling the piece where it has to go but I haven't actually defined what these 'targets' are, is that right?
                                    Thanks in advance.
                                    • 15. Re: Sound Objects no longer play external swf HELP!
                                      kglad Adobe Community Professional & MVP
                                      i don't see where you've defined _parent.target1 for your puzzle pieces. it must be somewhere if that works as a stand-alone.

                                      but the problem is related to that if-statement never evaluating to true. so, to debug you can use something like the following. drop one of the pieces on its intended target and see what your drop-target is and what _parent.target1 is:



                                      • 16. Re: Sound Objects no longer play external swf HELP!
                                        dani_paulo Level 1
                                        Apologies for the 3month delay had to stop to work on another project so I'm getting back up to speed with this same problem.

                                        I've looked over my original code for the whole project (see previous post 12/02/2008 03:30:51 PM) and the only place where target1 etc is defined is actually in the properties box for each piece where it's named target1 etc.

                                        So I added the above code you suggested to my jig piece and in the output window I get:
                                        _level0.target1 _level0.target1

                                        Is that what you were expecting to see or not? Like i've said before I'm a newbie to actionscript and I'm not sure what is supposed to happen.

                                        I hope this gives you a clue to helping my problem.
                                        Thanks in advance

                                        • 17. Re: Sound Objects no longer play external swf HELP!
                                          kglad Adobe Community Professional & MVP
                                          i don't remember this any more.