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: Preloading Assets on runtime  (Read 15040 times)
negttid
Newbie
*
Posts: 3


Flash/Flex AS2/AS3 Developer

 - 381530882
View Profile Email
« on: October 26, 2007, 12:13:19 »

Hello,

I would like to know the best practice, when I have to load Assets on runtime.
Should I use a Proxy (Model) to organize the import of visual classes and then create Mediators (View) and connect these to the new loaded ViewComponents?

The examples so far have all their assets loaded before the application starts, but how to handle a step by step loading on runtime best with pureMVC?

Regards,
Matthias
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 26, 2007, 10:23:27 »

Matthias,

Can you give an example of what Assets you are talking about loading?

-=Cliff>
Logged
meekgeek
Full Member
***
Posts: 25


View Profile Email
« Reply #2 on: October 28, 2007, 02:04:30 »

I would like to know an answer to this as well.

In my situation (using flash cs3), it could be a another component on another swf file ( build with pure mvc  ;D).

Seems confusing to me if you treat the information as part of the model layer  ???
Logged
negttid
Newbie
*
Posts: 3


Flash/Flex AS2/AS3 Developer

 - 381530882
View Profile Email
« Reply #3 on: October 29, 2007, 07:05:20 »

With the word "asset" I mean a visual asset (as3/flashCS3 based swf). This asset has to be loaded on runtime, because it is too huge to load before my application starts. And I know, that this would probably best placed into a ViewComponent, so no PMVC tier is involved, BUT because this SWF consists of a few assets/classes, I saw it as some kind of data. And the laoding of this (visual) data could be the task of a AssetDataProxy. The AssetDataProxy could notify the PreloaderMediator while loading and the corresponding Mediators when all content is loaded.
Am I totaly wrong with this?

Of yourse I could put loading into something outside of pmvc, but loading assets is part of my application. ;-)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: October 29, 2007, 03:12:25 »

I will actually be releasing a demo FlashLite game called Balloonatroid along with the new PureMVC/AS2 port very soon. In the game I do this very thing. You see the initial splash screen and can play one of a number of levels. Each level has unique assets and they won't all fit in the phone. It would also possible to monetize such a game architecture by adding additional gameplay levels for a fee, so all the more reason to have these extra asset files.

You may not have the luxury of waiting for this to be released though, so I'll briefly describe what's going on:

The main MovieClip has the symbols for the splash screen and the player's stuff, and it has an instance of an empty MovieClip called level_mc on the stage. The splash screen is all Flash with several MCs animating on their own timelines without assistance from PureMVC.

When the user hits the Play button we will load the appropriate SWF file for the current level which has the scrolling background and the boss and defender assets.

GameFacade has a startup() method (see this post: http://forums.puremvc.org/index.php?topic=85.0) which the main MovieClip calls on frame 1, passing a reference to itself.

GameFacade.startup() sends the notification that triggers StartupCommand to instantiate GameStateProxy, GameHistoryProxy, GameClipMediator and LevelClipMediator.

GameStateProxy, in addition to tracking score and such, generates the name of the SWF to load based upon the current game level. That level is pulled from the local shared object by the GameHistoryProxy and defaults to if you've played before or 1 otherwise. There are GameStateVO and GameHistoryVO that hold the data these two proxies work with.

In StartupCommand, LevelClipMediator is instantiated and passed a reference to level_mc as its viewComponent.

When the user hits the play button, LevelClipMediator hears about it and replaces its view component using a MovieClipLoader instance it created in its constructor. It does an addListener(this) to the MovieClipLoader and has an onLoadError method to handle loading faults.

Oddly, the FlashLite 2.0 engine has some wierd difficulty getting me other events like the all important onLoadComplete. Fortunately due to the tiny filesizes required by the phone (the main swf and a level are both under 300k combined) it's almost instantaneous. I don't think this will be a problem with Flash 9 targeted apps, though.

Please ask if any of this is unclear, but I think it's something like the solution you're looking for, though you'll have to map it to your problem domain.

-=Cliff>
Logged
negttid
Newbie
*
Posts: 3


Flash/Flex AS2/AS3 Developer

 - 381530882
View Profile Email
« Reply #5 on: October 30, 2007, 01:22:15 »

Hi Cliff,

so in short: the Loader (a view component) is bound to a Mediator, not a proxy. Your proxy just holds the names of the assets, which the Mediator/Loader shall load.
That's fine. Thanks,

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



View Profile WWW Email
« Reply #6 on: October 30, 2007, 09:32:09 »

Matthias,

Close. The MovieClipLoader is just a private property of the LevelClipLoader, whose viewComponent is actually the level MC that the loader will replace.

Otherwise, correct.
-=Cliff>
Logged
meekgeek
Full Member
***
Posts: 25


View Profile Email
« Reply #7 on: October 30, 2007, 01:37:22 »

That makes sense, however, in AS3 what would be best practice to "addChild()" after load is complete?

At the moment, My StageMediator listens for "ADD_TO_STAGE" and I pass my viewComponent.  Is this wrong?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: October 30, 2007, 02:06:52 »

No, it's right. That's a good way to get it onto the stage.

-=Cliff>
Logged
Pages: [1]
Print