Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Results 1 to 3 of 3

Thread: loading external swf, help please

  1. #1
    Junior Member Settled In scorptique is on a distinguished road
    Join Date
    Jul 2008
    Posts
    1
    Rep Power
    0

    loading external swf, help please

    amazing Flash templates
    Hello. Im new to this forum and very new to AS3. I have a problem with my preloader. My teacher gave me this chunk of code. The problem is...with every individual external swf file that loads, the preloader animation plays once. So the preloader plays like 11 times -_-" to load all the external swf files.

    I want the preloader animation to play once to load all the swf files. Then all the swf files animation can start playing at the same time. (like normal flash sites do)
    -------------------------------------------------------------------------------------------------------------------------


    var loadCount:Number = 0;
    var percentage:uint;

    var externalswfs:Array = new Array('cup2.swf', 'paper1.swf', 'pen_combine.swf',
    'paper2.swf', 'tape2.swf', 'tape1.swf', 'paper_small.swf',
    'TD.swf', 'sweets.swf', 'book.swf','blank.swf');

    //holder1, 2, 3 etc --> empty movie clips on stage with these instance names
    var holders:Array = new Array(holder1, holder2, holder3, holder4, holder5, holder6,
    holder7, holder9, holder10, holder11, holder12);

    loadswf(externalswfs[0], holders[0]);

    function loadswf(str:String, holder:MovieClip):void {
    var requestSWF:URLRequest=new URLRequest(str);
    var loader:Loader=new Loader();
    loader.load(requestSWF);

    loader.contentLoaderInfo.addEventListener(Event.OP EN,beginloading);
    function beginloading() {
    preloader_mc.gotoAndStop(1);
    preloader_mc.loader_txt.visible = true;
    }

    //Listener object to listen for the progress and
    //executes the currentProgress function with each change

    loader.contentLoaderInfo.addEventListener
    (ProgressEvent.PROGRESS,currentProgress);

    function currentProgress(e:ProgressEvent):void {
    //This variable get the percentage
    percentage = (e.bytesLoaded/e.bytesTotal)*100;
    //Place the percentage number in the text field
    preloader_mc.loader_txt.text=percentage.toString() +' %';
    //My preloader has 200+ frames
    preloader_mc.gotoAndStop(percentage/100 * 200);
    }

    //Listener object to listen to when the swf is fully loaded
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,completed);

    function completed(e:Event):void {
    preloader_mc.loader_txt.visible = false;
    //lastpart is the last section of animation for the preloader to play after the
    //loading is done
    preloader_mc.gotoAndPlay('lastpart');
    holder.addChildAt(loader.content,0);
    loadCount++;
    if (loadCount < externalswfs.length) loadswf(externalswfs[loadCount], holders
    [loadCount]);
    }
    }

    ---------------------------------------------------------------------------------------------------------------------

    I know the code is pretty complicated. Sorry. But some help please! ><!

  2. #2
    Junior Member Settled In badboykilla is on a distinguished road badboykilla's Avatar
    Join Date
    Oct 2008
    Posts
    18
    Rep Power
    0

    Re: loading external swf, help please

    ok try this. (i am not gonna explain each thing step by step :) )

    first u have main template where u coded to load all the external files right?

    1. now create a new AS3 file and save it in the same folder
    2. resize it to same as the main template.
    3. Make 5 layers. Name them as follows: >>
    actions
    loader
    preloader
    preloadercontent

    4. in the action layer paste this code:

    loader.addEventListener(ProgressEvent.PROGRESS, onProgress);
    loader.addEventListener(Event.COMPLETE, onComplete);

    function onProgress(e:ProgressEvent):void
    {
    var loaded:Number = loader.bytesLoaded;
    var total:Number = loader.bytesTotal;
    preloader_mc.scaleX = loaded / total;
    }

    function onComplete(e:Event):void
    {
    removeChild(preloader_mc);
    removeChild(outline_mc);
    }

    5. in the loader layer grab a UILoader from the > Components > User Interface
    6. drag it to stage (make sure the x and y = 0)
    7. in the properties panel name it "loader"
    8. click on the parameters in the properties panel and choose these setting:
    autoload: true
    maintainAspectRation: true
    scaleContent: false
    source: link it to the main template

    9. close that layer and Now, in the preloader layer
    make a shape. (make sure the only fill color is selected)
    (Width: 400)
    (height: 30)
    10. convert it to a moveclip. give it a Instance name "preloader"
    11. make sure the preloader is selected. In the properties panel name it "preloader_mc"

    12. Close preloader layer, now the preloadercontent layer
    13. create shape on the stage. choose any color u like (width: 407 | height: 40)
    14. convert it to a movie clip and give it a instance name "outline"
    15. select the "outline" in the properties panel give it a name "outline_mc

    16. test ur movie and everything should load together

  3. #3
    Junior Member Settled In badboykilla is on a distinguished road badboykilla's Avatar
    Join Date
    Oct 2008
    Posts
    18
    Rep Power
    0

    Re: loading external swf, help please

    Quote Originally Posted by pzhu520 View Post
    I come from china ,I am a newer and my english is bad,I hope you can help me,thank you !
    yeah i can guide u. have aim or yahoo messenger?

+ Reply to Thread

Similar Threads

  1. Loading external swf with no use of AS files
    By Flep in forum Actionscript for beginners - tutorials
    Replies: 33
    Last Post: 12-12-09, 04:16
  2. Loading mulitple external .swf files
    By mrentschler in forum Actionscript 3.0 newbies
    Replies: 1
    Last Post: 09-10-08, 22:24
  3. Problem with loading external swf
    By madmad in forum Actionscript 3.0 newbies
    Replies: 2
    Last Post: 28-05-08, 21:36
  4. Simple:Loading external SWF
    By mabron in forum Actionscript 3.0 newbies
    Replies: 1
    Last Post: 14-05-08, 23:02
  5. Simple:Loading external SWF
    By mabron in forum Flash CS3 | PHP | mySQL
    Replies: 0
    Last Post: 14-05-08, 03:18

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Optimization by vBSEO