[Pixlib] pixlib - examples

Francis Bourre peterphonix at usa.net
Wed Dec 20 09:04:08 EST 2006


yeah, sorry !

Lemme explain quickly the main concept.

Here's the cornerstone for communication beetween designers and coders.
It's all in the the class below and it's embedded in the 1st lightweight loader of the site/application.
The main key is _global.__DISPATCH.
Each designer of my company uses this global method to dispatch an order or an important event to the site/application engine.
Some examples: End of an animation happens, User asks for opening a new Menu item, Play a video ...
The goal is to split main logic from graphical part and give enough freedoom to designers.
Each designer event is logged and handled by the frontcontroller.
We share the build process of an EventList to make the site/application.

Code snippet of an event dispatched from a fla. 
_global.__DISPATCH( {type:"onIntroAnimationEnd"} );

Another Code snippet of an event dispatched from a fla. Event arguments are dynamic (DynBasicEvent).
_global.__DISPATCH( {type:"onOpenMenuItem", name:"Contacts", id:3} );

Now let's see the code of the class ->

private static function _initGlobals() : Void
 {
  _global.__DISPATCH = Loader._dispatchEventToController;
  _global.__LOG = Loader._logMessage;
  _global.__CONFIG = Loader._getConfig();
  _global.__LOADER = getInstance();
  _global.__TRANSLATE = Loader._translate;
 }

private static function _dispatchEventToController( o : Object ) : Void
 {
  Debug.DEBUG( o );
  EventBroadcaster.getInstance().dispatchEvent( o );
 }
 
 private static function _logMessage( o ) : Void
 {
  Debug.INFO( o );
 }
 
 private static function _getConfig() : Object
 {
  return Config.getInstance();
 }
 
 private static function _translate( sID : String ) : String
 {
  return Language.translate( sID );
 }


It's a really short explanation, hope that will help someone to understand,

