Quantcast
Channel: Adobe Community : All Content - Adobe Animate CC - General
Viewing all articles
Browse latest Browse all 13519

Preloader ignores external swf's actionscript

$
0
0

Hey guys

 

I have an External.swf file that is a video. The swf is 1135 frames long and running just fine by itself, stopping as I want when the actionscript says stop(); on the first frame and looping the end of the clip with gotoAndPlay(837).

 

The preloader SwfLoader.swf linked to the External.swf shows the percentage of bytes loaded as it should. However, it runs the video (sound playing in the background) while the preloader shows the loading progress I think it's because it doesn't load the first frame first.

Once the external swf is loaded, it plays the video again, still ignoring the first actionscript frame that says stop(); and the last frame gotoAndPlay(837).

 

Thank you.

 

Here is the preloader's actionscript on the first and only frame:

 

import flash.geom.*

import flash.display.*

 

 

var loadurl:String = "External.swf";

var nDepth:Number = 0;

var nWidth:Number = 200;

var nHeight:Number = 20;

var nPadding:Number = 3;

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 mcLoadBarBg:MovieClip = mcLoader.createEmptyMovieClip("LoadBarBg_MC", nDepth++);

var mcLoadBar:MovieClip = null; //Duplicated later with mcLoadBarBg

var txtPercLoad:TextField = null; //Create after duplication

var cMatrix:Matrix = new Matrix();

mcLoader._alpha = 0;

cMatrix.createGradientBox(nWidth, nHeight, 0, nPadding, nPadding);

cLoader.addListener(oListener);

mcLoader.lineStyle(1, 0x000066, 100);

DrawRect(mcLoader, 0, 0, nWidth, nHeight);

mcLoadBarBg.lineStyle(1, 0x0000FF, 0);

mcLoadBarBg.beginGradientFill("linear", [0x006699, 0x0066FF], [100,100], [0, 255], cMatrix, SpreadMethod.PAD);

DrawRect(mcLoadBarBg, 0, 0, nWidth - nPadding*2, nHeight - nPadding*2);

mcLoadBarBg.endFill();

mcLoadBar = mcLoadBarBg.duplicateMovieClip("LoadBar_MC", nDepth++);

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

mcLoadBar._alpha = 80;

mcLoadBarBg._alpha = 30;

Translate(mcTextMask, nPadding, nPadding);

Translate(mcLoadBarBg, nPadding, nPadding);

Translate(mcLoadBar, nPadding, nPadding);

mcLoadBar._xscale = 0;

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;

SetTextFormat(txtPercLoad, "0%");

mcLoader._alpha = 100;

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() + "%");

            mcLoadBar._xscale = nPercLoaded;

   }

}

 

 

function onContentLoaded(Void):Void

{

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

   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 <= 0) startLoadedContent();

   }

}

 

 

function startLoadedContent(Void):Void

{

   delete _root.onEnterFrame;

   mcLoader.removeMovieClip();

   mcContent._alpha = 100;

   mcContent.play();

}

 

 

function DrawRect(mc:MovieClip, nX:Number, nY:Number, nW:Number, nH:Number, nR:Number)

{

   trace("DrawRect in: " + mc);

   if(nR == undefined) nR = 6;

   mc.moveTo(nX+nR,nY);

   mc.lineTo(nX+nW-nR,nY);

   mc.curveTo(nX+nW,nY,nX+nW,nY+nR);

   mc.lineTo(nX+nW,nY+nH-nR);

   mc.curveTo(nX+nW,nY+nH,nX+nW-nR,nY+nH);

   mc.lineTo(nX+nR,nY+nH);

   mc.curveTo(nX,nY+nH,nX,nY+nH-nR);

   mc.lineTo(nX,nY+nR);

   mc.curveTo(nX,nY,nX+nR,nY);

}

 

 

function SetTextFormat(txtField:TextField, sText:String)

{

   var txtFmt:TextFormat = new TextFormat();

   sText = "Loading... " + sText;

   txtFmt.font = "Verdana";

   txtFmt.align = "center";

   txtFmt.size = 11;

   txtFmt.color = 0x000066;

   txtFmt.bold = true;

   txtField.selectable = false;

   txtField.text = sText;

   txtField.setTextFormat(txtFmt);

   txtFmt = null;

}

 

 

function Translate(mc:MovieClip, nX:Number, nY:Number):Void

{

   mc._x = nX;

   mc._y = nY;

}


Viewing all articles
Browse latest Browse all 13519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>