Best Practive to load and handle swf at runtime

PeterQ's Avatar


14 Sep, 2011 04:12 PM

i'am create a larger application with the need of loading a lot of swf adding them to views at runtime. whats the best way to wait of loading data and adding the view to context and adding the loaded content to the view. is it necessary to use a model or service to handle the loading logic (outside the view or mediator)?


  1. 1 Posted by PeterQ on 14 Sep, 2011 04:44 PM

    PeterQ's Avatar

    is it pratical to use a view controller to hold the loader logic?

  2. 2 Posted by jdijr on 20 Sep, 2011 04:52 PM

    jdijr's Avatar

    I would also like to know the answer to this question. It seems like loading swfs at runtime in the robotlegs architecture will break some things. It's almost as if the loading of swfs before startup would make the most sense. But loading all the swfs up front could be seen as cumbersome in larger applications with many view swfs.

  3. Support Staff 3 Posted by creynders on 20 Sep, 2011 08:16 PM

    creynders's Avatar

    I think the reason why there has been no answers yet is because there are a lot of possible scenarios all depending on a bunch of general environment and coding style factors: is it AS only, or using Flex? Do you want to include your view classes in the to-be-loaded swfs or do you compile them into the main application? Do you want to use a modular approach or not?

    In general I tend to take the modular approach, in which a module comprises a specific part of the application. It can hold models, services, views, commands and whatnot. Or it could include only business classes w/o views and assets.

    Defining what will be a separate module is something you learn to recognize with experience and depends on many different parameters: will the module be reused as-is only in this specific client application or will it be reused in various client applications (for instance targeting different platforms: web, mobile, desktop)?
    Could it potentially be used to differentiate on user role and permissions?
    Is it an asset heavy application in which the modules serve the purpose of easing the startup loading time?
    Does it need to encapsulate a 3rd party library that could possible be swapped at a future point in time?

    There are many reasons to split an application into smaller chunks and it's only the full picture that will dictate how these chunks will look like.

  4. 4 Posted by jdijr on 20 Sep, 2011 09:33 PM

    jdijr's Avatar

    For me it's a mxml and as project. There are modules and such but module or not the loading of the swf should be the same. I want the view code to be compiled into the module swf and not the view swf. Getting the swf paired with the view code after the application has started is the problem. I'm thinking about using a swf wrapper class that is a display object that adds the swf to itself via addChild. I need to load the swf before the wrapper is added to the stage and the mediator is created where it will attempt to add listeners to the assets in the swf. Also where this wrapper class is created is a good question.

  5. 5 Posted by Siddharth on 27 Sep, 2011 07:56 AM

    Siddharth's Avatar

    Hi, I am currently facing similar questions... I basically have "view" based modules... And I would like to load them at runtime using the ModuleManager class... Now the problem is onModuleReady, when I use factory.create and addChild , I am unable to see the loaded module. .. But when I comment out the viewMap.mapType statement then the module gets added and can be seen. How do I solve this strange problem ?

  6. 6 Posted by PeterQ on 01 Oct, 2011 12:42 PM

    PeterQ's Avatar

    jdijr, what do you mean with: "It seems like loading swfs at runtime in the robotlegs architecture will break some things"?
    Where is the difference between loading first or at runtime for robotlegs? for some reasons like loading an swf library with animations and something like this, i think its a good pratice to deal with a large amount of data. isnt it?

    Now i'am loading the swf when views are added to the stage automaticliy through the corresponding mediator, which trigger the loading event etc. it works fine.

  7. 7 Posted by bakedbeing on 17 Oct, 2011 05:59 AM

    bakedbeing's Avatar

    Heya guys. This seems like a fair question to me, and I don't think that Peter's being overly vague. It seems to me he's wondering how the loading (and storing?) of views happens in MVCS without breaking MVCS - perhaps it's because I'm wondering that too.

    Should a controller respond to a navigation event and trigger a load, which in turn fires a load complete controller that packs the swf into a typed variable in say a viewSwfPrepared event? If so is it okay to store the swf in a model to prevent reloads?

    Alternately, can a mediator acceptably load view elements that it is missing, and keep them in a vector if they're needed again (say different timeline animated notes with hotspots in a currency viewer). This is what I get from PeterQ's approach.

    Is it valid even for a model to act as a factory and load swfs that are then passed out as event payloads?

  8. 8 Posted by visnik on 18 Oct, 2011 11:54 PM

    visnik's Avatar

    I am currently working on an application that will require loaded swfs as well. I have not finalized the approach, but i was looking at solving it in the following manner.

    Have a ViewContainer object, loaded at run time. Have a command load a swf, update a model, dispatch an event with a displayObject as a payload. Have the Mediator for the ViewContainer Object listen for the event, once heard, call a public method that just passes the display object e.g. loaded swf into the ViewContainer object, and add it to the display list.

    Not sure if this approach helps anyone, or is even close to being correct or efficient, but my 2 cents.

  9. Ondina D.F. closed this discussion on 23 Dec, 2011 08:55 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac