PureMVC Architects Lounge

PureMVC Manifold => Demos and Utils => Topic started by: puremvc on September 29, 2008, 06:50:29



Title: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: puremvc on September 29, 2008, 06:50:29
This demo illustrates the use of the PureMVC framework, the Startup Manager Utility, and its new Asset management classes to load display assets at startup.

The demo is located at http://trac.puremvc.org/Demo_AS3_Flex_StartupForAssets

The author is Philip Sexton.

NOTE: This project is now known as LoadupForAssets, and was renamed when StartupManager was renamed Loadup, to dispel the notion that the utility it was only usable at startup time.

The new thread is here: http://forums.puremvc.org/index.php?topic=1395.0


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on September 30, 2008, 05:17:54
Note that this demo requires the latest version of the StartupManager utility, that is, version 1.5, which has just been tagged as the current version.
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: lulumOriss on October 18, 2008, 02:40:47
Hi,

I try to set up this demo for my development.
My files are well loaded but I can't understand how I have to store assets data in an appropriate proxy.
I think I have to register a proxy for each assets url but...

Here's my StartupCommand :

:
public class StartupCommand extends SimpleCommand implements ICommand
{
override public function execute( note:INotification ) : void
{
this.facade.registerProxy( new SettingsProxy( ) ); // this is the proxy where I want to store data from "assets/settings.xml"

var l_fileList:Array = [
"assets/settings.xml"
];
this.facade.registerProxy( new Proxy( ApplicationFacade.URL_GROUP_PROXY, l_fileList ) );
this.facade.registerMediator( new ApplicationMediator( note.getBody( ) ) );
}
}

Can anyone help ? lulu.

Subsidiary question : when I try to load a .css file, my application crashes (in a previous demo, it worked). Do you know why ?


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on October 20, 2008, 04:57:04
Is your ApplicationMediator the same as the one in the demo?

The ApplicationMediator has a var 'groupOfUrls'; it expects to be assigned an array of urls.  Your code indicates that you provide an array containing the single url, that for the xml file.  And I think you say that it loads.

If I understand you correctly, your settings proxy has to process the xml file content and get from it the set of urls for the assets that you wish to load.  And you then have to process this set as another group of urls to be loaded.  So it's a two-step process.  Is this the requirement?

Also, the StartupManager Utility asset Loader feature does not currently recognise files of type .css.  I should add this as a text asset type, presumably.  In the meantime, one workaround is for you to extend the AssetFactory class and override the urlToType function.

The currently supported set of types in the AssetFactory urlToType method are
- image type: .jpg, .gif, .png
- text type: .txt, .xml
- swf type: .swf

Apart from .css, what other types should I include?
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: lulumOriss on October 20, 2008, 08:04:08
Hi,

thank you for your reply.

Actually, I just want to set my data from each url (just one in my sample code but the same for more) in a specific proxy.
I use the same ApplicationMediator as the one on the demo and in the NEW_ASSET_AVAILABLE handler, I compare the url to set the appropriate proxy (see below).

I guess there's an automatic process to do this. Isn't it ?

:
private function setProxyData( p_asset:IAsset ):void
{
var l_proxyName:String;
var l_data:*;
switch( p_asset.url )
{
case DefaultAssetsURL.SETTINGS_URL:
l_proxyName = SettingsProxy.NAME;
l_data = new XML( p_asset.data );
break;
}
var l_proxy:IProxy = this.facade.retrieveProxy( l_proxyName );
l_proxy.setData( l_data );
}

//[...]
case StartupManager.NEW_ASSET_AVAILABLE:
this.setProxyData( note.getBody( ) as IAsset );
break;
//[...]

Thanks for the .css.
No other type wish for the moment.

lulu.


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on October 20, 2008, 08:47:24
Still not sure what your question is...

By using the StartupManager assetLoader, there is an AssetProxy created for each url.  Each asset proxy has the url string as its name and has the IAsset object as its data.  Hence, facade.retrieveProxy(url) can be used to get a reference to the asset proxy.

Does this help?

Also, let me just repeat the following question, to make sure it is addressed to all interested developers.
The currently supported set of types in the AssetFactory urlToType method are
- image type: .jpg, .gif, .png
- text type: .txt, .xml
- swf type: .swf

