A Flash Developer Resource Site

Results 1 to 20 of 189

Thread: For everyone with a preloader problem

Hybrid View

  1. #1
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    What version of Flash are you using?
    If above MX... ActionScript is case sensitive.

    a couple things to mention:

    1.) onClpiEvent(enterFrame)() is not a good way of coding.. you should NOT put code ON or IN movieClips on the stage. You 'should' put your code in FRAMES in the MAIN timeline.

    so:
    onClipEvent (enterFrame)():
    should be more like:
    someClip.onEnterFrame = function(){};

    2.) all mentions/reference of _root should be converted to relative paths/scope (ie: this, this._parent, _parent...etc)


    3.) case sensitive.... this where I believe YOUR problem lies..


    math.round should be Math.round()..

    Code:
    onClipEvent (enterFrame) {
    	tb = Math.round(_root.container.getBytesTotal()/1024);
    	lb = Math.round(_root.container.getBytesLoaded()/1024);
    	if (tb>0 && lb>0) {
    		this.percent = Math.round((lb/tb)*100);
    		this.gotoAndPlay(this.percent);
    		if (lb>=tb) {
    			_root.transition.gotoAndPlay("out");
    			_root.preloader.gotoAndStop("stop");
    		}
    	}
    }

    4.) I suggest looking into using the MovieClipLoader() class.. it it is VERY (very) useful for triggering actions when content is loaded as well as providing data for any preloder.


    update:

    here is a quick example of how to use the MovieClipLoader() class..


    simplified version:
    PHP Code:

    // create our MovieClipLoader instance (called: contentLoader)
    var contentLoader:MovieClipLoader = new MovieClipLoader();

    //create an object to handle the data available form the MovieClipLoader() object.
    var contentListener:Object = new Object();

    // create function that fires/executes when the content starts loading
    contentListener.onLoadStart = function(target_mc:MovieClip):Void {
        
    trace(">> contentListener.onLoadStart()");
    }
    // create function that fires/executes each time a byte/potion is loaded (preloader)
    contentListener.onLoadProgress = function(target_mc:MovieClipbytesLoaded:NumberbytesTotal:Number):Void {
        
    trace(">> contentListener.onLoadProgress()");
    }
    // create function that fires/executes when the content is complete
    contentListener.onLoadComplete = function(target_mc:MovieCliphttpStatus:Number):Void  {
        
    trace(">> contentListener.onLoadComplete()");
    };
    // create function that fires/executes when the content has initialized and is ready for manipulation
    contentListener.onLoadInit = function(target_mc:MovieClip):Void  {
        
    trace(">> contentListener.onLoadInit()");
    };


    // add our 'listener' object to our MovieClipLoader instance
    contentLoader.addListener(contentListener);


    // create an empty movieClip on the stage to hold our content...(this can be any target you want though)
    var containerClip:MovieClip this.createEmptyMovieClip("containerClip"this.getNextHighestDepth());

    // finally, make the call to load whatever content we want.. this is just an on-line image (but can be whatever, .swf, .jpg, clips in library..etc)
    contentLoader.loadClip("someIMage.jpgg"containerClip); 



    PHP Code:
    //create an object to handle the data available form the MovieClipLoader() object.
    var contentListener:Object = new Object();
    // create function that fires/executes when the content is complete
    contentListener.onLoadProgress = function(target_mc:MovieClipbytesLoaded:NumberbytesTotal:Number):Void {
        
    trace(target_mc._name ".onLoadProgress with " bytesLoaded " bytes of " bytesTotal);
        
    trace(">> Invoked every time the loading content is written to the hard disk during the loading process (that is, between MovieClipLoader.onLoadStart and MovieClipLoader.onLoadComplete).");
    }
    // create function that fires/executes when the content is complete
    contentListener.onLoadComplete = function(target_mc:MovieCliphttpStatus:Number):Void  {
        
    trace(">> contentListener.onLoadComplete()");
        
    trace(">> =============================");
        
    trace(">> "+target_mc._name+"._width: " target_mc._width);
        
    trace(">>> {its 0 because the content hasnt (although complete) hasnt initiliazed and Flash can not access any properties.}");
        
    trace(newline);
    };
    // create function that fires/executes when the content has initialized and is ready for manipulation
    contentListener.onLoadInit = function(target_mc:MovieClip):Void  {
        
    trace(">> contentListener.onLoadInit()");
        
    trace(">> =============================");
        
    trace(">> "+target_mc._name+"._width: " target_mc._width);
        
    trace(">>> {its 315 because once the content/clip has initialized, Flash can not access its properties.}");
        
    trace(newline);
        
    // Draw outline around the loaded content
        
    target_mc._x Stage.width/2-target_mc._width/2;
        
    target_mc._y Stage.height/2-target_mc._width/2;
        var 
    w:Number target_mc._width;
        var 
    h:Number target_mc._height;
        
    target_mc.lineStyle(40x000000);
        
    target_mc.moveTo(00);
        
    target_mc.lineTo(w0);
        
    target_mc.lineTo(wh);
        
    target_mc.lineTo(0h);
        
    target_mc.lineTo(00);
        
    target_mc._rotation 0;
    };

    // create our MovieClipLoader instance (called: contentLoader)
    var contentLoader:MovieClipLoader = new MovieClipLoader();
    // add our 'listener' object to our MovieClipLoader instance
    contentLoader.addListener(contentListener);
    // create an empty movieClip on the stage to hold our content...(this can be any target you want though)
    var containerClip:MovieClip this.createEmptyMovieClip("containerClip"this.getNextHighestDepth());
    // finally, make the call to load whatever content we want.. this is just an on-line image (but can be whatever, .swf, .jpg, clips in library..etc)
    contentLoader.loadClip("http://www.w3.org/Icons/w3c_main.png"containerClip); 

  2. #2
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263
    thanks - some interesting bed time reading...

    edit: it's flash 8 i'm using.

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263
    actually - that's worked a treat! it was the case sensitive thing you mentioned- thanks whispers...

    also i'll be adding the php code to my list of things to take a heavy interest in - it looks a little out of my depth at the moment (although a lot of things did before i started using this site )

  4. #4
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    Quote Originally Posted by inquizard
    actually - that's worked a treat! it was the case sensitive thing you mentioned- thanks whispers...

    also i'll be adding the php code to my list of things to take a heavy interest in - it looks a little out of my depth at the moment (although a lot of things did before i started using this site )
    hi there is NO PHP, I just wrapped the code in some PHP tags on the forum so the action script is color coded and easier to read..

    its ALL actionscript..

    just take the code open a new .fla and paste that in there.. and tst nothign else needs to be done.

  5. #5
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263
    Quote Originally Posted by whispers
    hi there is NO PHP, ...
    that's it i'm going to bed!

    thanks again whispers for your help - i came across your posts about not putting a preloader in the loading swf. ended up changing my site today because of it and seemed to have solved a problem before i realised it for a change.

    edit: OMG i just tried your code and i now have alot more to think about... and i was so looking forward to other stuff tomorrow
    Last edited by inquizard; 09-24-2007 at 04:40 PM.

  6. #6
    Junior Member
    Join Date
    Nov 2003
    Posts
    14
    hello there,
    i have this code for my preloading, it works fine, but this one waits for the
    entire site to load, how can i modify it, for a certain certain number of frames
    to be loaded and the move on.

    PHP Code:
    loadPercent = (Math.floor(_root.getBytesLoaded()/_root.getBytesTotal()*100)+"%");

    if (
    _root.getBytesLoaded() == _root.getBytesTotal()) {    //Check for finished loading
        //If loaded, final update to fields
        
    loadPercent "100%";
        
        
    gotoAndPlay("Scene 1"1);    //Where to go once your movie is loaded

    thanks

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