O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required