A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: AS 2.0 - Whats your preloading strategy? Mine isint working.

  1. #1
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    AS 2.0 - Whats your preloading strategy? Mine isint working.

    Hi all,
    I was wondering how people are targeting the flash 6 player with AS 2.0 in regard to a preloading class.
    I tried implementing a loader class written by Ralf Bolkenburg into my own classes. I get an error message saying that my line of code that is instantiating the loader object is not permitted within my class. The below class has more features than i need, I would love to have a "barebones" version of this class
    http://www.bryanledford.com/download/LoaderClass2.0.zip

    I've been swimming through many posts on preloading. Does anyone have a simple, elegant AS 2.0 preloader class they want to share? I guess my main problem is that I cant seem to set onData or onEnterFrame event from an external class(object) to a MovieClip created from that class(object) in my main movie(.fla)

    I would just use the MovieClipLoader class, but I dont want to force my users to upgrade to flash player 7

    Basically I have my own image class, I want to import a preloader class into it so that I can set my container MC(created by createEmptyMovieClip) width and height to the size of the jpg(or swf) once it has loaded.
    I instantiate my custom image object like so:
    Code:
    var image1 : ASImage = new ASImage("test.jpg",_root.createEmptyMovieClip("image",11),10);
    ~dev

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I saw your post a couple of days ago and made a preloader which uses a .as file. I also made a loader for swfs with high MBs exported in frame1. I will send you the script and the loader tonight if you are still interested. I guess that was what you are looking for.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    Awesome!

    That would be just beautiful.

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Here is my script. Not as fancy as the one you showed but it works. You have to open each fla and make swf. I did not get any error with your file by the way.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    very sweet.

    nice work.
    you da man cancer!
    I would like to try eliminate the need for an external preloader movie, and just create a loader bar with the drawing API, the displays with createEmptyTextField(, and the container mc with createEmptyMovieClip(); and then position them all the preloading items dynamically.
    Wouldn't it be nice to setup a preloader with one line of code and no symbols in the library or anything on the stage?
    ~Dev

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I can try, you can try, somebody else seeing this thread might try

    I am located in Davis.
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    collaborate

    I'm making the LoaderBar class, today. I'll post it whn I'm done. Maybe we can combine our coding efforts?
    ~Dev

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Sounds good. I started to work on it and will continue tomorrow morning. We'll see.
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Ok, it's done, a simple AS2 preloader which does not require any on stage objects. Everything virtually created. Just create a text file, copy the whole script and save the file as: FlashscriptLoader.as. For the movie follow the instructions in the script.

    PHP Code:
    /*
    This is the script for a simple virtual preloader.                                     
    Parameters:                                                                              
    xDistance: x position of loaderbar                                                    
    yDistance: y position of loaderbar                                                      
    barHeight: height of the loaderbar                                                                              
    barColor: hexadecimal color value for the loaderbar fill                                 
    frameName: name of the frame to go when movie is loaded                                  
                                                                                    
    Example (put this script in the first frame of your movie):                              
                                                                                             
    stop();                                                                                  
    var myLoader:FlashscriptLoader = new FlashscriptLoader(200,200,25,0xfff000,"frame2");   
                                                                                         
    copyright: Joachim Schnier 2003                                                          
    */

    //class definition
    class FlashscriptLoader {
        var 
    xDistance:Number;
        var 
    yDistance:Number;
        var 
    barHeight:Number;
        var 
    barColor:Color;
        var 
    frameName:String;
        var 
    movieLoader:String;
        var 
    outLine:String;
        var 
    perLoaded:Number;
        var 
    loadedBytes:Number;
        var 
    totalBytes:Number;
        var 
    bytes:Number;
        var 
    frame:Number;
        var 
    bytesField:String;
        var 
    frameField:String;
        var 
    totalField:String;
        
        
    //constructor
        
    function FlashscriptLoader xDistance,yDistance,barHeight,barColor,frameName ) {            
            
    loadTheMovie xDistance,yDistance,barHeight,barColor,frameName );        
        }
        
        private function 
    loadTheMovie xDist,yDist,bHeight,bColor,fName ):Void {
        
            
    //passing the parameter variables
            
    xDistance xDist;
            
    yDistance yDist;
            
    barHeight bHeight;
            
    barColor bColor;
            
    frameName fName;
            
            
    //creating empty movieclips for loaderbar        
            
    _root.createEmptyMovieClip("outLine",1);
            
    _root.createEmptyMovieClip("movieLoader",2);    
            
            
    //creating the outline for loaderbar
            
    _root.outLine.lineStyle(10x000000xDist);
            
    _root.outLine.moveTo(xDist-1,yDist-1);
            
    _root.outLine.lineTo(xDist+102,yDist-1);
            
    _root.outLine.lineTo(xDist+102,yDist+bHeight+2);
            
    _root.outLine.lineTo(xDist-1,yDist+bHeight+2);
            
    _root.outLine.lineTo(xDist-1,yDist-1);
            
            
    //creating textfields
            
    _root.createTextField("bytesField",3,xDist-70,yDist+bHeight+20,100,15);    
            
    _root.createTextField("frameField",4,xDist+90,yDist+bHeight+20,100,15);
            
    _root.createTextField("totalField",5,xDist+20,yDist+bHeight+50,100,15);    
            
            
    //loading function
            
    _root.onEnterFrame = function() {
                
    //getting total bytes
                
    totalBytes _root.getBytesTotal();
                
                
    //loded bytes defining            
                
    loadedBytes _root.getBytesLoaded();
                
                
    //bytes loaded
                
    bytes Math.ceil((loadedBytes/1024)*1000); 
                
                
    //% loaded
                
    perLoaded Math.ceil((loadedBytes/totalBytes) * 100);
                
                
    //defining the loading status for loaderbar                
                
    frame Math.ceil(loadedBytes/(totalBytes/100)+xDist); 
                
                
    //creating the fill for loaderbar
                
    _root.movieLoader.lineStyle(1bColorxDist);
                
    _root.movieLoader.beginFill(bColor,xDist);
                
    _root.movieLoader.moveTo(xDist,yDist);
                
    _root.movieLoader.lineTo(frame,yDist);
                
    _root.movieLoader.lineTo(frame,yDist+bHeight);
                
    _root.movieLoader.lineTo(xDist,yDist+bHeight);
                
    _root.movieLoader.lineTo(xDist,yDist);
                
                
    //showing the bytes and % loaded in textfield
                
    _root.totalField.text "total bytes: "+totalBytes;    
                
    _root.bytesField.text "bytes loaded: "+bytes;
                
    _root.frameField.text "% loaded: "+perLoaded;
                
                
    //after loading remove all objects and go to indicated frame                
                
    if (loadedBytes >= totalBytes) {
                    
    removeMovieClip(_root.movieLoader);
                    
    removeMovieClip(_root.outLine);
                    
    removeMovieClip(_root.bytesField);
                    
    removeMovieClip(_root.frameField);
                    
    removeMovieClip(_root.totalField);
                     
    _root.gotoAndPlay(fName);
                     
    delete _root.onEnterFrame;
                }
            }
        }

    Last edited by cancerinform; 11-09-2003 at 12:58 PM.
    - The right of the People to create Flash movies shall not be infringed. -

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