4 Replies Latest reply on Sep 10, 2006 11:51 AM by dad_1953

    Scoping Question when one movie loads a second movie

    dad_1953
      I have a movie that is just a preloader for the main movie. This preloader movie has the loader and progress bar components so that I can show the process of the main movie loading. When I load a sound file in frame 1 of the main movie to be used later in the movie and run the main movie (with out being called from the preloader movie) the sound will play when it is called (told to play). However if I call the main movie from the preloader movie, the sound will not play. To make the sound play I have to load the sound in the preloader movie.

      I am sure that this is a scoping problem and I am not correctly coding for the location of the sound.

      The code for loading the sound is :

      if(_global.Behaviors == null)_global.Behaviors = {};
      if(_global.Behaviors.Sound == null)_global.Behaviors.Sound = {};
      if(typeof this.createEmptyMovieClip == 'undefined'){
      this._parent.createEmptyMovieClip('BS_sndErrorMsg',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
      _global.Behaviors.Sound.sndErrorMsg = new Sound(this._parent.BS_sndErrorMsg);
      } else {
      this.createEmptyMovieClip('_sndErrorMsg_',new Date().getTime()-(Math.floor((new Date().getTime()) /10000)*10000) );
      _global.Behaviors.Sound.sndErrorMsg = new Sound(this.BS_sndErrorMsg);
      }
      _global.Behaviors.Sound.sndErrorMsg.attachSound("ErrorMsgSound");
      if (false) {
      _global.Behaviors.Sound.sndErrorMsg.start(0,1);
      }



      The code to play the sound is:

      _global.Behaviors.Sound.sndErrorMsg.start(0,1);


      I would like to keep the preloader movie as small as possible and don’t want to load any sound files in it.

      How do I load the sound files in the main movie and play them when needed (using actionscripts) from the main movie when the main movie is loaded from the preloader movie?

      Thank you,
      Steve
        • 1. Re: Scoping Question when one movie loads a second movie
          dad_1953 Level 1
          I have not been able to figure out this scoping problem. Is there anyone out there that can help me or at least point me in the right direction?

          Thank you,
          Steve
          • 2. Re: Scoping Question when one movie loads a second movie
            scrubjay
            "I have a movie that is just a preloader for the main movie. This preloader movie has the loader and progress bar components so that I can show the process of the main movie loading. "

            Yes, that's what I am doing too, and I had a problem when an important button in the main movie no longer working properly.

            I found an answer to this issue in another thread. In the large (external) file that your preloader is loading, place this in the first frame:

            this._lockroot=true;

            That solved the problem for me.


            • 3. Re: Scoping Question when one movie loads a second movie
              dad_1953 Level 1
              Thank you, I will try this tomorrow.
              • 4. Re: Scoping Question when one movie loads a second movie
                dad_1953 Level 1
                Putting the following code on frame one in the movie being loaded by the preloader corrected the problem.
                this._lockroot=true;

                The following is what Flash 8 help file says about _lockroot

                _lockroot (MovieClip._lockroot property)

                public _lockroot : Boolean

                A Boolean value that specifies what _root refers to when a SWF file is loaded into a movie clip. 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:

                this._lockroot = true;

                If you don't have access to Chess.fla (for example, if you are loading Chess.swf from someone else's site into chess_mc), you can set the Chess.swf _lockroot property when you load it. Place the following ActionScript on the main Timeline of Games.fla:

                chess_mc._lockroot = true;

                In this case, Chess.swf can be published for any version of Flash Player, as long as Games.swf is published for Flash Player 7 or later.

                When calling loadMovie(), set the MovieClip._lockroot property to true in the loader movie, as the following code shows. If you don't set _lockroot to true in the loader movie, any references to _root in the loaded movie point to the _root of the loader instead of the _root of the loaded movie:

                myMovieClip._lockroot = true;

                Availability: ActionScript 1.0; Flash Player 7