A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: One loader for all clips, not multi load

  1. #1
    Senior Member
    Join Date
    Aug 2012
    Posts
    115

    One loader for all clips, not multi load

    Helloo

    Can help please, I have
    PHP Code:
    package 
    {
        
    import flash.display.Loader;
        
    import flash.display.Sprite;
        
    import flash.display.MovieClip;

        
    import flash.events.Event;
        
    import flash.events.IOErrorEvent;
        
    import flash.events.MouseEvent;
        
    import flash.events.ProgressEvent;

        
    import flash.net.URLRequest;

        public class 
    LoadClips
        
    {
            public var 
    myLoader:Loader = new Loader();
            public var 
    getImage:URLRequest = new URLRequest();
            public var 
    loadSofar:int;
            public var 
    clipArray:Array = new Array("folder1/1.swf","folder2/1.swf");

            public function 
    LoadClips()
            {

                
    myLoader.contentLoaderInfo.addEventListener(Event.OPEN,startLoad);
                
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProg);
                
    myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadFault);
                
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadStop);

                
    Button1.buttonMode true;
                
    Button1.mouseEnabled true;
                var 
    getImage:URLRequest = new URLRequest(clipArray[0]);// need call this in same function!!
                
    Button1.addEventListener(MouseEvent.CLICK,getThisClip());

                
    Button2.buttonMode true;
                
    Button2.mouseEnabled true;
                var 
    getImage:URLRequest = new URLRequest(clipArray[1]);// need call this in same function!!
                
    Button2.addEventListener(MouseEvent.CLICK,getThisClip());

            }
            public function 
    loadFault(e:IOErrorEvent):void
            
    {
                
    trace(e);
            }
            public function 
    startLoad(e:Event)
            {
                
    trace("Start");
            }
            public function 
    loadProg(e:ProgressEvent)
            {
                
    loadSofar int(e.bytesLoaded e.bytesTotal 100);
                
    trace(loadSofar);
            }
            public function 
    loadStop(e:Event)
            {
                
    trace("Finish.");
                
    addChild(myLoader.content);
                
    myLoader.content.100;// make so not both!! want different for each
                
    myLoader.content.100;// make so not both!! want different for each
            
    }
            public function 
    getThisClip(e:MouseEvent):void
            
    {
                
    //myLoader.load(getImage);// not know how call this
                
    myLoader.load(getImage);
            };
        }

    how can i make so each button load its real clip with differnt x y on stage after???

  2. #2
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    ok, i explain better,


    two buttons on stage, 2 clips to loade.not at same time, when called code
    PHP Code:
    package 
    {
        
    import flash.display.Loader;
        
    import flash.display.Sprite;
        
    import flash.display.MovieClip;

        
    import flash.events.Event;
        
    import flash.events.IOErrorEvent;
        
    import flash.events.MouseEvent;
        
    import flash.events.ProgressEvent;

        
    import flash.net.URLRequest;

        public class 
    LoadClips extends MovieClip
        
    {
            public var 
    myLoader:Loader = new Loader();
            public var 
    getImage:URLRequest = new URLRequest();
            public var 
    loadSofar:int;
            public var 
    clipArray:Array = new Array("folder1/1.swf","folder2/1.swf");

            public function 
    LoadClips()
            {

                
    myLoader.contentLoaderInfo.addEventListener(Event.OPEN,startLoad);
                
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProg);
                
    myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadFault);
                
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadStop);

                
    Button1.buttonMode true;
                
    Button1.mouseEnabled true;
                
    Button1.addEventListener(MouseEvent.CLICK,getThisClip(event,0));

                
    Button2.buttonMode true;
                
    Button2.mouseEnabled true;
                
    Button2.addEventListener(MouseEvent.CLICK,getThisClip(event,1));

            }
            public function 
    loadFault(e:IOErrorEvent):void
            
    {
                
    trace(e);
            }
            public function 
    startLoad(e:Event)
            {
                
    trace("Start");
            }
            public function 
    loadProg(e:ProgressEvent)
            {
                
    loadSofar int(e.bytesLoaded e.bytesTotal 100);
                
    trace(loadSofar);
            }
            public function 
    loadStop(e:Event)
            {
                
    trace("Finish.");
                
    addChild(myLoader.content);
                
    myLoader.content.not same as other;
                
    myLoader.content.not same as other;
            }
            public function 
    getThisClip(e:MouseEventarg):void
            
    {
                var 
    getImage:URLRequest = new URLRequest(clipArray[arg]);
                
    myLoader.load(getImage);
            };
        }

    how i make this happen better without error plaese

  3. #3
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    ok i get somewhere now, is there better way please ???
    PHP Code:
    package 
    {
        
    import flash.display.Loader;
        
    import flash.display.Sprite;
        
    import flash.display.MovieClip;

        
    import flash.events.Event;
        
    import flash.events.IOErrorEvent;
        
    import flash.events.MouseEvent;
        
    import flash.events.ProgressEvent;

        
    import flash.net.URLRequest;

        public class 
    LoadClips extends MovieClip
        
    {
            public var 
    myLoader:Loader = new Loader();
            public var 
    getImage:URLRequest = new URLRequest();
            public var 
    loadSofar:int;
            public var 
    clipArray:Array = new Array("folder1/1.swf","folder2/2.swf");
            public var 
    arg:Number;
            public var 
    whichClip:Number;

            public function 
    LoadClips()
            {

                
    myLoader.contentLoaderInfo.addEventListener(Event.OPEN,startLoad);
                
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProg);
                
    myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadFault);
                
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadStop);

                
    Button1.buttonMode true;
                
    Button1.arg 0;
                
    Button1.mouseEnabled true;
                
    Button1.addEventListener(MouseEvent.CLICK,getThisClip);

                
    Button2.buttonMode true;
                
    Button2.arg 1;
                
    Button2.mouseEnabled true;
                
    Button2.addEventListener(MouseEvent.CLICK,getThisClip);

            }
            public function 
    loadFault(e:IOErrorEvent):void
            
    {
                
    trace(e);
            }
            public function 
    startLoad(e:Event)
            {
                
    trace("Start");
            }
            public function 
    loadProg(e:ProgressEvent)
            {
                
    loadSofar int(e.bytesLoaded e.bytesTotal 100);
                
    trace(loadSofar);
            }
            public function 
    loadStop(e:Event)
            {
                
    trace("Finish.");
                
    addChild(myLoader.content);
                
    myLoader.content.100 whichClip;
                
    myLoader.content.100 whichClip;
            }
            public function 
    getThisClip(e:MouseEvent):void
            
    {
                
    whichClip e.currentTarget.arg;
                var 
    getImage:URLRequest = new URLRequest(clipArray[e.currentTarget.arg]);
                
    myLoader.load(getImage);
            }
        }


  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    PHP Code:
    package 
    {
        
    import flash.display.Loader;
        
    import flash.display.Sprite;
        
    import flash.display.MovieClip;

        
    import flash.events.Event;
        
    import flash.events.IOErrorEvent;
        
    import flash.events.MouseEvent;
        
    import flash.events.ProgressEvent;

        
    import flash.net.URLRequest;

        public class 
    LoadClips extends MovieClip
        
    {
            public var 
    myLoader:Loader = new Loader();
            public var 
    getImage:URLRequest = new URLRequest();
            public var 
    loadSofar:int;
            public var 
    arg:Number;
        public var 
    Quantity:int 2;
            public var 
    whichClip:Number;

            public function 
    LoadClips()
            {

                
    myLoader.contentLoaderInfo.addEventListener(Event.OPEN,startLoad);
                
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProg);
                
    myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadFault);
                
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadStop);
                
                for(var 
    i:int 0<= Quantityi++)
                {
                
    this["Button"+i].buttonMode true;
                
    this["Button"+i].arg i;
                
    this["Button"+i].mouseEnabled true;
                
    this["Button"+i].addEventListener(MouseEvent.CLICK,getThisClip);
                }
            }
            public function 
    loadFault(e:IOErrorEvent):void
            
    {
                
    trace(e);
            }
            public function 
    startLoad(e:Event)
            {
                
    trace("Start");
            }
            public function 
    loadProg(e:ProgressEvent)
            {
                
    loadSofar int(e.bytesLoaded e.bytesTotal 100);
                
    trace(loadSofar);
            }
            public function 
    loadStop(e:Event)
            {
                
    trace("Finish.");
                
    addChild(myLoader.content);
                
    myLoader.content.100 whichClip;
                
    myLoader.content.100 whichClip;
            }
            public function 
    getThisClip(e:MouseEvent):void
            
    {
                
    whichClip e.currentTarget.arg 1;
                
                var 
    getImage:URLRequest = new URLRequest("folder"+int(e.currentTarget.arg)+"/"+int(e.currentTarget.arg)+".swf");
                
    myLoader.load(getImage);
            }
        }

    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    No, it no work better, splits up my array and make more hard to work with

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    What array are you talking about? I removed the array, with my version of your script, there are no need of using an array. Just change the variable Quantity to the number of buttons you will have. The magic happens here:

    PHP Code:
    for(var i:int 0<= Quantityi++)
                {
                
    this["Button"+i].buttonMode true;
                
    this["Button"+i].arg i;
                
    this["Button"+i].mouseEnabled true;
                
    this["Button"+i].addEventListener(MouseEvent.CLICK,getThisClip);
                } 
    and here:

    var getImage:URLRequest = new URLRequest("folder"+int(e.currentTarget.arg)+"/"+int(e.currentTarget.arg)+".swf");

    So you can have 100 folders named "folder1, folder2, folder 35, folder99, folder 100" and this script will trigger all of them.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You say my version is more hard to work with. I don't think so.
    My version allows you to trigger multiple movieclips instead of doing this:

    Button1.buttonMode = true;
    Button1.arg = 0;
    Button1.mouseEnabled = true;
    Button1.addEventListener(MouseEvent.CLICK,getThisC lip);

    Button2.buttonMode = true;
    Button2.arg = 0;
    Button2.mouseEnabled = true;
    Button2.addEventListener(MouseEvent.CLICK,getThisC lip);

    Button3.buttonMode = true;
    Button3.arg = 0;
    Button3.mouseEnabled = true;
    Button3.addEventListener(MouseEvent.CLICK,getThisC lip);


    Button4.buttonMode = true;
    Button4.arg = 0;
    Button4.mouseEnabled = true;
    Button4.addEventListener(MouseEvent.CLICK,getThisC lip);
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  8. #8
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    stop get mad, m,y array is not structure like example, i have folders named images, pictures and many more images inside each folder, my buttons not named Button 1,2,3,4

    "var getImage:URLRequest = new URLRequest("folder"+int(e.currentTarget.arg)+"/"+int(e.currentTarget.arg)+".swf");" not good overall

  9. #9
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I'm not mad at all. I'm just telling that using a for loop is more practical, easy and short for coding than Copy/pasting your scripts multiple times.

    And we are not fortune-tellers over here to figure out your folder structure. In the script you posted the structure was Button1, Button2, and so on, and the folders folder1/1.swf, folder2/2.swf.

    No issue at all, just add the array again, and you can make another array to hold the buttons names and loop through them with the for loops.
    I made enough here. Good luck
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  10. #10
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    You shouldn't load swfs. Just load xml, jpg, flv, etc. Whatever is in the swfs should go in your main flash.

    Here's some code that shows loading a png and referencing the png once loaded. There's also code that creates buttons and pushes them into an array.

    Code:
    public function Main() {			
    			var loader:Loader = new Loader();
    			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, bitmapLoaded);
    			loader.load(new URLRequest("monkey.png"));
    		}
    		
    private function bitmapLoaded(e:Event):void {
    			var b:Bitmap = e.target.content as Bitmap;
    			b.x = 23;
    			b.y = 57;
    			addChild(b);
    		}
    
    
    private function createButtons():void {
    	for (var i:int = 0; i < buttonList.length; i++) {
    		var basicButton:BasicButton = new BasicButton();
    		buttonsHolder.addChild(basicButton);
    		basicButton.x = 55*i;
    		basicButton.buttonNo = i;
    		basicButton.button.addEventListener(MouseEvent.MOUSE_OVER,buttonOver);
    		basicButton.button.addEventListener(MouseEvent.MOUSE_OUT,buttonOff);
    		basicButton.button.addEventListener(MouseEvent.MOUSE_DOWN,buttonPress);
    		arrayBasicButtons.push(basicButton);
    	}
    }
    Then you can reference the buttons like this: arrayBasicButtons[i]

  11. #11
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    Thanks you moot, your code give me better flexible and reference for further using.

    Angle your code was limit to the URLRequest and although the loop work ok it not work too well within class structure and packages

  12. #12
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    You mean "our code was limit to the URLRequest and although the loop work ok it not work too well within class structure and packages". Remember this was your code at first. I didn't know anything about classes, but I finally understood it in order to try to help you, and I made some modifications to it. I did't touch the URL Request thing, i focused on the fact that you were COPY/PASTING code and I pointed you in the right direction of using a for loop to trigger all your movieclips, the same way moot did. I didn't needed to get any further with this. But at least this thread gave me the opportunity of learning how the classes work good luck
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  13. #13
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    No, you code ""var getImage:URLRequest = new URLRequest("folder"+int(e.currentTarget.arg)+"/"+int(e.currentTarget.arg)+".swf");
    myLoader.load(getImage);"" make limit to url request of folder, not my orignal array of clips to be load.

    Thank have nicer day

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