best practice - I need use movieclips stored in model in my view

Egid's Avatar


12 Feb, 2015 01:20 PM


I have SWFLibsModel which is model that contains various movie clips.
I also need in my main view use those move clips.

What is best practice ? I tryed to put on my view mediator this metod, but I dont like this solution. Thank you for advice.

    private function onSWFLoaded(e:DataEvent):void

  1. Support Staff 1 Posted by Ondina D.F. on 12 Feb, 2015 02:59 PM

    Ondina D.F.'s Avatar

    Hi Egid,

    You are right, passing the model to the view is not nice.

    Your Model could dispatch a custom event on the shared eventDispatcher, with the movie clips as a payload. The Mediator listens to the event, and passes the payload to the view.

    So, if DataEvent is the event dispatched by your SWFLibsModel, you just need to pass the payload to the view:


    where payload (or a name of your choice) is your movieclip or a collection (array) of movieclips

    Depending on the nature of your movie clips, there could be other solutions as well.
    Are they modules, or just some assets (images, sounds) ?
    How are you loading the movie clips and where?

    Take a look at Matan's AssetLoader: , it might be what you need.


  2. 2 Posted by Egid on 17 Feb, 2015 10:08 AM

    Egid's Avatar


    Thank you for answer. I apologise for my inactivity. I was off for few days.

    I use my custom AssetLoader, which load *.swf file, which contains various MovieClips I am using.

    My model looks like this:

    package assets
    import controllers.DataEvent;
    import flash.display.MovieClip;
    import org.robotlegs.mvcs.Actor;

    * @author Egid
    public class SWFLibsModel extends Actor
    private var _swfLibs : Object = new Object();

    public function SWFLibsModel()


    public function saveLib(name:String, lib:MovieClip):void
    _swfLibs[name] = lib;

    eventDispatcher.dispatchEvent(new DataEvent(DataEvent.SWF_LOADED));

    public function getMovieClip(libName:String, clipName:String):MovieClip
    return _swfLibs[libName].getMovieClip(clipName);

    I am passing this model to view and call his method getMovieClip to get any movieClip in library

    var mc : MovieClip = swfLibsModel.getMovieClip("LibTiles", "Bush");

    Its for me really handy to have my assets in swf libraries.

    I was looking and Matan's AssetLoader and not sure if I should this assetLoader over my current assetLoading.


  3. Support Staff 3 Posted by Ondina D.F. on 18 Feb, 2015 12:07 PM

    Ondina D.F.'s Avatar

    No problem:)
    You don't have to use Matan's or anyone else's libraries. It was just a suggestion.

    As I said in my previous post, if you don't like to access your model in your mediator, you can dispatch a custom event from your model with the movieclip as a payload.

    For example:

    var movieclip: MovieClip = getMovieClip(libName, clipName)
    eventDispatcher.dispatchEvent(new DataEvent(DataEvent.SWF_LOADED, movieclip));

    I don't know when are you loading the movieclips and I also don't know how many mediators need to pass assets to their views. Depending on your use case, there might be many solutions.

    You could dispatch the event the moment the movieclips are loaded, or you could let the mediator request the assets within its onRegister() method by dispatching an event to trigger a command .

    override public function onRegister():void
        //add a listener first
        addContextListener(DataEvent.SWF_LOADED, onSwfLoaded, DataEvent ); 
        //then dispatch the event       
        dispatch(new DataEvent (DataEvent.SWF_REQUESTED,  "LibTiles" )); 
    private function onSWFLoaded(e:DataEvent):void 

    DataEvent.SWF_REQUESTED could be mapped to a command:
    commandMap.mapEvent(DataEvent.SWF_REQUESTED, LoadSWFCommand, DataEvent);

    When triggered, the Command can access SWFLibsModel, which is injected into the Command. The model can dispatch the event with the requested assets as a payload to the mediator.

    Let me know if you need more help with this.


  4. Ondina D.F. closed this discussion on 11 May, 2015 11:33 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