Apart from .css, what other types should I include?
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: lulumOriss on October 20, 2008, 08:58:59
ok.
You solve my problem.

Thanks.


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: lulumOriss on October 21, 2008, 08:04:17
I'm back javascript:void(0);

I have understood where the data are stored after loading but, actually, I want to use a personal proxy with specific methods.
What is the best way to do this ?

Thanks. lulu.

(I try to be clear but...)


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on October 21, 2008, 09:07:18
First, note that after the load, in addition to the AssetProxy objects, there is an AssetGroupProxy object that is a single proxy for the group of assets.

As regards the personal proxy, I suppose you design it to have the behaviour you require and you populate it from the data that has been stored in the AssetProxy objects.

----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: lulumOriss on October 21, 2008, 10:19:37
Yes, that's the idea.
Should I transfer data from the default proxy to my personal one in the NEW_ASSET_AVAILABLE handler (like I did in my sample code above) ?


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on October 22, 2008, 08:23:22
Yes, that's ok.
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on May 18, 2009, 08:18:54
Hi Folks!
I am making a photo viewer app in pure flash environment with puremvc,
I have a problem loading multiple thumbnail jpegs using assetloader: Type was not found or was not a compile-time constant: UIComponent... this utility in only for flex?

thanks
C


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on May 19, 2009, 03:03:32
@crypt
The assetloader feature is part of the StartupManager utility (SM). 

In that utility, there are 2 interfaces available for assets: IAsset and IAssetForFlex.  The 3 supplied asset classes implement IAssetForFlex - the 3 classes are AssetOfTypeImage, AssetOfTypeSwf and AssetOfTypeText - the code content is extremely small.  If you want to avoid IAssetForFlex, and thus avoid UIComponent, you could create your own versions of these asset classes to extend AssetBase and implement just IAsset.

Let me try to be more comprehensive in my reply.  Say you want to continue to just include the SM utility as a lib component - the .swc file.  In that case. it seems to me, you could do the following
- create your own 3 classes as described above, but with different  names
- create your own AssetTypeMap class, different name, implementing IAssetTypeMap; the only change from the utility version is to substitute your own names for the 3 asset classes
- create your own LoadAssetGroupCommand class, different name; the only change from the utility version is to substitute your own name for the AssetTypeMap class.

Hope this helps.
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on May 19, 2009, 03:16:38
Thanks! It's help a lot! Meanwhile i hacked the files you mentioned, but the sollution you prefer is much more elegant! I would go that way. Thanks for fast reply!


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on May 20, 2009, 07:30:23
just one more question :-)

i am loading small thumbnails LoadAssetGroupInstructions, In groupOfUrls:Array i defined thumnails url's,   but the loading sequence is different from groupOfUrls. Is there any sollution for this? To sequence the loading?

I use this command when new asset is available:
case StartupManager.NEW_ASSET_AVAILABLE:
                   popupThumbnails.addItem( ((note.getBody() as IAsset).data) as DisplayObject );

That's ok, but I need more information about thumbnails not just pure bitmap data. How can i send and receive other paramaters about assets? Like id, name, url, comment... ?

thanks!!
crypt


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on May 22, 2009, 03:09:12
@crypt
Is there any sollution for this? To sequence the loading?
As you may know, the StartupManager utility (SM) has a sequencing feature - see StartupAsOrdered demo. So, you could do the following, in your load assets command
- make and register a StartupResourceProxy object for each asset; say ar1, ar2, etc
- express the sequencing by using the appropriate requires statements, for example: ar2.requires = [ar1];
- use addResource() instead of addResourceViaStartupProxy().

other parameters about assets? Like id, name, url, comment... ?
Maybe the following
- extend IAsset to include the additional attributes
- in your load assets command, when each asset is instantiated using the AssetFactory, set the additional attributes on the asset; this assumes that the additional attributes are available from the same source as the url string, so maybe groupOfUrls is not just an array of urls, maybe each array element contains the url plus the additional attributes.

Hope this helps.
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on May 22, 2009, 09:55:19
THANKS! I make a copy of the original LoadAssetGroupCommand, now I called it LoadAssetGroupAsyncCommand

