Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: BulkLoader Proxy?  (Read 15055 times)
Groady
Newbie
*
Posts: 6


View Profile Email
« on: June 30, 2009, 11:17:28 »

I'm just wondering if anyone has attempted to create a Proxy for BulkLoader?

I was thinking of creating one but thought I'd ask here first. Basically the proxy would allow a series of items to be loaded as a group and then fire off a notification when finished. The notification would carry the loaded assets as it's body.

Has anything like this already been created? What's everyone using for bulk loading of assets?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: June 30, 2009, 01:22:48 »

I haven't seen one for BulkLoader. If you like that utility go for it. You might also want to check out the StartupManager utility: http://forums.puremvc.org/index.php?topic=259.0

-=Cliff>
Logged
Groady
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: July 01, 2009, 06:36:50 »

I had already looked at StartupManager and to be honest I don't think it's for me.

Part of the reason I thought a BulkLoader proxy could be useful is that it is not necessarily limited to being a start up resource loader but could be called anytime while the app is running.

For example, I'm currently creating a site which has several 10x10 social media icons which get loaded into the footer. I consider these non start up critical items so these get loaded AFTER the navigation and start up content has loaded.

Also I like the idea of a single loading proxy which fires notifications into the system over something like StartupManager which requires creating several Proxy classes.

I imagine the proxy would expose methods like:

addGroupItem(groupName:String, itemPath:String, itemID:String);
loadGroup(groupName:String, completeNotification:String, progressNotification, failedNotification);

The proxy would handle the instantiation of BulkLoader instances and route it's events to the notifications in defined by the loadGroup method.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: July 01, 2009, 08:22:27 »

The StartupManager is actually a misnomer, and I think we probably need to change that for clarification. You can use it anytime, not just at startup. It's name is also conflict now with the StateMachine (since people often refer to both as 'SM').

-=Cliff>
Logged
stinkyian
Newbie
*
Posts: 4


View Profile Email
« Reply #4 on: July 02, 2009, 09:53:47 »

Hi, I needed to write a BulkLoader proxy and found this post in an attempt to not reinvent the wheel ;)

Anyway, it's written so I thought I'd post it here in case anyone's interested.


:
package tv.stinkdigital.puremvcbase.model
{
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;
import br.com.stimuli.loading.loadingtypes.LoadingItem;

import flash.events.ErrorEvent;
import flash.events.Event;

import org.puremvc.as3.interfaces.IProxy;
import org.puremvc.as3.patterns.proxy.Proxy;

import tv.stinkdigital.puremvcbase.ApplicationFacade;

public class BulkLoaderProxy extends Proxy implements IProxy
{
public static const NAME:String = "BulkLoaderProxy";

public function BulkLoaderProxy(data:Object=null)
{
super(NAME, data);
}

public function addLoader(loaderId:String):void
{
var bulkLoader:BulkLoader = new BulkLoader( loaderId );

bulkLoader.addEventListener(BulkLoader.COMPLETE, onComplete);
           
            bulkLoader.addEventListener(BulkLoader.PROGRESS, onProgress);
           
            bulkLoader.addEventListener(BulkLoader.ERROR, onError);
            bulkLoader.addEventListener(BulkLoader.SECURITY_ERROR, onError);
}

public function addItem(loaderId:String, url:String, itemId:String, type:String = null, weight:int = 0, priority:int=0, maxTries:uint=1, preventCaching:Boolean = false, checkPolicyFile:Boolean = false, headers:Array=null ):void
{
var props:Object = { id:itemId, type:type, weight:weight, priority:priority, maxTries:maxTries, preventCaching:preventCaching, checkPolicyFile:checkPolicyFile, headers:headers };
getLoader( loaderId ).add( url, props );
}



public function getLoader(loaderId:String):BulkLoader
{
return BulkLoader.getLoader( loaderId );
}

public function getItem(loaderId:String, itemId:String ):LoadingItem
{
return getLoader( loaderId ).get( itemId );
}

public function getItemContent(loaderId:String, itemId:String, clearMemory:Boolean = false ):*
{
return getLoader( loaderId ).getContent( itemId, clearMemory );
}

public function startLoader(loaderId:String):void
{
getLoader( loaderId ).start();
}

public function clearLoader(loaderId:String):void
{
getLoader( loaderId ).clear();
}





protected function onComplete(event:Event):void
{
sendNotification( ApplicationFacade.BULKLOADER_COMPLETE, (event.target as BulkLoader) );
}

protected function onProgress(event:BulkProgressEvent):void
{
sendNotification( ApplicationFacade.BULKLOADER_PROGRESS, (event.target as BulkLoader) );
}

protected function onError(event:ErrorEvent):void
{
sendNotification( ApplicationFacade.BULKLOADER_ITEM_ERROR, (event.target as LoadingItem) );
}


}
}


