Get GSAP

Version: 1.13.1 updated 2014-07-22

Core

    Extras

      Plugins

        By using GreenSock code, you agree to the terms of use.

        Jump to content

        Codepen Notification

        You didn't provide a codepen sample that illustrates the problem. It really helps us quickly identify problems. This isn't mandatory, but it will get you better/faster results. Would you like to add one?

        How to remove all loaded swf files, except one, from Xml file?

        Started by Sakar, May 16 2012 04:42 AM xmlloader remove loaded swf files

        10 replies to this topic
        Sakar

        Post #1 by Sakar , 16 May 2012 - 04:42 AM

        Hello GreenSock!

        Congrats for your Amazing job.
        I’m really a first timer with AS3, Greensock and have no skills with programming.

        I just made a huge personal flash website and I was stacked with the LoaderMax and XMLLoader.
        Never made it work. (Need a lot of studying)

        But this tutorial helps me like a charm: (thanks to Carl)
        http://www.snorkl.tv...-the-xmlloader/


        From the XML file, I load with succeed, the Main swf plus 200 swf files.
        Main swf loaded at x:0 y:0 and
        all other swf files at x:3000 and y:3000
        Just far away from the stage. Everything load and work ok, but
        Loading 200 files on the stage makes fps to 2-5/sec

        How can I remove all loaded swf from the stage, except from the Main swf ???

        I use the same actionscript and xml from Carl's tutorial.!

        Thanks
        Sakar
        • Back to top

        Carl

          Administrator

        • Carl
        • 4,900 posts

        Post #2 by Carl , 16 May 2012 - 01:30 PM

        interesting situation.
        what you can do is loop through all the loaders from your xml and unload() all of them except main.swf.

        I altered my original tutorial files to include a button that unloads all the images except for the one with name "crab" (as specified in the xml).

        here is the code:

        unload_btn.addEventListener(MouseEvent.CLICK, unloadHandler);
        function unloadHandler(e:MouseEvent):void{
        
        var nameOfAssetToKeep:String = "crab";
        
        var assetsArray:Array = queue.getChildren();
        var numOfAssets:int = assetsArray.length;
        
        trace("numOfAssets = " + numOfAssets);
        
        for(var i:int = 0; i < numOfAssets; i++){
          if(assetsArray[i].name != nameOfAssetToKeep){
           assetsArray[i].unload();
           }
          }
        }
        

        flash cs4 fla attached (save it into the same folder as the other tutorial flas)

        Attached Files


        • Back to top

        Sakar

        Post #3 by Sakar , 16 May 2012 - 10:17 PM

        Thanks for your very fast reply Carl !

        This script works and it’s very nice.
        Your tutorial is the best way I can find for now.
        But loading a big website, I see it’s not the right way to load everything at start.

        I was start building my website before I meet Greensock LoaderMax.
        When I need to load some swf, I use URLRequest and load swf inside a Movieclip.
        200 Different URLRequests inside 200 different Mcs.

        After that I realize that the loading process loads everything on “background” is boring for visitors to wait.
        Every URLRequest loads too slow because all other URLRequests is been loaded at the same time.

        So, your way and my way, think is not the perfect choice for my website.
        What do you think?

        Is there any way to force start and complete loading the particular swf only when request?
        I don’t know what to do about it. And have no LoaderMax skills

        All I know is ,all that 200 swf files needs a better download process.
        Total size is 30MB and its too much heavy, loading all, at first page.
        I feel so bad about that.

        Hope to find a better solution.

        Thanks
        Sakar
        • Back to top

        Carl

          Administrator

        • Carl
        • 4,900 posts

        Post #4 by Carl , 17 May 2012 - 02:10 AM

        Yeah, loading 200 swfs up-front is not a great approach.
        You can load any asset based on the user's selection as long as you know the name or url of the SWFLoader.

        after your xml has loaded you can do

        LoaderMax.getLoader("someSwf").load();
        • Back to top

        Sakar

        Post #5 by Sakar , 17 May 2012 - 10:39 AM

        I didn't get that.
        What do you mean:
        "...as long as you know the name or url of the SWFLoader"

        how can I fire that from the Main swf.?
        Main.swf = the first loaded swf from xml and had all the buttons inside.

        Thanks
        Sakar
        • Back to top

        Carl

          Administrator

        • Carl
        • 4,900 posts

        Post #6 by Carl , 17 May 2012 - 02:07 PM

        the name and url of each SWFLoader is all in the xml. once the xml loads you can read all of that info and tell different buttons to be in charge of loading specific SWFLoaders.

        I don't think I really understand everything you have going in your project or how the user is supposed to interact with or navigate to all 200 swfs;(
        • Back to top

        Sakar

        Post #7 by Sakar , 17 May 2012 - 08:34 PM

        Reorient the swfs lines inside the xml and cut some unnecessary from it, is a bit better.

        Let's say we have an (almost) empty swf, used "as a loader" for xml.
        From the xml, we start loading first, the Main.swf (All buttons - and empty pages there)
        and then, loading all the others swfs to be placed inside the empty pages.

        This code didn't work inside the Main.swf

        import com.greensock.*;
        import com.greensock.loading.*;
        import com.greensock.events.LoaderEvent;
        import com.greensock.loading.display.*;
        import flash.display.Sprite;
        import flash.display.MovieClip;
        
        LoaderMax.activate([ImageLoader, SWFLoader]);
        
        tst.buttonMode = true;
        tst.addEventListener(MouseEvent.CLICK, tstClick);
        
        function tstClick(e:MouseEvent):void{
        LoaderMax.getLoader("mous").load();
        }
        

        Something is missing. (maybe the xml path)

        Before all of that, I was tried to put the code from your tutorial to the Main.swf
        but I get a lot of errors. That's why I use the empty swf as a loader for everything else.

        Now, URLRequests as I said at previous message, are still remain inside the Main.swf
        I'm afraid that I make a double load of my files.

        Thanks again.
        Sakar
        • Back to top

        Carl

          Administrator

        • Carl
        • 4,900 posts

        Post #8 by Carl , 18 May 2012 - 02:12 AM

        what do you mean by it didn't work?
        did you get errors?
        where are you defining the container that "mous" should get loaded into?

        I'm wondering if perhaps it loaded, but just isn't being placed on the stage.

        if you want to edit and package your files so that only 1 or 2 swfs needs to load from main.swf I can take a look at it.
        • Back to top

        Sakar

        Post #9 by Sakar , 18 May 2012 - 06:41 AM

        I didn't defining the container.
        I don't know how to do that.

        If it's loaded from xml file, why its not being placed on the stage.?

        By the way
        I don't have the time now to experiment more with that.

        I'll start a new post for any of my new questions

        You really help me a lot. I appreciate that :mrgreen:

        Thanks
        Sakar
        • Back to top

        Carl

          Administrator

        • Carl
        • 4,900 posts

        Post #10 by Carl , 18 May 2012 - 05:22 PM

        If it's loaded from xml file, why its not being placed on the stage.?


        just like in my tutorial sample you need to use addChild() in your completeHandler.
        when defining your SWFLoader in the actionscript you can use the container property, but that doesn't work when the SWFLoader is defined in the xml.
        • Back to top

        Sakar

        Post #11 by Sakar , 19 May 2012 - 09:16 PM

        Thanks Carl !
        I'll check that :ugeek:
        • Back to top




        0 user(s) are reading this topic

        0 members, 0 guests, 0 anonymous users