and looks like:
            var prevProxy:StartupResourceProxy;
            for ( var i:int=0; i < groupOfUrls.length; i++ ) {
                var url :String = groupOfUrls;
                if ( facade.hasProxy( url )) {
                    sendNotification( StartupManager.URL_REFUSED_PROXY_NAME_ALREADY_EXISTS, url, groupId );
                }
                else {
                   
                    var asset :IAsset = assetFactory.getAsset( url );
                    var px :IStartupProxy = new AssetProxy( groupPx, url, asset );
                    facade.registerProxy( px );
                   
               var rAssetProxy:StartupResourceProxy = makeAndRegisterStartupResource( url , px );
               if(prevProxy!=null)rAssetProxy.requires = [ prevProxy ];
               prevProxy = rAssetProxy;
                   
                }
            }


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on June 01, 2009, 04:14:11
Just one more.. ;-)

I have a mediator (ThumbnailsMediator.as) that is for viewing small thumbnails of photos from the current category. So if you change category, there will be showed another thumbnails.
In this mediator I use StartupManager.NEW_ASSET_AVAILABLE - notification and a command
popupThumbnails.addItem( ((note.getBody() as IAsset).data) as DisplayObject );
to add new items to the view. It's okey..

if i change category new thumbnails will be loaded and new_asset_available notification willl fire.. but if I change back to the previous category, i can't use this notification because they are already loaded.
what do you think? what can I do in this situation?


thanks!


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on June 02, 2009, 02:46:24
I'm sorry. I don't understand the question.

Is there a separate ThumbnailsMediator instance for each category?  When you change back to the previous category, are the thumbnails displayed?  Is each category treated as a separate asset group with it's own AssetGroupProxy instance?

The NEW_ASSET_AVAILABLE notification has the the asset group proxy name as notification type.  This can be used in the mediators to determine whether a notification is relevant.

Hope this helps.
----Philip


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on June 02, 2009, 03:31:26
Thanks for your fast reply, my english is bad.. ;-)

No I have only one ThumbnailsMediator, I want to use this to display all of the categorys, (maybe this is the problem..). It has a viewComponent: popupThumbnails.

If I change category first I use my method to remove all thumbnails >  popupThumbnails.removeAll();

After it I am listening to NEW_ASSET_AVAILABLE notification, and if a new asset is available > popupThumbnails.addItem(..

but if I change back to the previous category, i can't use this notification because this notification will not fire again, because this assets are already loaded somewhere


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on June 02, 2009, 06:29:44
ok, so one possibility is...
- a mediator instance per category, with a mediator name that is same as asset group proxy name
- a popup thumbnails component instance per category; maybe it doesn't have to be a popup, but maybe you want it to be, so whatever you choose.

another possibility, closer to your existing approach, is...
- when you change back to a previous category, the mediator needs to know this; via a notification if needs be, say we call this 'redisplay'
- in mediator, on redisplay, get all the loaded assets from the relevant asset group proxy (via getData() say) and add them to the mediator's view component.

Or maybe you can see other better approaches now.
----Philip

maybe you


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: crypt on June 02, 2009, 06:50:57
okey! fine! thanks!
now I can go on! :-)


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on July 12, 2009, 04:52:30
There is a new version of the StartupForAssets demo in the code repository; in trunk, not tagged.

Here is the relevant extract from version.txt.

2.0 - Requires StartupManager Utility version 2.0.  Now demonstrates
    loading of single assets as well as a group of assets, concurrently
    if desired.


Title: Re: Startup for Assets - A PureMVC AS3 / Flex / StartupManager Demo
Post by: philipSe on July 17, 2009, 03:36:28

See this post: http://forums.puremvc.org/index.php?topic=259.msg6136#msg6136 (http://forums.puremvc.org/index.php?topic=259.msg6136#msg6136)

Arising from that, my post above about this demo code in the repository trunk is premature, since there is not yet a StartupManager Utility version 2.0.  Hence, this demo code is in transition and is not a final version.  Use it at your own risk and be aware that the ultimate version will probably require you to refactor what you've done.

My apologies for any inconvenience caused.
----Philip