A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: onEnterFrame not getting deleted in a simple preloader

Hybrid View

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

    onEnterFrame not getting deleted in a simple preloader

    This is a simple preloader document where im loading an swf file called Target.swf into a clip called ContainerMC.

    PHP Code:
    PreloaderMC.TXT=0;

    loadMovie("target.swf","ContainerMC");

    this.onEnterFrame=function(){
        
    trace("ENTERFRAME");
        
    BytesLoaded=ContainerMC.getBytesLoaded();
        
    FileSize=ContainerMC.getBytesTotal();
        
    PreloaderMC.TXT=Math.round((BytesLoaded/FileSize)*100);trace(PreloaderMC.TXT);
        if (
    PreloaderMC.TXT==100) {
            
    trace("YES");
            
    //delete this.onEnterFrame;
        
    };
    }; 
    The onEnterFrame(); checks for the amount of file loaded etc as usual and everything works prefect.

    Except for the last statement delete this.onEnterFrame; which is why ive deactivated it by commenting it.

    As long as its commented everything works ok. But the minute i uncomment it and it comes into action nothing runs properly.

    But i also need it to work there as thats the standard way to kill the onEnterFrame loop and also maybe add an extra statement to remove the PreloaderMC as otherwise theres a huge "100%" standing in the middle of the screen. But the last statement never works. It prevents the entire preloader from running. But trace shows YES and keeps on tracing YES and 100 repeatedly.

    There are only 2 clips on the root timeline on a single frame. ContainerMC and PreloaderMC (inside which there a dynamic text whose variable etc ive correctly given as the preloader text refreshes correctly with percent loaded).

    The delete this.onEnterFrame wreaks havoc.

    Can someone point me to what statement i should use or if my logic in the loop is wrong.

    Thanks

  2. #2
    Senior Member
    Join Date
    May 2009
    Posts
    213
    What happened ? This forum used to be so active and filled with helpful people who would reply immediately.

    Now things seem very slow here. One has go to bump and push and keep pushing to even get the question noticed.

    Anyway i sorted out the situation on my own by trying different variations over 2 days and found that i could exit the looping using onLoad, FWIW.

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

    You could always use movieClipLoader, like so
    PHP Code:
    MyLoader = new MovieClipLoader();
    MyListen = new Object();
    MyLoader.addListener(MyListen);

    MyLoader.onLoadStart = function(ContainerMC)
    {
        
    my.text "0%";
    };
    MyLoader.onLoadProgress = function(ContainerMC)
    {
        
    Math.round(ContainerMC.getBytesLoaded());
        
    Math.round(ContainerMC.getBytesTotal());
        
    int(100);
        
    my.text "%";
        
    trace(P);
    };
    MyLoader.onLoadComplete = function(ContainerMC)
    {
        
    my.text "Complete";
    };
    MyLoader.onLoadInit = function(ContainerMC)
    {
        
    // Now do things
    };

    MyLoader.loadClip("target.swf",ContainerMC); 
    or setInterval(), like so
    PHP Code:
    function DoLoad()
    {
        
    ContainerMC._alpha 0;
        
    Math.round(ContainerMC.getBytesLoaded());
        
    Math.round(ContainerMC.getBytesTotal());
        
    int(100);
        
    my.text "%";
        if (
    >= 100)
        {
            
    ContainerMC._alpha 100;
            
    my.text "Complete";
            
    clearInterval(DoLoader);
        }
    }
    loadMovie("target.swf"ContainerMC);
    DoLoader setInterval(DoLoad100); 

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

    Thanks for helping.

    May i just ask why it says PHP code. This is AS2 right. Yet many tag it as PHP ? Are they closely associated ?

    Regards

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

    From what I remember, the AS tags were acting funny for a while, so people used the php tags, it makes no difference other than a bit of coloration to the coding.
    I was going to test the AS tags, but they have vanished.
    I could have used any of the code entry brackets.

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