Jump to content
Search Community

Handling SWFs Load and Unloading on a Website

isaacalves test
Moderator Tag

Recommended Posts

I'm building a website - using Flash IDE and Textmate - from scratch using just a couple frameworks (Greensock for tweening and loading), and a singleton class to handle the whole thing. I'm not using any framework like Gaia, for instance, or any other MVC framework. The singleton helps me keep track of the pages and components, in a way I can add objects to it, and then have access to them whenever I am. I mean, For example, on the constructor of each swf's class I have something like this:

 

_app = myApp.getInstance();
_app.addObject("contactpage", this);

 

Some pages are quite complex, with panels, menus and galleries, etc, so I've linked some movieclips that are already on stage to separated classes, to provide an easier maintenance of the code. Then i have some movieclips on the library with linkage IDs for instatiating on ActionScript. Finally I have also some components that are separated SWFs, cause they must be on different pages. For example, I have a StatusPanel that appears both on the OrderPage and the GalleryPage.

 

I have dispose() methods in each classes, in order to avoid errors and CPU consuming.

 

Though it's organized in my own way, I sometimes face problems for example, when I want to access the dispose methods of loaded SWFs that are loaded with SWFLoader for example.

 

Well I can circumvent that but the whole thing becomes messy each time..

 

What do you guys think? Which are the best practices on that issue?

 

Thanks!

Link to comment
Share on other sites

Hey Carl, what's up?

 

That's not really a problem... for example... in that case, when I have a 'component SWF' (StatusPanel) that gets loaded in two or more 'pages SWFs', I can do something like this:

 

I declared the 'component SWF' as a class variable of the class of the 'page SWF' that'll load it. If I use strong typing I get plenty of errors.

 

private var statusPanel:*;

 

and then when it gest loaded, in the SWFLoader onComplete handler:

 

statusPanel = e.target.content.getChildAt(0);

 

and when i want to dispose it i'll do:

 

if (statusPanel) statusPanel.dispose();

 

That doesn't seem to be a good practice...

 

I'm actullay asking for suggestions on how to build/structure a website/app with a modular approach. What I do now is basically use the Flash IDE to build the library of MovieClips, embedded small bitmaps, fonts, etc, and pre arrange this stuff on the stage. And then I use TextMate for coding, trying to keep as modular as possible in order to have consistency and reuse code.

What happens is that i eventually face some situations where I have to decide whether I'll make something a different SWF, a MovieClip in the library that'll be linked to a Class and I'll instantiate in AS3, or leave it already added to the stage in the FLA...

 

No big deal, I just would like to know other people's thoughts on that. As well as on handling 'pages SWFs' with Greensock's SWFLoader.

 

I've used some frameworks like Gaia, a couple of times already, but I'm trying to do things on my own now...I graduated in design but in terms of code i'm an autodidact, so stuff like MVC frightens me up yet...

 

Cheers!

Link to comment
Share on other sites

Hi Isaac,

 

Thanks so much for the clarification. Unfortunately I'm in a similar boat as you and not terribly equipped to really suggest "best practices" and complex architectures. I'm more of a brute-force kind of guy and if I can get something to just work... I'm pretty happy.

 

You may find some guys on the kirupa.com or actionscript.org forums a bit more vocal and elaborate in their advice on such matters.

I'd think that if you seek guidance on one particular aspect of your structure in one of those forums, plenty will chime in.

 

I have heard plenty of people speak well of gaia and integrating LoaderMax with it successfully.

 

I'd say you are wise to experiment with your own systems as it is the best way to learn what works and what doesn't. I know for myself this stuff doesn't always come easily but over time it does get easier.

 

I wish I could be of more help.

 

Carl

 

 

 

-c

Link to comment
Share on other sites

Just a couple of quick thoughts:

 

1) You can use the rawContent rather than content.getChildAt(0).

//the following two lines are equivalent:
statusPanel = e.target.rawContent;
statusPanel = e.target.content.getChildAt(0);

 

2) You could automate the dispose() call for your subloaded swfs so that you don't need to manually remember to call it from the parent. See this thread for details:

viewtopic.php?f=6&t=4212&p=16730#p16730

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...