Adding a preloader to determine external swf

Hi there! I have a script which works wonders! but need to add a preloader to it so that a text box will show the % remaining?...
The code is randomising the files which is what I want but just need to add a preloader... any suggestions?
Sample:
filename = ["A01.swf", "A02.swf", "A03.swf"];
path = "A/";
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(path+filename[k], movieTarget1);
Of if you know a link to something done before that would be swell!!!

filename = ["A01.swf", "A02.swf", "A03.swf"];
path = "A/";
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(path+filename[k], movieTarget1);
clearInterval(preloadI);
var preloadI:Number=setInterval(preloadF,100);
function preloadF(){
var fl:Number=movieTarget1.getBytesLoaded()/movieTarget1.getBytesTotal();
if(fl>0){
yourtextfield.text = (100-Math.round(100*fl))+" % Remaining";
if(fl==1){
clearInterval(preloadI);

Similar Messages

  • Preloader that changes external swfs every 5 seconds

    HI,
    I've done an web banner in flash that loads an external swf
    and changes for another external swf after 5 seconds. The banner
    have a preloader, but the problem becomes when it loads the first
    time. As the swfs aren't cached in the browser's cache yet, the
    time for 5 seconds starts to count from the preloader, and when the
    external swf finally shows, only rest 1 second and it is changed to
    another. There is a way to "freeze" the time for each external swf
    until it totally loads?
    The code that loads the swfs every 5 seconds (this code is
    placed into an action layer):
    begin of code:
    var intervalId:Number;
    var count:Number = 0;
    var maxCount:Number = 23;
    var duration:Number = 0;
    var banners:Array = new Array(
    "abatrade.swf",
    "bancobrasil.swf",
    "caparao.swf",
    "cedro.swf",
    "cesama.swf",
    "copasa.swf",
    "damatta.swf",
    "emtel.swf",
    "engedrain.swf",
    "extel.swf",
    "feedback.swf",
    "iti.swf",
    "intermedium.swf",
    "magnesita.swf",
    "maquenge.swf",
    "maxxdata.swf",
    "orteng.swf",
    "paiva.swf",
    "paraibuna.swf",
    "paraopeba.swf",
    "sabesp.swf",
    "serpro.swf",
    "soll.swf",
    "thawte.swf"
    function executeCallback(param:String) {
    var duration:Number = 5000;
    loadMovie(banners[count],loadmovie_mc);
    loadmovie_mc._x=0;
    loadmovie_mc._y=0;
    clearInterval(intervalId);
    if(count < maxCount) {
    count++ ;
    intervalId = setInterval(this, "executeCallback", duration,
    banners[count]);
    else {
    count=0;
    intervalId = setInterval(this, "executeCallback", duration,
    banners[count]);
    if(intervalId != null) {
    clearInterval(intervalId);
    intervalId = setInterval(this, "executeCallback", duration,
    banners[count]);
    //end of code
    And the code for the preloader (this code I place into the
    movieclip that loads the external swfs):
    //begin of code:
    onClipEvent(enterFrame) {
    var gtT:Number = this.getBytesTotal();
    var gtL:Number = this.getBytesLoaded();
    var gtP:Number = int((gtL/gtT)*100);
    if ( gtT > gtL ) {
    this._alpha = 0;
    _root.loader._alpha = 100;
    _root.loader.bar._width = gtP;
    clearInterval(intervalId);
    } else {
    this._alpha = 100;
    _root.loader._alpha = 0;
    intervalId = setInterval(this, "executeCallback", duration,
    banners[count]);
    delete onEnterFrame;
    //end of code
    Note that I tryed to freeze the time using a clearInterval in
    the second code, but it simply don't works...
    Any Ideas? Thanks
    Edson

    http://www.maxxdata.com.br/banners.zip
    Open the fla and preview the file with bandwidth preview (
    Crtl+Enter twice ). You will note that the third banner
    (caparao.swf) start to loads but it don't shows at all because the
    loading for a slow internet (56K) takes more than 5 seconds. So the
    loader skip to the next banner. Is there a way to "freeze" the time
    for the preloader (to give it enough time to the banner load
    completely, even in slow connections) and count the 5 seconds only
    to the banner itself?
    Thanks.

  • Loading external swf file in a new window

    Hi,
    I've got a few .swf files with video tutorials I've created using Captivate 4.
    I wanted to link them so I've created a main screen with menu with buttons in Flash.
    I've added AS to load the external swf files but they load in the same window. How can I load these .swf files in seperate window so that you could get back to the main window after you've finished watching?
    Here's my code:
    stop();
    var myLoader:Loader = new Loader();
    button1_btn.addEventListener(MouseEvent.CLICK, movie1_1);
    function movie1_1(e:MouseEvent):void
        var myURL:URLRequest = new URLRequest("01_01_Welcome.swf");
        myLoader.load(myURL);
        addChild(myLoader);
    I'm also attaching screenshot with menu in flash

    I've deleted the line and now the code lookes like that:
    stop();
    var myLoader:Loader = new Loader();
    button1_btn.addEventListener(MouseEvent.CLICK, movie1_1);
    function movie1_1(e:MouseEvent):void
        var myURL:URLRequest = new URLRequest("01_01_Welcome.swf");
        addChild(myLoader);
    Unfortunately, it doesn't load the .swf file when you click on the button...

  • Loading font from external *.swf

    So!
    I have 3 movies.
    1)Main movie - index.swf
    2)Movie with created & checked in linkadge "Export for
    runtime sharing" fonts in library - fonts.swf
    3)movie with text fields which need embeded fonts to work in
    a proper way. Fonts in the library checked in linkage as "import
    for runtime sharing" - content.swf
    What happens:
    I strike CTRL+ENTER and run movie index.swf.
    on the (for ex.) 10 frame it loads fonts.swf with
    movieClipLoader class..
    then in the same way on (for ex.) 100 frame, i load content
    swf
    BUT!!! before it starts loading process IT DOWNLOADS FONT.swf
    again
    SO HOW DO I PRELOAD fonts from external *.swf..
    maybe there is yhe way without using runtime sharing..
    but i've heard that loaded whith movieClipLoader movies don't
    adds objects from their library to main movie liblary...
    HOW DO I SOLVE THIS PROBLEM!

    can you give your erroe source code,and then i will give you the success code.
    in the function
    private function onLoadComplete(e:Event):void {}
    ApplicationDomain.currentDomain.getDefinition("com.scottgmorgan.ExternalMovie") ;
    use like this:
    var EMClass:Class=loader.contentLoaderInfo.applicationDomain.getDefinition("com.scottgmorgan.ExternalMovie") ;
    then you can new a instance :
    var emInstance:Object=new EMClass();
    emInstance.alert("hello word");
    and we also can use other method. so email me  [email protected]

  • Load second external swf after first is done?

    Hello,
    I have a main movie with a blank mc to hold my 2 external
    swf's. I load the first swf, things are fine. When it ends I'd like
    to load the 2nd swf into the same blank mc. Anybody have a solution
    or point me to a good tutorial?
    Thanks in advance.
    Pharaoh

    Here is the code:
    //this section is a preloader for the external swf
    var mcl:MovieClipLoader = new MovieClipLoader();
    var mclL:Object = new Object();
    mclL.onLoadProgress = function(target,loaded,total) {
    loader.percent.text = Math.round((loaded/total) * 100) +
    mclL.onLoadInit = function() {
    loader._visible = false;
    loader.percent.text = "";
    mcl.addListener(mclL);
    //the line below loads and plays the swf
    mcl.loadClip("wtts_spotlight.swf",holder);
    The way I have it working now is that I have actionscript at
    the end of the first swf telling the main movie to load the next
    swf in the blank mc:
    stop();
    _root.holder.loadMovie("NewZoo_Spotlight.swf", 1);
    I then repeat this code in the last frame of the
    "NewZoo_Spotlight.swf" but tell it to load the first swf again,
    thus creating the loop:
    stop();
    _root.holder.loadMovie("wtts_spotlight.swf", 1);
    This all works well but there has to be a way to do it so all
    actionscript is contained in frame one of the main movie, right?
    Thanks.

  • Preload external swf before play

    i have a project i am working on...but for some reason the solution i went with is not satisfying my instructor......
    so....here is my new code ( which is incorrect but i cant figure out how to arrange the preloader at the end )
    var Xpos:Number=0;
    var Ypos:Number=0;
    var swf:MovieClip;
    var bgloader:Loader = new Loader();
    var bgURL
    if(page==1){
    bgURL=new URLRequest("pages/home.swf");
    else if(page==2){
    bgURL=new URLRequest("pages/about.swf");
    else if(page==3){
    bgURL=new URLRequest("pages/projects.swf");
    else if(page==4){
    bgURL=new URLRequest("pages/experimental.swf");
    else if(page==5){
    bgURL=new URLRequest("pages/contact.swf");
    bgloader.load(bgURL);
    bgloader.x=Xpos;
    bgloader.y=Ypos;
    bg.addChild(bgloader);
    stop();
    var percent:Number = bgURL.bytesTotal;
    if(percent==100){
    gotoAndPlay("start");
    first off, i dont even know if what i am being asked to do is possible...but, what i am being requested to do is obviously load in the external swf BUT, the external swf cannot play until the MAIN swf is directed to "start"......
    i have done this numerous times in as1 and 2....but back then things were totally written different and if you do it the same way you run into migration issues....
    i thought this was solved already, but my instructor will not accept the method of using an event to be dispatched in the external SWF to tell the main swf when to play "start"....im not sure if there is any other way to do this?
    he wants the external swf to contain NO code other than what is necessary for its internal functions....
    everything is to be coded in the MAIN swf.....
    so im trying to use bytesTotal, and the percent==100 is just a number i threw in for example purposes.....i am just not figuring this out....
    any help is greatly appreciated

    From what I could gather based on your description, your instructor wants you to start playing when external swf is loaded completely.
    If my understanding is correct, what you need to do conceptually is:
    1. Instantiate Loader
    2. Add event listeners that you are interested in.
    3. Execute code corresponding to these listeners in their corresponding handler functions.
    As for No 2 - Usually there are at least 3 events that are of interest when dealing with Loaders:
    1. Event.COMPLETE - dispatched when entire target is loaded
    2. ProgressEvent.PROGRESS - dispatched when a new bytes packet arrives.
    3. IOErrorEvent.IO_ERROR - dispatched when something goes wrong with loading (say, wrong url, etc.)
    In your particular case it is supposed to be something like this (may not work because you did not describe what is the point of different swfs loading and how it affects entire application). SEE COMMENTS:
    stop();
    var swf:MovieClip;
    // always specify datatype
    var bgURL:URLRequest;
    if(page == 1) {
         bgURL = new URLRequest("pages/home.swf");
    else if (page == 2) {
         bgURL = new URLRequest("pages/about.swf");
    else if (page == 3) {
         bgURL = new URLRequest("pages/projects.swf");
    else if (page == 4) {
         bgURL = new URLRequest("pages/experimental.swf");
    else if (page == 5) {
         bgURL = new URLRequest("pages/contact.swf");
    var bgloader:Loader = new Loader();
    configureListeners();
    // now you are ready to load
    bgloader.load(bgURL);
    * Adds listeners.
    function configureListeners():void {
         // NOTE!!! Listeners are added to contentLoaderInfo - not Loader itself
         bgloader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
         bgloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
         bgloader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
    * Removes listeners.
    function removeListeners():void {
         bgloader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadComplete);
         bgloader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
         bgloader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
    function onLoadComplete(e:Event):void
         // depeneding on the situation
         // you may want to add loaded swf
         // but before if swf exists - you need to remove it
         if (swf && this.contains(swf)) {
              removeChild(swf);
              swf = null;
         swf = bgloader.content as MovieClip;
         addChild(swf);
         // now play
         this.gotToAndPlay("start");
         // dont't forget to remove listeners
         removeListeners();
    function onLoadError(e:IOErrorEvent):void
         // deal with the error
    function onProgress(e:ProgressEvent):void
         // here you update preloader if you have one
         trace("Progress", e.bytesLoaded, e.bytesTotal);
    On a side note, the way you deal with instnatiating URLRequests is not the most efficient or scalable. A better approach would be to keep them in an array and call by index. Note, conditionals are gone.
    var bgList:Array = [
              "pages/home.swf",
              "pages/about.swf",
              "pages/projects.swf",
              "pages/experimental.swf",
              "pages/contact.swf"];
    var bgURL:URLRequest = new URLRequest(bgList[page]);

  • How can I get a preloader to launch a main (external) swf file, and have the main file remove the preloader once it's fully loaded?

    Using Flash MX, ActionScript 2:
    I’ve been struggling for several weeks, trying to get a preloader to work on a large (~80 MB) photo portfolio file (using the method where the preloader is on frame 1 of the file, and when loading is completed, it jumps to the content).  I’ve done countless tutorials, and none seem to work on my presentation.  I even tried downloading a trial version of CS4 so I could export every one of the file’s library movie clips and images so that they load on Frame 2 (a feature MX doesn’t have).  It takes about 20 seconds for the .exe to load from a CD, and no matter which preloader construction I use, it always seems to appear in the last few seconds before the movie loads completely.  During the initial wait time, there’s no indication that anything is happening:  no hourglass on the mouse, and not even a blank screen. This is only true for the first time that the file is loaded from the CD; on subsequent loads, the file must already be in RAM, because it loads within a few seconds. 
    I decided that I’m going to try and make the file which the user clicks on (one named Windows_Portfolio.exe or another called Mac_Portfolio.hqx) the preloader so that it would be tiny, and would load instantly.  I want that file to launch the external huge portfolio file (renamed files.swf), keep track of its loading progress, and cycle through a slideshow (10 thumbnail images that transition into each other over 100 frames) proportionally, based upon the percentage of files.swf that had been loaded.
    I assume that there should be a loadMovie() or a loadMovieNum() command on the preloader’s timeline to launch files.swf, and that the initial code of files.swf should have some sort of this._parent._visible=false or other way of deleting the preloader on level0.  Can anyone explain the steps to me, or direct me to a good Flash MX tutorial that explains how to launch another external swf from a preloader .exe, keep track of its load progress, and delete the preloader .exe once the external swf had been loaded?
    Also, I’ve read that, using this construction on a CD, every file has to be in the same place, and that I can’t nest files.swf in a folder named “files,” and reference it with files/files.swf.  Is this true?
    Thanks for any assistance you can offer.

    If you know JavaScript (ECMA Script) then you might be able to get it done applying a for loop and a random function
    to the for loop if you know how to get a page-loaded request into JavaScript.
    But an easier solution, if you know ActionScript 3.0, and if your SWF's don't need to be recoded and can load into a "container" SWF would be to create a master FLA file that loads your SWF's in a random fashion using Math.random() as a multiplier, though you won't see much variation if you only have 2-3 SWF's to load--if you had more than that then you would begin to benefit from the random function's capabilities.  In ActionScript 3.0 use the load() method along with addChild() to load the SWF and add it to the stage.  You will be able to search for specifics on how to code the FLA properly by using Flash's Adobe Help tool and also using an internet search.
    -markerline
    P.S. Once you have the master FLA coded you can Publish it to an SWF and an HTML and if the container/master SWF needs to be in a page with other content you can simply copy and paste the object and embed tags for the container SWF from the published HTML into any place on your master HTML that you need it to reside.  You can then use CSS to control placement of the SWF object if it is in a div tag.

  • Both main movie and external swf preloader - confusion!

    Hi there!
    I have a webite with my main movie (88kb) and an external swf
    soundloop (1mb). I made a preloader, but it only loaded the main
    movie, meaning that after the intro, the soundloop would not start.
    I loaded the soundloop onto level 1, and then tried to make a
    preloader with this code (I thoguht it worked but it really was a
    total guess).
    stop();
    this.onEnterFrame = function() {
    bl = _level1.getBytesLoaded()+this.getBytesLoaded();
    bt = _level1.getBytesTotal()+this.getBytesTotal();
    if (bt<=0) {
    bt = 99;
    bar.gotoAndStop(Math.floor((bl/bt)*100));
    if ((bl == bt) && (bt>0)) {
    delete this.onEnterFrame;
    gotoAndPlay("Intro", 1);
    Now when I test the movie, everything loads, but when the
    soundloop is loaded after the intro, the preloader movie clip
    appears and starts playing and repeating itself!
    How on earth do I get rid of this?! You can see the problem
    here:-
    http://www.vanitee.co.uk/princess.swf
    Thanks in advance

    Please! Still in great need of help. Have tried all sorts
    =(

  • Preloader in external swf not working

    I have several external SWFs that are loaded into my site and
    each one has a preloader. When I run them by themselves the
    preloader works fine, but when it is embeded into the main SWF the
    preloaders do not work. Any ideas?
    here is my actionscript -
    lBytes = _root.getBytesLoaded();
    tBytes = _root.getBytesTotal();
    percentLoaded = Math.floor((lBytes/tBytes)*100);
    loader.bar._xscale = percentLoaded;
    loader.percent.text = percentLoaded + "% of " +
    Math.floor(tBytes/1024) + "K loaded.";
    if (lBytes>=tBytes && tBytes>0) {
    if (count>=12) {
    gotoAndPlay("enter");
    } else {
    count++;
    gotoAndPlay("preload");
    } else {
    gotoAndPlay("preload");
    }

    I am experiencing the exact same problem on my site -
    www.expansiondesign.com
    It works in flash player but not when live (tested safari and
    firefox)
    I don't know if you are using the same script as I am paul.
    I execute the following when each image button is pressed:
    button1.onRelease = function () {
    startLoading("image1.jpg");
    which runs this:
    function startLoading(whichImage) {
    loadMovie(whichImage, "_root.image_holder");
    _root.onEnterFrame = function() {
    infoLoaded = _root.image_holder.getBytesLoaded();
    infoTotal = _root.image_holder.getBytesTotal();
    percentage = (infoLoaded/infoTotal*100);
    _root.loader._yscale = percentage;
    _root.loader._visible = true;
    if (percentage>=100) {
    delete this.onEnterFrame;
    _root.loader._visible = false;
    Thanks,
    Barton

  • Preload extern swf results in weid behavior. It this normal?

    Hello,
    I tried to load an external swf file. In this swf file i have an embeded movie so that i see the preloader in action.
    What happens is, that while preloading i hear the movie playing in the background.
    So when the external swf is at for example 20% preloading the timeline is already playing in the external swf.
    Isn't that weird?
    I also noticed that the Event.INIT get's executed sooner for example at 17%  progress.  This should be at 100% is it not?
    And in CS3 i get the error while previewing the bandwidth profiler:
    Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed.
    Does anyone know what is going wrong?
    Regards,
    Chris
    This is the code i use:
    package {
    import flash.display.LineScaleMode;
    import flash.display.DisplayObject;
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;
    * @author chris
    public class PreloadMain extends MovieClip {
    private var _loaderSprite:Sprite;
    private var _request : URLRequest;
    private var _loader : Loader;
    private var _myMovie:Sprite;
    public function PreloadMain() {
    addEventListener(Event.ADDED_TO_STAGE, init);
    private function init(event:Event):void {
    _request = new URLRequest("../swf/main.swf");
    _loader = new Loader();
    _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress, false, 0, true);
    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingComplete, false, 0, true);
    _loader.contentLoaderInfo.addEventListener(Event.INIT, loadInit)
    _loader.load(_request);
    drawLoader();
    private function drawLoader():void {
    trace("draw");
    _loaderSprite = new Sprite();
    _loaderSprite.graphics.lineStyle(1, 0x000000,1,false, LineScaleMode.NORMAL );
    _loaderSprite.graphics.beginFill(0x0000FF, 1);
    _loaderSprite.graphics.drawRect(0, 0, 150, 20);
    _loaderSprite.graphics.endFill();
    _loaderSprite.x = stage.stageWidth/2 -_loaderSprite.width/2 ;
    _loaderSprite.y = stage.stageHeight/2 - _loaderSprite.height/2;
    addChild(_loaderSprite);
    function loadProgress(event:ProgressEvent):void
        var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;
        percentLoaded = Math.round(percentLoaded * 100);
      _loaderSprite.scaleX = percentLoaded/100;
       trace("loaded " +String(uint(percentLoaded)) + "%" );
        //this.percentLoaded.text = String(uint(percentLoaded)) + "%";
    function loadingComplete(event:Event):void
      removeChild(_loaderSprite);
      _myMovie = Sprite(_loader.content);
      addChild(_myMovie);
    _loader.contentLoaderInfo.removeEventListener( ProgressEvent.PROGRESS, loadProgress);
    _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadingComplete);
    _loader = null;
       trace("Load Complete");
    function loadInit(event:Event):void {
    trace("load Init");

    It is normal to receive Event.INIT before Event.Complete because on Init event you may access as3 on loaded swf, but the symbols of library may still downloading.

  • External swf. preloader blues

    Hiya,
    I've just finished a website which is nearly ready to go
    live, all except the preloader. I need to have external swfs
    preload before running, and after going through a few tutorials and
    threads, I'm pretty sure that my website is constructed in such a
    way as to make it difficult to impliment the tutorials into my
    work.
    I've attached 2 fla. files (the main parent and one of the
    external files. ), and would be really greatful if someone could
    take a look at them and let me know how I could create a preloader
    for the exteranl files (in the attachement's case the
    "visual.fla").
    Thanks a million for your time.
    ...Probably obvious, but the visual.swf is launched when the
    "visual" button is pressed on the main home.swf.
    Cheers!
    http://www.yousendit.com/transfer.php?action=download&ufid=B95706E71E2DB94E&rcpt=goodwalla [email protected]

    did you manage to do this?
    If yes, then please let me know how you did it, cause I also
    want this
    10x

  • Preload External swf files

    I am trying to create a website that has a main swf file that
    loads several external swf files into itself.
    I would like the preloader not only to preload all of the
    "main" content, but also the content that exists inside the
    external swf files before proceeding to the main user interface.
    Any help that you could give, addresses to a tutorial would
    be much appreciated.
    Thanks in advance.

    You could load each movie using movieClip.loadClip(); and
    check it has been loaded by using a listener and the
    "myListener.onLoadInit" script to write your own function to begin
    the playhead for that movie.

  • Preload external swf's

    Hi,
    Every time I have asked this question, people say , just go
    online you'll find lots of preloaders out there. Or, its documented
    really well in flash help. BUt I still dont get it. Im sure that
    anyone who knows actionscript moderately well can figure it out no
    prob.
    All I want to do is preload 3 external swf's into my main
    movie - and I want to include the preloading script in the
    preloading script I already have for my main movie. This is the
    script Im using (it has a loader bar etc,..).
    onClipEvent (load) {
    if (_parent.getBytesTotal() == _parent.getBytesLoaded()) {
    quickPlay = true;
    } else {
    preLoad = (_parent.getBytesTotal() * 0.75); //percent to
    preload
    _parent.stop();
    onClipEvent (enterFrame) {
    gotoAndStop(loadedIndicatorFrame());
    if (quickPlay == true) { //quickly play the anim
    if (_currentframe == _totalframes) {
    _parent.play();
    } else { //wait for the preload
    if (_parent.getBytesLoaded() >= preLoad) {
    _parent.play();
    Can someone help me out here?
    Also, if I preload it right at the beginning, do I need to
    additionally specify the place (empty mc) that I want to eventually
    run it in?
    Thanks a million for anyone who can help with this. Please
    dont tell me its well document\ed, because although it may, Its
    just as hard to figure it out with the documentation, Im not great
    at action script.

    I'm having a similar issue!
    I am currently building a web gallery that loads external
    .swfs (of each gallery) into movie clip containers within seperate
    frames.
    Is there any way to preload those .swfs in the background
    before they are called upon by going to those frames?
    An example of a site I built in this manner can be found
    here:
    http://gillestoucas.com/
    Help! Thanks a bunch!

  • Preloader ignores external swf's actionscript

    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;

    Hi kglad,
    The external swf is a movieclip (flv embedded with an AS3 layer to control the timeline) exported as an swf file .
    The first frame of the external swf is just stop();
    I didn't know the proloader code was AS2 though
    The preloader works fine with the external swf locally, but the problem happens when I run them from my server.
    The external swf itself and its code works fine from the server, both combined don't, so I guess the problem comes from the preloader. Probably because of the AS being 2 insted of 3.

  • FAQ: How do I load an external SWF file into a parent SWF file?

    A ton of Flash users visit Adobe’s we site every month wondering  about how to load an external SWF file from within another SWF.
    Adobe's own TechNote on the subject attempts to answer the basic question, along with some common follow-up questions, including:
    How do I load more than one SWF?
    How do I load a SWF into a specific location in the display list?
    How do I resize the loaded SWF?
    How do I set its X and Y location?
    Here are some additional resources that elaborate on loading content and on working with the display list:
    Sample files for the above TechNote. A set of 3 FLA and 3 corresponding SWF files, including a parent SWF and 2 SWFs that the parent loads.
    Help > AS3 Developer’s Guide > Loading an external SWF file
    Help > AS3 Developer’s Guide > Loading display content dynamically
    Loading multiple external SWFs within a main SWF – CreativeCow.net forums
    Video tutorial: ActionScript 101 – Episode 6: Adding named objects to the Stage. By Doug Winnie. An example of how to add the loaded external asset to the Stage and modify its location or other properties.
    Video tutorial: Preloading in ActionScript 3.0.  By Lee Brimelow. A slightly more complicated example, showing how to  make the parent SWF display information about the progress of loading  the external SWF.
    Tutorial: Loading and unloading SWFs - FlashAndMath.com
    This article provides several examples of how to communicate between a parent SWF file and the loaded SWF:
    SWF to SWF Communcation via ActionScript 3.0 (by kglad)

    quote:
    Originally posted by:
    NedWebs
    You now seem to want to get rid of the swf once it has loaded
    and played itself thru. To do that you would need to have something
    in the swf itself that triggers its removal in its last frame. The
    following might work...
    MovieClip(this.parent).removeChild(this);
    Unfortunately I couldn't get this to work. I placed it on the
    last frame of the SWF to be called - is that right?
    I am not sure I am doing it correctly...

Maybe you are looking for