2009
08.25

EshopDesktop网店系统仿QQ消息提醒功能分享:
先看下效果图:
msg

实例代码如下:

public static function palyHandle(e:Event):void{
           var sound:Sound = e.target as Sound;
           sound.play();
           trace('play msg alert');
          }
          private static function errorHandle(e:ErrorEvent):void{
           trace(e.text);
          }
          public static function showNotification(title:String, content:String, showDetail:Boolean = false):void{
              //播放声音
              if(AppModel.getInstance().setting.sound==1){
                  trace('start play msg alert');
                  var url:URLRequest = new URLRequest('/Assets/Sound/newalert.mp3');
                  var voice:Sound =new Sound(url);
                  voice.addEventListener(Event.COMPLETE, palyHandle);
                  voice.addEventListener(IOErrorEvent.IO_ERROR, errorHandle)
              }
               var notice:Notification = new Notification();
               notice.alwaysInFront = true;
               notice.showStatusBar = false;
               notice.msgTitle = title;
               notice.msgContent = content;
               notice.showDetail = showDetail;
              
               notice.open();
               var mainScreen:Screen = Screen.mainScreen;
               var winMove:Move  = new Move();
               winMove.target = notice;
                winMove.xTo = winMove.xFrom = mainScreen.visibleBounds.width - notice.width - 10;
                winMove.yFrom = mainScreen.visibleBounds.height;
                winMove.yTo = mainScreen.visibleBounds.height - notice.height -3;
                winMove.duration = 1000;
                winMove.play();
          }
窗体控件:
<?xml version="1.0" encoding="utf-8"?>
<mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  width="250" height="185"
paddingBottom="0"  paddingTop="0"  status="false"
     showFlexChrome="false"  transparent="true" systemChrome="none"   title="消息提醒:"
    showStatusBar="false" showTitleBar="false" verticalScrollPolicy="off"  horizontalAlign="center"
horizontalScrollPolicy="off" showGripper="false" paddingLeft="5" paddingRight="5" borderStyle="none">
    <mx:Script>
     <![CDATA[
     import Eshop.Units.WindowsEffect;
     import mx.core.Application;
     [Bindable]
     private var _msgTitle:String='消息提示:';
     [Bindable]
     private var _msgContent:String = '';
     [Bindable]
     private var _showDetail:Boolean = false;
    
     public function set msgTitle(value:String):void{
     _msgTitle = value;
     }
     public function get msgTitle():String{
     return _msgTitle;
     }
     public function set msgContent(value:String):void{
     _msgContent = value;
     }
     public function set showDetail(value:Boolean):void{
     _showDetail = value;
     }
     private function closeWin():void{
     WindowsEffect.close(this);
     }
     private function startMove():void{
     this.nativeWindow.startMove();
     }
     ]]>
    </mx:Script>
    
    <mx:Image width="250"  height="185" source="Skin/Default/images/titleWindow.png"/>
    <mx:HBox horizontalGap="0" mouseDown="startMove()" width="100%" height="35" verticalAlign="middle" paddingLeft="5">
        
        <mx:Label text="{_msgTitle}" fontWeight="bold" width="220" color="#FFFFFF"/>
        <mx:Image width="16" toolTip="关闭窗口" height="16" buttonMode="true"  useHandCursor="true"  click="closeWin()" source="@Embed(source='/Icons/cancel.png')"/>
    
    </mx:HBox>
    <mx:HBox width="100%" top="36" height="110" textAlign="center" paddingLeft="3" paddingRight="3" horizontalAlign="center">
     <mx:HBox width="100%" top="36" backgroundColor="#F2F2F2"
     height="100%" horizontalAlign="center"  paddingLeft="5" paddingRight="5">
     <mx:Text   color="#333333"  textAlign="left"  htmlText='{_msgContent}' width="100%" height="100%"/>
        </mx:HBox>
    </mx:HBox>
    
    <mx:HBox width="100%" top="150" height="30"  paddingRight="10" verticalAlign="middle" horizontalAlign="right" horizontalGap="0">
        <mx:Button label="查看详细" visible="{_showDetail}"/>
    </mx:HBox>
</mx:Window>

暂无回复

添加回复