A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: External Preloader starts at 100 !! and then goes to 1 and proceeds as normal

  1. #1
    Senior Member
    Join Date
    May 2009
    Posts
    213

    External Preloader starts at 100 !! and then goes to 1 and proceeds as normal

    Flash Pro 8 : AS2.

    Hi,

    I made a simple flash preloader.

    AS2 script given below. On the stage is a HolderMc clip to receive the incoming swf and a TextBoxMc inside which is the dynamic text is kept. The dynamic text variable box is filled with _root.VL
    PHP Code:
    stop();
    trace("------------------------");
    HolderMc._visible=0;
    //////////

    //Preloader Block.
    HolderMc.loadMovie("Imagery.swf",0);

    this.onEnterFrame=function(){
    MyLoaded=Math.round(HolderMc.getBytesLoaded());
    MyTotal=Math.round(HolderMc.getBytesTotal());
    MyPercent=(MyLoaded/MyTotal);
    VL=Math.round(MyPercent*100)+"%";  trace(VL);
    if (
    VL==99){
        
    delete this.onEnterFrame;
        
    trace("OEF DELETED");
        
    _root.TextBoxMc._visible=0;
        };
    }; 
    Never works correctly because of the simple fact that its always starting at 100% for a few frames as can be noted from the trace results. Because of this the onEnterFrame isnt getting killed. And the 100% stays on the screen.

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Use movieClipLoader instead, it is more accurate and have more control over other things, try like this
    PHP Code:
    stop();
    trace("------------------------");
    HolderMc._visible 0;

    ImageLoad = new MovieClipLoader();
    ImageLoader = new Object();
    ImageLoad.addListener(ImageLoader);

    ImageLoader.onLoadStart = function(Target)
    {
        
    HolderMc._visible 0;
    };
    ImageLoader.onLoadProgress = function(TargetLoadBytesTotalBytes)
    {
        
    VL Math.floor((LoadBytes TotalBytes) * 100);
        
    trace(VL "% - " LoadBytes " / " TotalBytes);
        
    myText.text VL "%";
    };
    ImageLoader.onLoadComplete = function(Target)
    {
        
    HolderMc._visible 1;
        
    trace("Loaded");
    };
    ImageLoader.onLoadInit = function(Target)
    {
        
    HolderMc._visible 1;
        
    _root.TextBoxMc._visible 0;
        
    myText.text "";
    };

    ImageLoad.loadClip("Imagery.swf","HolderMc"); 
    Last edited by fruitbeard; 08-06-2013 at 12:49 PM.

  3. #3
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi Fruitbeard,

    Thanks a lot for being so helpful.
    Is that AS2 ?

    Seems quite complicated .

    Regards

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Yes it's AS2 and it's quite straight forward when you take a closer look.
    PHP Code:
    stop();
    trace("------------------------");
    HolderMc._visible 0;
    // *** declare new movie clip loader and object listener
    ImageLoad = new MovieClipLoader();
    ImageLoader = new Object();
    ImageLoad.addListener(ImageLoader);
    // *** start the loading when called
    ImageLoader.onLoadStart = function(Target)
    {
        
    HolderMc._visible 0;
    };
    // *** during loading after called
    ImageLoader.onLoadProgress = function(TargetLoadBytesTotalBytes)
    {
        
    VL Math.floor((LoadBytes TotalBytes) * 100);
        
    trace(VL "% - " LoadBytes " / " TotalBytes);
        
    myText.text VL "%";
    };
    // *** loading has now finished
    ImageLoader.onLoadComplete = function(Target)
    {
        
    HolderMc._visible 1;
        
    trace("Loaded");
    };
    // *** now instigate everything
    ImageLoader.onLoadInit = function(Target)
    {
        
    HolderMc._visible 1;
        
    _root.TextBoxMc._visible 0;
        
    myText.text "";
    };
    // *** initiate the loader/ call the loader
    ImageLoad.loadClip("Imagery.swf","HolderMc"); 
    Last edited by fruitbeard; 08-06-2013 at 02:50 PM.

  5. #5
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    What should be inplace of the word function (in green) and what should i give instead of the keyword target ?

    My swf which is being loaded is Landing.swf its a flash webpage and its on the same folder as the .fla and its respective .swf.

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You can call (Target) whatever you desire as long as they are all the same. such as theClip, theMovie, MyLoad it plays no relevance to any name of your clips.

    you could be more accurate with the code though, with details such as
    PHP Code:
    ImageLoader.onLoadStart = function(Target:MovieClip)
    ImageLoader.onLoadProgress = function(Target:MovieClipLoadBytes:NumberTotalBytes:Number
    you can even remove them all and it still worlks with some less function, such as getting bytes total/loaded.

    You best leave function as it is!

    just swap Imagery.swf for Landing.swf, path structure applies like any normal web page.

    for further advice/reading adobe:http://help.adobe.com/en_US/AS2LCR/F...=00001386.html
    Last edited by fruitbeard; 08-07-2013 at 01:58 AM.

  7. #7
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    Thanks a ton. I will try this code and let you know how things fare.

    Regards

  8. #8
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    I tried your code and it works very nicely thank you. But now im puzzled how to use it to load on levels. I tried loadClip._level1 instead of HolderMc and it works and loads on the correct level but its not able to sense the data flow etc. Should i specify _level0 and then the listener name for all the statements ?

  9. #9
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Just use ImageLoad.loadClip("Imagery.swf",2); or whichever level you wish ImageLoad.loadClip("Imagery.swf",1); / ImageLoad.loadClip("Imagery.swf",3);

  10. #10
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    But then the preloader stops working, how do i get it to load on a different level where there is no HolderMc ?
    If i specify a level its loading correctly on the level but the preloader stops sensing the byte values.
    Sorry for being so naive.

    Actually this is for a website. So now i have the preloader with your code on the index page. When the index page loads it has your code with the preloader clip on the main timeline within a single frame. The end of the code block calls for the landing.swf page. When that page loads in. I want to have an enter button on that page which when clicked shows the preloader again and shows the correct percent as its working now on the index page.

    Do i have to paste the same preloader clip and the code into all the pages ?
    Last edited by plainman007; 08-09-2013 at 11:26 AM.

  11. #11
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Post the whole code you are using to load it into another level

  12. #12
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi There,

    Very little code indeed. I hope you dont mind i slimlined your code block a little and this works perfectly for me. Only i just need to learn how to once the page has loaded on level1 now the preloader is below that. How do i design this in such a way that i can make one preloader to come into play for every page that i load ? Is there a way i can have this preloader to start with on level 3 so that all pages load below it and i can have it visible=0 when its completed and visible=1 when its called into play. Even that i can work out i think but i dont know how i can have the preloader work with all levels and different pages. Because ive defined only one MovieClipLoader called PageLoader. But when i use PageLoader.loadClip on different levels it doesnt work. I think its something to do with the target path or that the variable VL isnt accessible on the other level etc ?

    My toned down version of your script....

    PHP Code:
    /////////Preloader Script.
    ///
    PageLoader = new MovieClipLoader();
    PLListener = new Object();
    PageLoader.addListener(PLListener);
    ///
    PLListener.onLoadProgress = function(TargetLoadBytesTotalBytes){
        
    VL Math.floor((LoadBytes TotalBytes) * 100);
        };
    ///
    PLListener.onLoadComplete = function(Target){
        
    PreloaderMc._visible=0;
        };
    ///
    PageLoader.loadClip("Landing.swf",1); 

  13. #13
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Ok,

    So you want to be able to reuse the moviecliploader.
    one way i do it is like so.

    instead of putting
    PHP Code:
    PageLoader.loadClip("Landing.swf",1); 
    do it like this maybe
    PHP Code:
    function LoadMovieExtra()
    {
        
    PageLoader.loadClip(TheName,TheArea);
    }
    TheName "Landing.swf";// swf name
    TheArea "_level1";// use clipname or a level
    LoadMovieExtra(); 
    making sure you declare TheName and TheArea when calling the loader

    or like so
    PHP Code:
    function LoadMovieExtra(A,B)
    {
        
    PageLoader.loadClip(A,B);
    }
    LoadMovieExtra("Landing.swf",1); 
    on my site I use a reuseable loader for everything, my hobby
    Last edited by fruitbeard; 08-09-2013 at 12:01 PM.

  14. #14
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    I saw your website. Very cute looking and yet looks complicated. You collect a lot of media ? Are you a 3d designer or something.

    Where should this code and preload animation clip be ? On the index page ? But the higher level loaded page will cover up the preloader right ?
    Or is there a way i could get the preload clip onto level 5 or something so its uppermost ?

    PS : Can i pm you my website ? Just so you can comment and give me tips and your opinon.

    Regards

  15. #15
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    OK,

    I'm with you now,

    make a simple swf file and call it "pre" for now with some text with instance name of myText (embedded), you can change it of course, but be sure to chnage each similar value if you do, and use this
    PHP Code:
    PL = new MovieClipLoader();
    PLL = new Object();
    PL.addListener(PLL);

    PLL.onLoadComplete = function(Target)
    {
        
    PageLoader.loadClip("Landing.swf"1);
    };
    PL.loadClip("pre.swf"100);

    ////
    PageLoader = new MovieClipLoader();
    PLListener = new Object();
    PageLoader.addListener(PLListener);
    ///
    PLListener.onLoadProgress = function(TargetLoadBytesTotalBytes)
    {
        
    _level100._visible true;
        
    VL Math.floor((LoadBytes TotalBytes) * 100);
        
    _level100.myText.text VL;
        
    trace(VL);
    };
    ///
    PLListener.onLoadComplete = function(Target)
    {
        
    _level100._visible false;
        
    _level100.myText.text "";
    }; 
    the pre.swf can be as elaborate as you like, as you can always set its visiblility to 0 and back again whenever called.

    and then whenever you wish to use the preloader again simply use
    PHP Code:
    PageLoader.loadClip("another.swf"18); 
    No I'm not a designer, it's all just random images from the net that I use as Im have no material myself, its more a showcase of abilities than anything else.
    Last edited by fruitbeard; 08-09-2013 at 12:27 PM.

  16. #16
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    Ive used all your earlier suggestions (Just havent tried the last version due to the fear factor ). But the good news is everything works fine by pasting the preloader clip and its script into the Home Page and then using a custom function BtnHandler to call each seperate webpage section into _level3 (since the Homepage is on _level2). Everything works fine, I created a return button, or in other words return to homepage button on the loaded page so that when its clicked the page loaded on _level3 gets flushed out revealing the homepage which is below it.

    I created the ReturnBtn on the page that loads into _level3 but wanted a single point to control returns from any page loaded above the home page. So in the homepage main timeline i gave...

    PHP Code:
    _level3.GalleryPageContent.ReturnBtn.onPress=function(){
    LoadMovieNum("NoFile.swf",3);//this just is a non existant file to flush out level3.
    }; 
    Doesnt work. .
    Is this because im loading content using MovieClipLoader ?

  17. #17
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Try
    PHP Code:
    unloadMovie(thelevel);// thelevel = your number 
    plus I don't think it would remove the old movie if it finds no movie to load, so make a blank movie if you wish to do it like you are doing, then it will flush it with the blank movie, but unloading is probably better!
    Last edited by fruitbeard; 08-13-2013 at 09:32 AM.

  18. #18
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Hi,

    I was just trying it as you were posting i guess and found the button sensing itself doesnt work.
    In other words the higher level contains a newly loaded website section and has a ReturnBtn clip in it.

    The _level2 homepage which just called the GalleryPage.swf (or whatever) has
    _level3.GalleryPageContentMc.ReturnBtn.onPress=fun ction(){our actions};

    This basic script should atleast create mouse sensing over the ReturnBtn which is in the movie on level3.
    But its not doing so. The clip doesnt get sensed if you get what i mean. Its just lays there like a normal scriptless Mc.

  19. #19
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Whats happening is the command isn't being initiallised,

    so to add to themovieClipLoader, use
    PHP Code:
    PLListener.onLoadInit = function(Target)
    {
        
    _level3.GalleryPageContentMc.ReturnBtn.onPress = function()
        {
            
    unloadMovieNum(3);
        };
    }; 
    this is usually placed underneath this part of the clipLoader
    PHP Code:
    PLListener.onLoadComplete = function(Target)
    {
        
    //;
    }; 
    the PLListener.onLoadInit actually allows you to set things up.
    PLListener.onLoadComplete just means its finished loading.

    make sure you use the PageLoader.loadClip to load your movies so it will know when its complete, simple loadMovie is not the same.

    you could even make a nice alpha tween so the movie doesn't just disappear, like so
    PHP Code:
    PLListener.onLoadInit = function(Target)
    {
        
    import mx.transitions.Tween;
        
    _level3.button.onPress = function()
        {
            var 
    alphaTween:Tween = new Tween(_level3"_alpha"mx.transitions.easing.Regular.easeOut10002true);
            
    alphaTween.onMotionFinished = function()
            {
                
    unloadMovieNum(3);
            };
        };
    }; 
    Last edited by fruitbeard; 08-13-2013 at 10:07 AM.

  20. #20
    Senior Member
    Join Date
    May 2009
    Posts
    213
    Thanks a lot. The code was correct like you pointed. The location mattered.

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