# Traffic & time economy + duplicate loaders?

**URL:** <https://forum.kirupa.com/t/traffic-time-economy-duplicate-loaders/296369>\
**Category:** flash\
**Created:** [September 14, 2009, 9:46am UTC](https://forum.kirupa.com/t/traffic-time-economy-duplicate-loaders/296369 "2009-09-14T09:46:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jloa](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@jloa](https://forum.kirupa.com/u/jloa)\
**Post date:** [September 14, 2009, 9:46am UTC](https://forum.kirupa.com/t/traffic-time-economy-duplicate-loaders/296369/1 "2009-09-14T09:46:51Z")

</div>

Greets.  
I thought some of u would probably get into it. This is a rough copy of my solution to ‘traffic saving’ + duplicate content.  
The idea is pretty simple - extend the loader + after Event.COMPLETE event just record the bytes of the content to a static/singleton (as u wish) manager class. After u can freely grab those bytes from the buffer and create a nice & full copy of the object (no matter image/swf).

The manager

```auto
package
{
    import flash.utils.ByteArray;
    
    public class LoaderManager
    {
        private static var DATA:Object = {};
        
        public static function setData(id:int, data:ByteArray):void
        {
            LoaderManager.DATA[id] = data;
        }
        
        public static function getData(id:int):ByteArray
        {
            if(LoaderManager.DATA[id])
                return LoaderManager.DATA[id];
            else
                return null;
        }
    }
}

```

The ALoader

```auto
package
{
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.utils.ByteArray;
    import flash.events.Event;
    import LoaderManager;
    
    public class ALoader extends Loader
    {
        private var _useManager:Boolean;
        private var _id:int;
        
        public function ALoader(useManager:Boolean = false, id:int = -1)
        {
            this._useManager = useManager;
            this._id = id;
            super();
        }
        
        public override function load(request:URLRequest, context:LoaderContext = null):void
        {
            if(_useManager)
            {
                var bytes:ByteArray = LoaderManager.getData(_id);
                if(bytes)
                {
                    trace("Yes! Traffic & time economy. Got the content from buffer");
                    super.loadBytes(bytes);
                }else{
                    super.contentLoaderInfo.addEventListener(Event.COMPLETE, dataLoaded);
                    super.load(request, context);
                }
            }else{
                super.load(request, context);
            }
        }
        
        private function dataLoaded(event:Event):void
        {
            //the magic
            LoaderManager.setData(_id, super.contentLoaderInfo.bytes);
        }
    }
}

```

Sorry, no comments in code - it’s just a working sketch (writing from my mobile)  
Hope this helps anyone. :hugegrin:
