A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] preloading multiple external swfs

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2007
    Posts
    10

    resolved [RESOLVED] preloading multiple external swfs

    Hello all,

    I was hoping someone here could help me out. I have two swf files that I exported from After Effects. They are both fairly large (1.7mb and 2.6mb) so I decided to load them into my main fla externally. This works fine but the playback is a little choppy. I tried creating a separate preloader.fla that will play my main movie once it is loaded. This doesn't work though since my main movie is only 4kb (since all the swfs are externally loaded). With me so far?

    So then I created a regular preloader inside my main fla. Here is my code:

    Code:
        stop();   
    
        import flash.display.*;
    
        var request:URLRequest = new URLRequest("snowfall.swf");
        var loaders:Loader = new Loader();
    
        loaders.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
        loaders.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
        loaders.load(request)
    
        function loadProgress(event:ProgressEvent):void
        {
            var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
            lbar.scaleX=pcent/100;
            lbc.text=int(pcent)+"%";
        }
    
        function loadComplete(event:Event):void
        {
           addChild(loaders);
           lbar.visible = false;
           lbc.visible = false;
        }
    This works perfect for my snow.swf...however I have another swf which hasn't been told to preload, so it takes about 5 seconds before it plays. I need both swfs to play at the same time. This is my code for the other swf:

    Code:
        play();
    
        var plane_sm_loader:Loader = new Loader();
        var urlRequest:URLRequest=new URLRequest("Plane_sm.swf");
        plane_sm_loader.load(urlRequest);
        plane_sm_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadDone);
    
        function loadDone(event:Event):void {
                plane_sm_loader.width = event.target.width /3;
                plane_sm_loader.height = event.target.height /3;
                plane_sm_swf.addChild(plane_sm_loader);
        }


    And here is my code for calling the snow.swf externally...just in case you need it:

    Code:
        // This is the Loader instance that will load your SWF.
        var loader:Loader = new Loader();
    
        // URLRequest points to your external SWF
        var defaultSWF:URLRequest = new URLRequest("snowfall.swf");
    
        //create the container Movie Clip to load swf
        var swf:MovieClip= new MovieClip();
    
        loader.load(defaultSWF);
    
        //just add the loaded swf to container
        swf.addChild(loader);
        //add container to the stage and make it visible
        snow.addChild(swf);

    So my question would be...how do I tell my preloader code to make sure both snow.swf and plane_sm.swf are loaded before the movie plays? I keep finding information in AS2 but not AS3. Any guidance in the right direction would be greatly appreciated!!!!

    Thank you so much in advance!

  2. #2
    Not directly helpful, but I've just started using LoaderMax, which seems to do the job a lot simpler:

    http://www.greensock.com/tweenmax/

  3. #3
    Junior Member
    Join Date
    Mar 2007
    Posts
    10
    Actually that was quite helpful. I completely forgot about Greensock and decided to use it for the majority of my animation, including the loader. Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center