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: loading exernal views in a flash application  (Read 8634 times)
separated
Newbie
*
Posts: 6


View Profile Email
« on: December 11, 2007, 05:46:45 »

Hi everyone,

I am trying to build an application in flash using the pureMVC, the question is:

I want to load an external swf ( incorporating a view components on its stage ) in my application and i would like this new view components to be able to send notification to the facade....   I cannot register a mediator for that view components in the ViewPrepCommand cause at the initialization of the application that view components is not loaded yet and will only be loaded when a user click on the button that loads that swf.

Basically i am wondering what's the steps to follow to use a new view components at runtime ?
Should the registration Mediator code:
:
facade.registerMediator(new MyViewMediator(myViewCompMC))
of the new view components be on the external swf ? 

I hope all this is making sense, any feedback will be appreciated,

Thanks ! 
« Last Edit: December 11, 2007, 06:28:44 by separated » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: December 12, 2007, 04:12:25 »

Along the lines of the newly recommended startup idiom (http://forums.puremvc.org/index.php?topic=85.0), you can place a method on the facade that the newly loaded swf can simply on frame1 say something like:

import com.me.myapp.ApplicationFacade;
ApplicationFacade.getInstance().registerLoadedClip(this);

ApplicationFacade.registerLoadedClip() takes the reference to the newly loaded clip, creates and registers the appropriate mediator, passing in the reference to the clip. Note that I say 'appropriate'. registerLoadedClip might look at a variable defined on the clip and do a switch on statement to determine the correct mediator. This would keep you from having to have a special facade method for each clip you want to treat this way.

-=Cliff>
Logged
separated
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: December 13, 2007, 03:18:37 »

Thank you Sir
« Last Edit: December 13, 2007, 09:03:51 by separated » Logged
separated
Newbie
*
Posts: 6


View Profile Email
« Reply #3 on: December 13, 2007, 11:06:27 »

I have implemented the new idiom, and started testing the concept outlined above but it's generating an issue...

To make it had to declare "instance" in ApplicationFacade as a private static var. Is this still respecting the singleton pattern ?

And

In my ApplicationMediator which is holding the reference to the "root" of my application and is being created by ViewPrepCommand i am placing a preloaderMC on the stage:

:
var preloaderMC:Preloader = new Preloader();
facade.registerMediator( new PreloaderMediator(preloaderMC));
application.addChild(preloaderMC);


but when i place this code
:
import com.me.myapp.ApplicationFacade;
ApplicationFacade.getInstance().registerLoadedClip(this);

on the time line of the swf to load and publish, it runs through all the ApplicationFacade code gets to the ApplicationMediator and returns an error because it can't find the loadingBarMC being reference in the Preloader class because the preloaderMC is not in the swf library...

so if i comment out the instantiation of the preloader in the ApplicationMediator and then publish the swf it works fine... then i enable the instantiation on the preloader in the ApplicationMediator publish and my application works.

Basically the reference to view components in the ApplicationMediator is generating errors when you publish the swf that don't have these view components in there libraries...

Thanks ;)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: December 14, 2007, 03:31:12 »

I'd have to see the code to advise further.Not sure why you'd need to mess with the instance var in the facade.

Will have to do a demo soon.

-=Cliff>
Logged
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #5 on: December 26, 2007, 05:48:23 »

Is it not so that we don't want the viewcomponents to have any knowledge of the framework? They should just expose a public API to their mediators, nothing more.

In my opinion, external swf's that are only supposed to be viewcomponents, shouldn't hold any code whatsoever. Using a MovieLoader Proxy, you can load external swf's. When a swf is loaded, the MovieLoader can send a notification to a SimpleCommand that - based on the type of the notification - then registers the appropriate mediator with the facade, passing in the newly loaded swf as its viewcomponent.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: December 26, 2007, 07:52:16 »

Excellent solution Peter!

When I started with the game, I was having problems with FlashLite 2.0 MovieClipLoader not sending all its events, namely progress events. It does send a complete event, and I am sending a notification on it now, but I'd already gone the route of calling a method on ApplicationFacade by the time I discovered that. 

Absolutely, your answer is the correct way.

-=Cliff> 
Logged
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #7 on: December 26, 2007, 02:33:34 »

Well Cliff, what can I say... once you discover the power of the Notifications and the Commands...  ;)
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #8 on: December 26, 2007, 05:50:25 »

Duh...   :P

I was creating a placeholder movie in the app, so that I could wrap a Mediator around that to begin with. Then the MovieClipLoader dynamically replaced the movie. Which is probably the problem 'separated' had with my suggestion.

I felt a little backward about it, but I don't work in Flash that much, and hadn't really worked it out properly yet.  Good thing there are others who are and don't mind chiming in.

Thanks, Peter.
-=Cliff>
Logged
Peter
Full Member
***
Posts: 26


View Profile Email
« Reply #9 on: December 27, 2007, 02:01:18 »

Well, it's just that I'm working on a commercial project so I was forced to find solutions for all sorts of Flash related issues. The good thing is that I could solve just about anything using the Proxies and Commands. Man, you did a good job writing PureMVC. It's the best thing I've seen yet.
Logged
Pages: [1]
Print