1 Reply Latest reply on Aug 8, 2012 7:02 PM by Ned Murphy

    External SWF dissapears afte sometime

    separm@yahoo.com

      Hi There!

       

      I have a preloader to preload a SWf file, everything works fine, except, when I run html file on any browser, external swf file dissapears after 1-2 minutes,

      basically, I put preloader (swf file), on html code, and preload the external swf.

      this is the code:

       

      import flash.geom.*

      import flash.display.*

       

      var loadurl:String = "external.swf";

      var nDepth:Number = 0;

      var nWidth:Number = 200;

      var nHeight:Number = 20;

      var cLoader:MovieClipLoader = new MovieClipLoader();

      var oListener:Object = {onLoadInit:onContentLoaded};

      var mcLoader:MovieClip = this.createEmptyMovieClip("Loader_MC", 0);

      var mcContent:MovieClip = this.createEmptyMovieClip("Content_MC", 1);

      var cMatrix:Matrix = new Matrix();

       

      cLoader.addListener(oListener);

       

      txtPercLoad = mcLoader.createTextField("PercLoad_TXT", nDepth++, 0, 0, nWidth, nHeight);

      mcContent._alpha = 0;

      mcContent._lockroot = true;

      mcLoader._x = Stage.width/2 - mcLoader._width/2;

      mcLoader._y = Stage.height/2 - mcLoader._height/2;

      txtPercLoad._x = mcLoader._width/2 - txtPercLoad._width/2;

      txtPercLoad._y = mcLoader._height/2 - txtPercLoad._height/2;

      cLoader.loadClip(loadurl, mcContent);

       

      _root.onEnterFrame = function()

      {

         var nBytesLoaded:Number = mcContent.getBytesLoaded();

         var nBytesTotal:Number = mcContent.getBytesTotal();

         var nPercLoaded:Number = Math.round(nBytesLoaded / nBytesTotal * 100);

         if(nPercLoaded > 0)

         {

            SetTextFormat(txtPercLoad, nPercLoaded.toString() + "%");

         }

      }

       

      function onContentLoaded(Void):Void

      {

         SetTextFormat(txtPercLoad, "100%");

         cLoader.removeListener(oListener);

         delete _root.onEnterFrame;

         delete oListener;

         delete cLoader;

         _root.onEnterFrame = function()

         {

            //trace(_root + "::onContentLoaded::_root.onEnterFrame");

            var nInc:Number = 5;

            mcLoader._alpha -= nInc;

            mcContent._alpha += nInc;

            if(mcLoader._alpha <= 100) {mcLoader.removeMovieClip();};

         }

      }

       

       

       

      function SetTextFormat(txtField:TextField, sText:String)

      {

         var txtFmt:TextFormat = new TextFormat();

         sText = "Loading Content " + sText;

         txtFmt.font = "Arial";

         txtFmt.align = "center";

         txtFmt.size = 12;

         txtFmt.color = 0xff0000;

         //txtFmt.bold = true;

         txtField.selectable = false;

         txtField.text = sText;

         txtField.setTextFormat(txtFmt);

         txtFmt = null;

      }

       

       

      Please let me know what I am doing wrong? thanks in advance

        • 1. Re: External SWF dissapears afte sometime
          Ned Murphy Adobe Community Professional & MVP

          If you keep an eye on the value of mcContent._alpha, you'll see that because you never shut off that second onEnterFrame function, the _alpha property continues to go up until it reaches a maximum and then flips negative, which means it goes invisible.  I confirmed this with running your code.

           

          I don't know what the limit is.  In Actionscript, when a number limit is reached it is common for it to advance to its opposite limit - basically a looped numeric system.