A Flash Developer Resource Site

Results 1 to 20 of 189

Thread: For everyone with a preloader problem

Threaded View

  1. #11
    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); 

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