22.5. Revising Loading Posts

The loading and displaying of posts is currently accomplished with the following classes.

  • LoadRecentPostsEvent

  • LoadRecentPostsDelegate

  • LoadRecentPostsCommand

  • SetCurrentPostEvent

  • SetCurrentPostCommand

The LoadRecentPostsEvent and SetCurrentPostEvent will become types on the PostEvent class.

The loadRecentPosts function of the LoadRecentPostsDelegate will be moved to the PostDelegate.

The LoadRecentPostsCommand will be updated to use the PostDelegate.

The SetCurrentPostCommand will be updated to cast the event as a PostEvent.

Start by adding the following constants to the PostEvent class:

public static const LOAD:String = 'loadPostsEvent';

Move the loadRecentPosts function from the LoadRecentPostsDelegate to the PostDelegate. The PostDelegate should now look like this:

package com.FlexBlog.delegates
{
    import com.FlexBlog.valueobjects.PostVO;
    import flash.errors.SQLError;
    import mx.rpc.IResponder;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.events.ResultEvent;
    import sql.FlexBlogDatabaseManager;
    public class PostDelegate
    {
        private var responder:IResponder
        public function PostDelegate(responder:IResponder)
{ this.responder =responder; } public function addPost(post:PostVO):void{ var dbManager:FlexBlogDatabaseManager = FlexBlogDatabaseManager.getInstance(); try{ var added:int = dbManager.addPost(post); var event:ResultEvent = new ResultEvent(ResultEvent.RESULT,false,true,{added:added}) this.responder.result(event) }catch(error:SQLError){ var faultEvent:FaultEvent ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.