francis
  ----- Original Message ----- 
  From: Marcelo de Moraes Serpa 
  To: Pixlib at osflash.org 
  Sent: Wednesday, December 20, 2006 1:27 PM
  Subject: Re: [Pixlib] pixlib - examples


  Very helpful Francis! Thanks a lot. What about the workflow thing!? Sorry if I'm being balky...

  Something keeps telling me that we need a dedicated wiki for pixlib or something ... we are all hungry for more documentation right? Let's put them on the proper place! 

  Btw, this mailing list is already a very rich resource (although not structured).

  Marcelo.


  On 12/20/06, Francis Bourre < peterphonix at usa.net> wrote:
    Hello, lemme give few more infos:

    The controller is initialized in my Site constructor:



    private function Site( mc:MovieClip )
     {
      super( UIList.SITE, _level0.createEmptyMovieClip("__SITE", 1) );
      
      Dictionnary.DEBUG_IS_ON = false;
      Debug.INFO("Dark Messiah Site LAUNCHED");

      Controller.getInstance().init();
      var navModel : NavModel = new NavModel();
      
      if (Config.getInstance().deleteCookie) SharedObjectUtils.saveLocal( "com.periscope.dm", "alwaysSkipIntro", false );
      
      _loadIntroLibs();
     }




    As you guessed, _getGL is a private method of my Site class.




    private function _getGL( nDepth : Number, target : MovieClip ) : GraphicLib
     {
      return new GraphicLib( (target?target:view), nDepth, false );
     }
     


    I got a SiteEngine class for every project which instantiates all the components of my site/application.
    Real world example shown below (for http://www.darkmessiahgame.com/ ) 



    class com.periscope.dm.core.SiteEngine 
    {
     public function SiteEngine() 
     {
      Debug.DEBUG( "SiteEngine constructor" );
      
      var videoUI : VideoUI = new VideoUI();
      var deathVideoUI : DeathVideoUI = new DeathVideoUI();
      var weaponVideoUI : WeaponVideoUI = new WeaponVideoUI();
      var deathScreenUI = new DeathScreenUI();
      
      var walkVideoModel : WalkVideoModel = new WalkVideoModel( videoUI.getVideoObject() );
      walkVideoModel.addListener( videoUI );
      
      var deathVideoModel : DeathVideoModel = new DeathVideoModel( deathVideoUI.getVideoObject() );
      deathVideoModel.addListener( deathVideoUI );
      deathVideoModel.addListener( deathScreenUI );
      
      var weaponVideoModel : WeaponVideoModel = new WeaponVideoModel( weaponVideoUI.getVideoObject() );
      weaponVideoModel.addListener( weaponVideoUI );
      
      var weaponScreen = new WeaponVideoScreenUI();
      var mediaScreen = new MediaVideoScreenUI();
      
      var console = new ConsoleUI();
      var nav = new NavUI();
      var logo = new LogoUI();
      var forum = new ForumUI();
      var lightLoader = new LightLoaderUI();
      
      var preorder : PreorderUI = new PreorderUI();
      
      var backgroundModel : BackgroundModel = new BackgroundModel();
      backgroundModel.addListener( new ItemBackgroundUI() );
      
      var contentModel : ContentModel = new ContentModel();
      contentModel.addListener( new ContentUI() );
      
      var prevNextUI : PrevNextUI = new PrevNextUI();
      
      var glowUI : GlowUI = new GlowUI();
      walkVideoModel.addListener( glowUI );
      
      var menuPlayer : MenuPlayer = new MenuPlayer();
      walkVideoModel.addListener( menuPlayer );
      
      var soundLib : MovieClip = GraphicLibLocator.getInstance().getGraphicLib(UIList.SOUND).getView();
      SoundFactoryManager.getInstance().init( soundLib );
      SoundFactoryManager.getInstance().addSounds(Config.getInstance().sound);
      _global.__SOUND = SoundFactoryManager.getInstance();
      
      var imageUI : ImageUI = new ImageUI( MovieClipHelper.getMovieClipHelper(UIList.CONTENTCONTAINER).view, 40 );
      var charViewer : CharacterViewerUI = new CharacterViewerUI( MovieClipHelper.getMovieClipHelper(UIList.CONTENTCONTAINER).view, 60 );
      //var charScroller = new CharacterScrollerUI();
      
      var tuto = new TutoUI();
      var muteUI : MuteUI = new MuteUI();
      
      var videoLoader : VideoLoaderUI = new VideoLoaderUI();
      
      var fpsLogger = new FPSLoggerUI();
      var videoLogger = new VideoLoggerUI();
      walkVideoModel.addListener( videoLogger );
     }
     
     /**
      * Returns the string representation of this instance.
      * @return the string representation of this instance
      */
     public function toString() : String 
     {
      return "'" + ClassUtils.getFullyQualifiedClassName( this ) + HashCodeFactory.getKey( this ) + "'";
     }
    }



    Hope that helps a bit more,

    francis
      ----- Original Message ----- 
      From: Tim Will 
      To: Pixlib at osflash.org 
      Sent: Wednesday, December 20, 2006 4:13 AM
      Subject: Re: [Pixlib] pixlib - examples


      OH! OH!  I GET it!!
      sorry for so many emails tonight guys...but it is all starting to come together for me now....
      So, I think after our LibStack has completed loading all the swfs via GraphicLibs, probably the next thing we do is instantiate our model(s) like so;
      var model : Model = new SomeModel();///// where SomeModel extends Model()

      then, after that we can instantiate our UIs and make them listeners of SomeModel like this;
      model.addListener( new SomeUI() );//// where SomeUI extends MovieClipHelper

      Inside of SomeUI is a reference to the unique name of a GraphicLib (the same name that we passed into the LibStack - we can retrieve it from the UIList enumerator).  This reference is passed to the superconstructor, which calls the GraphicLibraryLocator method and gives it the reference.  The GraphicLibraryLocator locates the GraphicLib and maps it to the MovieClipHelper that SomeUI extends.  Next the MovieClipHelper uses the setName() method to set it's own name the same as the GraphicLib. 
      In this way, the SomeUI class is now associated with the swf that was loaded, and is subscribed to hear events from the model.

      After this, we could initiate a controller that extends FrontController...this would be used to map commands to events.  Those commands update the model(s).
      We can also update the views with Commands, but we don't absolutely have to - we could have methods in our UI class with the same name as the event type broadcast by the model, and they will get executed.

      And so....our MVC is complete!
      Woohoo!!!  Thank you so much for that example, very useful.
      (I hope I remember this tomorrow...ha ha!)
      -tim.

       
      On 12/19/06, Tim Will <thedigitalartist at gmail.com> wrote: 
        Ah ha!  Perfect!
        Okay, so I fully understand then.  Thank you Ali.
        And in the example, I see you can also pass the view as a parameter right?  Because GraphicLib allows you to pass depth, container clip, and 'autoshow' as a boolean.  This is demonstrated by;

         libs.enqueue( _getGL(10, contentContainerUI.view), UIList.ITEMBACKGROUND, "swf/fond_rubriques.swf");

        In this case, the swf will be loaded into depth 10 of "__container" movieClip, and its GraphicLib name will be retrieved from "UIList.ITEMBACKGROUND" enumerator.........so cool!!
        Once again, I am quite impressed!

        -tim.

         
        On 12/19/06, ali_o_kan < ali_o_kan at get-url.net > wrote: 
          Hi Tim,

          _getGL is a private function used to encapsulate the construction of
          the GraphicLib ;)

          private function _getGL( nDepth : Number ) : GraphicLib
                 {
                         return new GraphicLib( view, nDepth, false );
                 }

          bye,
          Laurent

          --
          Communication �lectronique
          http://www.get-url.net
          +32 477 62 34 37




          Le 20-d�c.-06 � 02:47, Tim Will a �crit :

          > But I am missing one thing: where does "_getGL(5)" come from?  I
          > know it is of type ILib, but how was it instantiated?  Maybe by 
          > action of the ConfigLoader???  I know I must do more digging...but
          > a push in the right direction is good...
          > Thanks very much.
          > -tim


          _______________________________________________ 
          Pixlib mailing list
          Pixlib at osflash.org
          http://osflash.org/mailman/listinfo/pixlib_osflash.org







--------------------------------------------------------------------------


      _______________________________________________
      Pixlib mailing list
      Pixlib at osflash.org
      http://osflash.org/mailman/listinfo/pixlib_osflash.org



    _______________________________________________
    Pixlib mailing list
    Pixlib at osflash.org
    http://osflash.org/mailman/listinfo/pixlib_osflash.org







------------------------------------------------------------------------------


  _______________________________________________
  Pixlib mailing list
  Pixlib at osflash.org
  http://osflash.org/mailman/listinfo/pixlib_osflash.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/pixlib_osflash.org/attachments/20061220/760d4f0d/attachment-0001.htm


More information about the Pixlib mailing list