8 Replies Latest reply on Aug 15, 2010 7:24 PM by alexee77

    How to prevent .swf file from the 2nd playing?

    alexee77

      There is a .swf file with fade out the white cover.

       


      var picTotal:Number = 1;
      var lightSpeed:Number = 5;
      var delay:Number = 5000;
      var count:Number = 0;
      function init():Void {
      var white:MovieClip = this.createEmptyMovieClip("wh", 10);
      with (white) {
      beginFill(0xFFFFFF);
      lineTo(Stage.width, 0);
      lineTo(Stage.width, Stage.height);
      lineTo(0, Stage.height);
      lineTo(0, 0);
      endFill();
      }
      white.blendMode = "add";
      showNext(white);
      }
      function showNext(clip:MovieClip):Void {
      clip.onEnterFrame = function():Void {
      this._alpha -= lightSpeed;

       

       

       


      This .swf file we would like to use in the 1st page of the web-site and in the following pages.
      The question:
      How is it possible to do so that in the 1st page it is loading with this effect of fade out the white cover,
      and in the following pages only the last frame of .swf clip is displayed, i.e. the static picture that is already loaded in the 1st page.

       

       

       

      I has been advised that this can be made by the commands asf.:

       

       

       

      stop();
      if(_root.) {
      goToAndPlay("on")
      }
      else
      {
      goToAndPlay("off")
      }

       

       

       

      However, I cannot understand how can it be made exactly. It seems this code is incomplete.
      It seems, there should be a communication between AS2 and html/php code.

        • 1. Re: How to prevent .swf file from the 2nd playing?
          DazFaz Level 1

          I have solved this same problem in the past by passing a variable through the object tag within the page where the swf sits and plays.

           

          <param name="movie" value="mySWF.swf?firstRun=true" />

           

          Then within the all you need to do is take this boolean and impliment it into the script you already have:

           

          stop();
          if(firstRun) {
          goToAndPlay("on")
          }
          else
          {
          goToAndPlay("off")
          }

           

          Then on all the pages you want your swf to go to the static image:

           

          <param name="movie" value="mySWF.swf?firstRun=false" />

          • 2. Re: How to prevent .swf file from the 2nd playing?
            alexee77 Level 1

            Hi,

             

            Thank you for your advice. However, by some reason this makes no changes to the movie load.
            The repeated loading remains, there is no load of a static image on the pages with

             

            <object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="top"
            codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" border="0" width="800" height="90">
            <param name="movie" value="flash/top.swf"?firstRun=false" />
            <param name="quality" value="best">
            <param name="loop" value="false">
            <embed src="flash/top.swf" loop="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"
            name="top" width="800" height="90"></object>

             


            Code of .swf file:

             

            var picTotal:Number = 1;
            var lightSpeed:Number = 3;
            var delay:Number = 5000;
            var count:Number = 0;
            function init():Void {
            var white:MovieClip = this.createEmptyMovieClip("wh", 10);
            with (white) {
            beginFill(0xFFFFFF);
            lineTo(Stage.width, 0);
            lineTo(Stage.width, Stage.height);
            lineTo(0, Stage.height);
            lineTo(0, 0);
            endFill();
            }
            white.blendMode = "normal";
            showNext(white);
            }
            function showNext(clip:MovieClip):Void {
            clip.onEnterFrame = function():Void {
            this._alpha -= lightSpeed;
            if(this._alpha<=0){
            delete this.onEnterFrame;
            }
            };
            }
            init();
            stop();
            if(firstRun) {
            goToAndPlay("on")
            }
            else
            {
            goToAndPlay("off")
            }

             


            Please, check, if all is correct.

            • 3. Re: How to prevent .swf file from the 2nd playing?
              DazFaz Level 1

              Hi,

               

              I have checked this and it works ok for me:

              // within the fla file add:

               

              if(firstRun=="true"){
              init();
              }

               

               

               

               

              // within the page that dispays your swf file

              <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="fade" align="middle">
              <param name="allowScriptAccess" value="sameDomain" />
              <param name="allowFullScreen" value="false" />
              <param name="movie" value="fade.swf?firstRun=false" />
              <param name="quality" value="high" />
              <param name="bgcolor" value="#ff0000" />
              <embed src="fade.swf?firstRun=false" quality="high" bgcolor="#ff0000" width="550" height="400" name="fade" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
              </object>

              • 4. Re: How to prevent .swf file from the 2nd playing?
                alexee77 Level 1

                Thank you for your message. Does this addon to the code prevents from the loop or from the second loading? I have still the repeated loading of the same .swf file. If the file is loading in /index.html , then after clicking on /index.en.html it is loading again, and does not skip to the last frame.

                • 5. Re: How to prevent .swf file from the 2nd playing?
                  DazFaz Level 1

                  Sorry maybe I didnt make myself clear.

                   

                  In any other pages where you dont want the fade to trigger you change the firstRun=false.

                   

                  If you want the fade to work then you change the firstRun=true

                   

                  in the index.html object tag for the flash swf file you have:

                   

                  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#ve rsion=9,0,0,0" width="550" height="400" id="fade" align="middle">
                  <param name="allowScriptAccess" value="sameDomain" />
                  <param name="allowFullScreen" value="false" />
                  <param name="movie" value="fade.swf?firstRun=true" />
                  <param name="quality" value="high" />
                  <param name="bgcolor" value="#ff0000" />
                  <embed src="fade.swf?firstRun=true" quality="high" bgcolor="#ff0000" width="550" height="400" name="fade" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
                  </object>

                   

                  And in all the otehr web pages where you dont want the fade to fade in you have:

                   

                  <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#ve rsion=9,0,0,0" width="550" height="400" id="fade" align="middle">
                  <param name="allowScriptAccess" value="sameDomain" />
                  <param name="allowFullScreen" value="false" />
                  <param name="movie" value="fade.swf?firstRun=false" />
                  <param name="quality" value="high" />
                  <param name="bgcolor" value="#ff0000" />
                  <embed src="fade.swf?firstRun=false" quality="high" bgcolor="#ff0000" width="550" height="400" name="fade" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
                  </object>

                   

                  The code within your flash file still stays the same:

                   

                  if(firstRun=="true"){
                  init();
                  }

                   

                  What the firstRun variable does is it stops the init() function from being triggered.

                   

                  I hope that helps.

                   

                  The rest of the code already

                  • 6. Re: How to prevent .swf file from the 2nd playing?
                    alexee77 Level 1

                    Thank you for your advice, but by some reason, it does not work and continue to load every time.
                    Maybe there is any error in the code of .swf file?

                     

                    var picTotal:Number = 1;
                    var lightSpeed:Number = 3;
                    var delay:Number = 5000;
                    var count:Number = 0;
                    function init():Void {
                    var white:MovieClip = this.createEmptyMovieClip("wh", 10);
                    with (white) {
                    beginFill(0xFFFFFF);
                    lineTo(Stage.width, 0);
                    lineTo(Stage.width, Stage.height);
                    lineTo(0, Stage.height);
                    lineTo(0, 0);
                    endFill();
                    }
                    white.blendMode = "normal";
                    showNext(white);
                    }
                    function showNext(clip:MovieClip):Void {
                    clip.onEnterFrame = function():Void {
                    this._alpha -= lightSpeed;
                    if(this._alpha<=0){
                    delete this.onEnterFrame;
                    }
                    };
                    }
                    init();
                    if(firstRun="true"){
                    init();
                    }
                    else
                    {
                    goToAndPlay ("off")
                    }

                     

                     

                     

                    html code is also as recommended:

                     

                    <object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="top"
                         codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" border="0" width="800" height="90">
                    <param name="allowScriptAccess" value="sameDomain" />
                    <param name="allowFullScreen" value="false" />
                         <param name="movie" value="flash/top.swf?firstRun=false" />
                    <param name="quality" value="best">
                    <param name="loop" value="false">
                         <embed src="flash/top.swf?firstRun=false" loop="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"
                         name="top" width="800" height="90"></object>

                    • 7. Re: How to prevent .swf file from the 2nd playing?
                      DazFaz Level 1

                      Hi,

                       

                      Within your code you are declaring the "firstRun" as "true".

                       

                      if(firstRun="true"){
                           init();
                      }

                       

                      This is wrong it should be:

                       

                      if(firstRun == "true"){
                      init();
                      }

                       

                      Im not sure if you need the else statement either where you are directing the playhead to a frame name "off". Unless you have a frame flagged up as "off". The code I have given you just stops the fade movieClip from running if the condition firstRun == "false". If the movieClip "white" does not load and run, the image below will just appear straight away.

                       

                      I hope this helps.

                      • 8. Re: How to prevent .swf file from the 2nd playing?
                        alexee77 Level 1

                        Thank you very much for your advice. I'll try to implement it.