Skip to Main Content
Professional Cairngorm™
book

Professional Cairngorm™

by Jeremy Wischusen
November 2009
Intermediate to advanced content levelIntermediate to advanced
357 pages
8h 20m
English
Wrox
Content preview from Professional Cairngorm™

15.6. Views

First you will deal with the view responsible for displaying messages to the user.

In the com.FlexBlog.views package create a new component based on HBox. Name it NotificationDisplay and clear the height and width values. Edit the component to match the following:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" visible="{this.message.length}"><mx:Script>
<![CDATA[
    import com.FlexBlog.valueobjects.UserNotificationVO;
    [Bindable]
    private var message:String = '';
    [Bindable]
    private var messageStyle:String = '';
    public function set notification(notification:UserNotificationVO):void{
        this.message = notification.message;
        if(notification.type == UserNotificationVO.ERROR_MESSAGE){
            this.messageStyle ='errorStyle';
        }else{
            this.messageStyle='';
        }
    }
    private function clearMessage(event:MouseEvent):void{
        this.message = '';
        this.messageStyle='';
    }
    ]]>
</mx:Script>
<mx:Style>
    .errorStyle{
        color:#95090f;
    }
</mx:Style>
    <mx:Button id="clearButton" label="Clear" click="clearMessage(event);"/>
    <mx:Text fontWeight="bold" fontSize="14" text="{this.message}"
styleName="{this.messageStyle}" width="100%"/>
</mx:HBox>

Starting at the top of the component, notice that the visible property has been tied to the length of the message property. Therefore, this component will display itself only if there is a message to display.

There are two private variables: message and messageStyle. These are used to tell other parts of this component what message to display ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Professional Java® JDK®, 6th Edition

Professional Java® JDK®, 6th Edition

W. Clay Richardson, Jeff Scanlon, Donald Avondolio, Mark W. Mitchell, Scot Schrager

Publisher Resources

ISBN: 9780470497265Purchase book