Usage as so (i created a BulkLoaderMediator as a template):

:
package tv.stinkdigital.puremvcbase.view
{
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.loadingtypes.LoadingItem;

import flash.display.Bitmap;

import org.osflash.thunderbolt.Logger;
import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.mediator.Mediator;

import tv.stinkdigital.puremvcbase.ApplicationFacade;
import tv.stinkdigital.puremvcbase.model.BulkLoaderProxy;
import tv.stinkdigital.puremvcbase.view.components.LoadingBar;

public class BulkLoaderMediator extends Mediator implements IMediator
{
public static const NAME:String = "BulkLoaderMediator";

protected var bulkLoaderProxy:BulkLoaderProxy;
protected var loaderId:String = "bulkLoad";

public function BulkLoaderMediator(viewComponent:Object)
{
super(NAME, viewComponent);
}

override public function onRegister():void
{
// add component to stage
            sendNotification(ApplicationFacade.ADD_TO_STAGE, viewComponent);
           
            // cache a reference to frequently used proxies
            bulkLoaderProxy = facade.retrieveProxy( BulkLoaderProxy.NAME ) as BulkLoaderProxy;           
           
            bulkLoaderProxy.addLoader( loaderId );

bulkLoaderProxy.addItem( loaderId, "http://example.com/1.jpg", "image1", BulkLoader.TYPE_IMAGE, 100 );
bulkLoaderProxy.addItem( loaderId, "http://example.com/2.jpg", "image2", BulkLoader.TYPE_IMAGE, 100 );
bulkLoaderProxy.addItem( loaderId, "http://example.com/3.jpg", "image3", BulkLoader.TYPE_IMAGE, 100 );

bulkLoaderProxy.startLoader( loaderId );
}

override public function listNotificationInterests():Array
{
return [
ApplicationFacade.BULKLOADER_PROGRESS,
ApplicationFacade.BULKLOADER_COMPLETE,
ApplicationFacade.BULKLOADER_ITEM_ERROR
                   ];
}

override public function handleNotification(note:INotification):void
{
switch ( note.getName() )
      {
          case ApplicationFacade.BULKLOADER_PROGRESS:
         
          var bulkLoader:BulkLoader = note.getBody() as BulkLoader;
          if( bulkLoader.name == loaderId )
          {
          loadingBar.update( bulkLoader.weightPercent );
          }
          break;
         
          case ApplicationFacade.BULKLOADER_COMPLETE:
         
          if( (note.getBody() as BulkLoader).name == loaderId )
          {
          Logger.info( "Bulk Load Complete" );
         
          loadingBar.hide();
         
         
          var img1:Bitmap = bulkLoaderProxy.getItemContent( loaderId, "image1" ) as Bitmap;
          sendNotification( ApplicationFacade.ADD_TO_STAGE, img1 );
         
          var img2:Bitmap = bulkLoaderProxy.getItemContent( loaderId, "image2" ) as Bitmap;
          img2.x = img1.width;
          sendNotification( ApplicationFacade.ADD_TO_STAGE, img2 );
         
          var img3:Bitmap = bulkLoaderProxy.getItemContent( loaderId, "image3" ) as Bitmap;
          img3.x = img2.x + img1.width;
          sendNotification( ApplicationFacade.ADD_TO_STAGE, img3 );
         
         
          }
         
          break;
         
          case ApplicationFacade.BULKLOADER_ITEM_ERROR:
         
         
          Logger.error( "BULKLOADER_ITEM_ERROR" );
         
          break;
         
      }
}

protected function get loadingBar():LoadingBar
{
            return viewComponent as LoadingBar;
        }

}
}
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: July 02, 2009, 03:31:31 »

Thanks stinkyian!
Logged
Pages: [1]
Print