Fading Chat Messages [Text Fade AS3]

  • Syxn
  • Born
  • Born
  • Syxn
  • Posts: 1

Post 3+ Months Ago

Hello can someone show me how to make it so when someone types text in game it will fade out? thanks here is the actionscript code.

Code: [ Select ]
package project.hud {
    import flash.display.MovieClip;
    import caurina.transitions.Tweener;
    import flash.geom.Rectangle;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.Bitmap;
    import project.utils.ImageLoader;
    import project.utils.Layout;
    import flash.utils.setTimeout;
    import project.events.HUDEvents;
    import project.events.SoundEvents;
    import flash.events.KeyboardEvent;
    import flash.geom.ColorTransform;
    import scaleform.gfx.*;
    import flash.geom.Point;
    import scaleform.gfx.MouseEventEx;
    
    public class HUD extends MovieClip {
        public var isDebug:Boolean = false;
        
        public var Main:MovieClip = null;

        static public var api:HUD = null;

        public    var    activeChatTab:int = 0;

        public    var        showchat:Boolean = true;
        public    var        showInput:Boolean = true;
        
        /**
         * Chat
         **/
        public    function showChat (showChat:Boolean, showInput:Boolean = true, inputText:String = ""):void
        {
            this.showchat = showChat;
            this.showInput = showInput;
            
            if (!showChat && !showInput)
            {
//                if (Main.Chat.currentLabel != "out")
//                    Main.Chat.gotoAndPlay ("out");
                    
                Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput);
                Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
                Main.stage.focus = null;
            }
            else
            {
                var    chat = Main.Chat;
                var    me = this;
                
                if (showChat)
                    chat.Chat.Plate.visible = true;
                else
                    chat.Chat.Plate.visible = false;
                
//                if (Main.Chat.currentLabel != "start")
//                    Main.Chat.gotoAndPlay ("start");
                    
                if (showInput)
                {
                    chat.Chat.TabPlates.visible = true;
                    if (chat.Chat.Tab1.Active)
                        chat.Chat.Tab1.visible = true;
                    if (chat.Chat.Tab2.Active)
                        chat.Chat.Tab2.visible = true;
                    if (chat.Chat.Tab3.Active)
                        chat.Chat.Tab3.visible = true;
                    if (chat.Chat.Tab4.Active)
                        chat.Chat.Tab4.visible = true;
                    chat.Chat.InputText.visible = true;
                    chat.Chat.InputTextBack.visible = true;

                    Main.Chat.Chat.InputText.addEventListener(KeyboardEvent.KEY_DOWN, keyboardInput)
                }
                else
                {
                    chat.Chat.TabPlates.visible = false;
                    chat.Chat.Tab1.visible = false;
                    chat.Chat.Tab2.visible = false;
                    chat.Chat.Tab3.visible = false;
                    chat.Chat.Tab4.visible = false;
                    chat.Chat.InputText.visible = false;
                    chat.Chat.InputTextBack.visible = false;
                    Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput)
                    Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
                    Main.stage.focus = null;
                }
                
                Main.Chat.Chat.InputText.text = inputText;
            }
        }
        
        /**
         * setChatTab
         *
         * id
         * name
         * active - true / false
         * visible - true / false
         **/
        public    function setChatTab (id:int, name:String, active:Boolean, visible:Boolean):void
        {
            var    tabName = "Tab" + String (id + 1);
            var    tabPlateName = "TabPlates" + String (id + 1);
            var    me = this;
            
            Main.Chat.Chat[tabName].Text.Text.text = name;
            Main.Chat.Chat[tabName].Text.TextShad.text = name;
            Main.Chat.Chat[tabName].Tab = id;
            Main.Chat.Chat[tabName].visible = visible;
            Main.Chat.Chat[tabName].Active = visible;
            
            if (Main.Chat.Chat.TabPlates.currentLabel != tabName)
                Main.Chat.Chat.TabPlates.gotoAndPlay (tabName);

            Main.Chat.Chat[tabName].Active = active;
            
            if (active)
            {
                if (Main.Chat.Chat[tabName].currentLabel != "over")
                    Main.Chat.Chat[tabName].gotoAndPlay ("over");
                    
                activeChatTab = id;
            }
            else
            {
                if (Main.Chat.Chat[tabName].currentLabel != "out")
                    Main.Chat.Chat[tabName].gotoAndPlay ("out");
            }
        }
        
        /**
         * setChatTabActive
         *
         * id
         **/
        public    function setChatTabActive (id:int):void
        {
            if (this.showInput)
            {
                for (var a:int = 0; a < 4; a++)
                {
                    var    tabName = "Tab" + String (a + 1);
                    
                    if (Main.Chat.Chat[tabName].Active)
                        Main.Chat.Chat[tabName].gotoAndPlay("out");
    
                    Main.Chat.Chat[tabName].Active = false;
                }
                
                tabName = "Tab" + String (id + 1);
                Main.Chat.Chat[tabName].gotoAndPlay("over");
                Main.Chat.Chat[tabName].Active = true;
    
                if (Main.Chat.Chat.TabPlates.currentLabel != tabName)
                    Main.Chat.Chat.TabPlates.gotoAndPlay (tabName);
                
                activeChatTab = id;
            }
        }
        
        /**
         * setChatActive
         *
         **/
        public    function setChatActive ():void
        {
            Main.stage.focus = Main.Chat.Chat.InputText;
            Main.Chat.Chat.InputText.addEventListener(Event.ENTER_FRAME, chatInputEnterFrame)
        }
        
        /**
         * setChatActive
         *
         * alpha - 0 - 1.0
         **/
        public    function setChatTransparency (alpha:Number):void
        {
            Main.Chat.Chat.TabPlates.alpha = alpha;
            Main.Chat.Chat.Plate.alpha = alpha
        }
        
        /**
         * receiveChat
         *
         * tab
         * user
         * text
         **/
        public    function receiveChat (text:String):void
        {
            var    chat = new project.hud.ChatTextBlock ();
            var clip = Main.Chat.TextWindows[0];
            
            //TextFieldEx.setNoTranslate(chat.Text, true);
            chat.ChatOutputText.htmlText = text;
            
            var    texHeight = chat.ChatOutputText.height;
            var    height = chat.ChatOutputText.textHeight;
            
            chat.ChatOutputText.height = chat.ChatOutputText.textHeight + 4;
//            chat.TextShad.height = chat.TextShad.textHeight + 4;
            
            clip.addChild(chat);
            clip.Chats.push (chat);
            
            height = 300;
            for (var a:int = clip.Chats.length - 1; a >= 0; a--)
            {
                chat = clip.Chats[a];
                chat.y = height - chat.height;
                
                height -= chat.height;
            }
            
            while (clip.Chats[0] && clip.Chats[0].y + clip.Chats[0].height < 0)
            {
                clip.removeChild(clip.Chats[0]);
                clip.Chats.splice (0, 1);
            }
            
            Main.Chat.TextWindows[0].visible = true;
            Main.Chat.TextWindows[0].mask = Main.Chat.Chat.ChatMasker;//cynthia: 1778
        }

/**********************************************************************
*
* Helper Functions
*
**********************************************************************/
        public function loadSlotIcon(path:String, imageHolder:MovieClip)
        {
            var    dat:Object = {imageHolder:imageHolder};
            var    imageLoader:ImageLoader = new ImageLoader (path, loadSlotCallback, dat)
        }
        
        public    function loadSlotCallback (bitmap:Bitmap, dat:Object)
        {
            bitmap = Layout.stretch (bitmap, 189, 117, bitmap.width, bitmap.height, "uniform");
            bitmap.x = -37;
            bitmap.y = 0;
            
            dat.imageHolder.addChild (bitmap);
        }

        public    function killMsg (msg:Object)
        {
            Main.Msg.removeChild(msg);
        }
        
        public    function startDebugTimer ()
        {
            Main.startDebugTimer ();
        }
        
        public    function keyboardInput(evt:KeyboardEvent):void
        {
            if (evt.keyCode == 13)
            {
// send message                    
                HUDEvents.eventChatMessage(activeChatTab, Main.Chat.Chat.InputText.text);
                Main.Chat.Chat.InputText.text = "";
                Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
                Main.stage.focus = null;
            }
            else if (evt.keyCode == 27)
            {
                HUDEvents.eventChatMessage(-1, "");
                Main.Chat.Chat.InputText.text = "";
                Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
                Main.stage.focus = null;
            }
        };
        
        public function chatInputEnterFrame(evt:Event):void
        {
            if(Main.stage.focus != Main.Chat.Chat.InputText)
            {
                HUDEvents.eventChatMessage(activeChatTab, "");
                Main.Chat.Chat.InputText.text = "";
                Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput);
                
                Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
            }
        }
    }
}
  1. package project.hud {
  2.     import flash.display.MovieClip;
  3.     import caurina.transitions.Tweener;
  4.     import flash.geom.Rectangle;
  5.     import flash.events.Event;
  6.     import flash.events.MouseEvent;
  7.     import flash.display.Bitmap;
  8.     import project.utils.ImageLoader;
  9.     import project.utils.Layout;
  10.     import flash.utils.setTimeout;
  11.     import project.events.HUDEvents;
  12.     import project.events.SoundEvents;
  13.     import flash.events.KeyboardEvent;
  14.     import flash.geom.ColorTransform;
  15.     import scaleform.gfx.*;
  16.     import flash.geom.Point;
  17.     import scaleform.gfx.MouseEventEx;
  18.     
  19.     public class HUD extends MovieClip {
  20.         public var isDebug:Boolean = false;
  21.         
  22.         public var Main:MovieClip = null;
  23.         static public var api:HUD = null;
  24.         public    var    activeChatTab:int = 0;
  25.         public    var        showchat:Boolean = true;
  26.         public    var        showInput:Boolean = true;
  27.         
  28.         /**
  29.          * Chat
  30.          **/
  31.         public    function showChat (showChat:Boolean, showInput:Boolean = true, inputText:String = ""):void
  32.         {
  33.             this.showchat = showChat;
  34.             this.showInput = showInput;
  35.             
  36.             if (!showChat && !showInput)
  37.             {
  38. //                if (Main.Chat.currentLabel != "out")
  39. //                    Main.Chat.gotoAndPlay ("out");
  40.                     
  41.                 Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput);
  42.                 Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
  43.                 Main.stage.focus = null;
  44.             }
  45.             else
  46.             {
  47.                 var    chat = Main.Chat;
  48.                 var    me = this;
  49.                 
  50.                 if (showChat)
  51.                     chat.Chat.Plate.visible = true;
  52.                 else
  53.                     chat.Chat.Plate.visible = false;
  54.                 
  55. //                if (Main.Chat.currentLabel != "start")
  56. //                    Main.Chat.gotoAndPlay ("start");
  57.                     
  58.                 if (showInput)
  59.                 {
  60.                     chat.Chat.TabPlates.visible = true;
  61.                     if (chat.Chat.Tab1.Active)
  62.                         chat.Chat.Tab1.visible = true;
  63.                     if (chat.Chat.Tab2.Active)
  64.                         chat.Chat.Tab2.visible = true;
  65.                     if (chat.Chat.Tab3.Active)
  66.                         chat.Chat.Tab3.visible = true;
  67.                     if (chat.Chat.Tab4.Active)
  68.                         chat.Chat.Tab4.visible = true;
  69.                     chat.Chat.InputText.visible = true;
  70.                     chat.Chat.InputTextBack.visible = true;
  71.                     Main.Chat.Chat.InputText.addEventListener(KeyboardEvent.KEY_DOWN, keyboardInput)
  72.                 }
  73.                 else
  74.                 {
  75.                     chat.Chat.TabPlates.visible = false;
  76.                     chat.Chat.Tab1.visible = false;
  77.                     chat.Chat.Tab2.visible = false;
  78.                     chat.Chat.Tab3.visible = false;
  79.                     chat.Chat.Tab4.visible = false;
  80.                     chat.Chat.InputText.visible = false;
  81.                     chat.Chat.InputTextBack.visible = false;
  82.                     Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput)
  83.                     Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
  84.                     Main.stage.focus = null;
  85.                 }
  86.                 
  87.                 Main.Chat.Chat.InputText.text = inputText;
  88.             }
  89.         }
  90.         
  91.         /**
  92.          * setChatTab
  93.          *
  94.          * id
  95.          * name
  96.          * active - true / false
  97.          * visible - true / false
  98.          **/
  99.         public    function setChatTab (id:int, name:String, active:Boolean, visible:Boolean):void
  100.         {
  101.             var    tabName = "Tab" + String (id + 1);
  102.             var    tabPlateName = "TabPlates" + String (id + 1);
  103.             var    me = this;
  104.             
  105.             Main.Chat.Chat[tabName].Text.Text.text = name;
  106.             Main.Chat.Chat[tabName].Text.TextShad.text = name;
  107.             Main.Chat.Chat[tabName].Tab = id;
  108.             Main.Chat.Chat[tabName].visible = visible;
  109.             Main.Chat.Chat[tabName].Active = visible;
  110.             
  111.             if (Main.Chat.Chat.TabPlates.currentLabel != tabName)
  112.                 Main.Chat.Chat.TabPlates.gotoAndPlay (tabName);
  113.             Main.Chat.Chat[tabName].Active = active;
  114.             
  115.             if (active)
  116.             {
  117.                 if (Main.Chat.Chat[tabName].currentLabel != "over")
  118.                     Main.Chat.Chat[tabName].gotoAndPlay ("over");
  119.                     
  120.                 activeChatTab = id;
  121.             }
  122.             else
  123.             {
  124.                 if (Main.Chat.Chat[tabName].currentLabel != "out")
  125.                     Main.Chat.Chat[tabName].gotoAndPlay ("out");
  126.             }
  127.         }
  128.         
  129.         /**
  130.          * setChatTabActive
  131.          *
  132.          * id
  133.          **/
  134.         public    function setChatTabActive (id:int):void
  135.         {
  136.             if (this.showInput)
  137.             {
  138.                 for (var a:int = 0; a < 4; a++)
  139.                 {
  140.                     var    tabName = "Tab" + String (a + 1);
  141.                     
  142.                     if (Main.Chat.Chat[tabName].Active)
  143.                         Main.Chat.Chat[tabName].gotoAndPlay("out");
  144.     
  145.                     Main.Chat.Chat[tabName].Active = false;
  146.                 }
  147.                 
  148.                 tabName = "Tab" + String (id + 1);
  149.                 Main.Chat.Chat[tabName].gotoAndPlay("over");
  150.                 Main.Chat.Chat[tabName].Active = true;
  151.     
  152.                 if (Main.Chat.Chat.TabPlates.currentLabel != tabName)
  153.                     Main.Chat.Chat.TabPlates.gotoAndPlay (tabName);
  154.                 
  155.                 activeChatTab = id;
  156.             }
  157.         }
  158.         
  159.         /**
  160.          * setChatActive
  161.          *
  162.          **/
  163.         public    function setChatActive ():void
  164.         {
  165.             Main.stage.focus = Main.Chat.Chat.InputText;
  166.             Main.Chat.Chat.InputText.addEventListener(Event.ENTER_FRAME, chatInputEnterFrame)
  167.         }
  168.         
  169.         /**
  170.          * setChatActive
  171.          *
  172.          * alpha - 0 - 1.0
  173.          **/
  174.         public    function setChatTransparency (alpha:Number):void
  175.         {
  176.             Main.Chat.Chat.TabPlates.alpha = alpha;
  177.             Main.Chat.Chat.Plate.alpha = alpha
  178.         }
  179.         
  180.         /**
  181.          * receiveChat
  182.          *
  183.          * tab
  184.          * user
  185.          * text
  186.          **/
  187.         public    function receiveChat (text:String):void
  188.         {
  189.             var    chat = new project.hud.ChatTextBlock ();
  190.             var clip = Main.Chat.TextWindows[0];
  191.             
  192.             //TextFieldEx.setNoTranslate(chat.Text, true);
  193.             chat.ChatOutputText.htmlText = text;
  194.             
  195.             var    texHeight = chat.ChatOutputText.height;
  196.             var    height = chat.ChatOutputText.textHeight;
  197.             
  198.             chat.ChatOutputText.height = chat.ChatOutputText.textHeight + 4;
  199. //            chat.TextShad.height = chat.TextShad.textHeight + 4;
  200.             
  201.             clip.addChild(chat);
  202.             clip.Chats.push (chat);
  203.             
  204.             height = 300;
  205.             for (var a:int = clip.Chats.length - 1; a >= 0; a--)
  206.             {
  207.                 chat = clip.Chats[a];
  208.                 chat.y = height - chat.height;
  209.                 
  210.                 height -= chat.height;
  211.             }
  212.             
  213.             while (clip.Chats[0] && clip.Chats[0].y + clip.Chats[0].height < 0)
  214.             {
  215.                 clip.removeChild(clip.Chats[0]);
  216.                 clip.Chats.splice (0, 1);
  217.             }
  218.             
  219.             Main.Chat.TextWindows[0].visible = true;
  220.             Main.Chat.TextWindows[0].mask = Main.Chat.Chat.ChatMasker;//cynthia: 1778
  221.         }
  222. /**********************************************************************
  223. *
  224. * Helper Functions
  225. *
  226. **********************************************************************/
  227.         public function loadSlotIcon(path:String, imageHolder:MovieClip)
  228.         {
  229.             var    dat:Object = {imageHolder:imageHolder};
  230.             var    imageLoader:ImageLoader = new ImageLoader (path, loadSlotCallback, dat)
  231.         }
  232.         
  233.         public    function loadSlotCallback (bitmap:Bitmap, dat:Object)
  234.         {
  235.             bitmap = Layout.stretch (bitmap, 189, 117, bitmap.width, bitmap.height, "uniform");
  236.             bitmap.x = -37;
  237.             bitmap.y = 0;
  238.             
  239.             dat.imageHolder.addChild (bitmap);
  240.         }
  241.         public    function killMsg (msg:Object)
  242.         {
  243.             Main.Msg.removeChild(msg);
  244.         }
  245.         
  246.         public    function startDebugTimer ()
  247.         {
  248.             Main.startDebugTimer ();
  249.         }
  250.         
  251.         public    function keyboardInput(evt:KeyboardEvent):void
  252.         {
  253.             if (evt.keyCode == 13)
  254.             {
  255. // send message                    
  256.                 HUDEvents.eventChatMessage(activeChatTab, Main.Chat.Chat.InputText.text);
  257.                 Main.Chat.Chat.InputText.text = "";
  258.                 Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
  259.                 Main.stage.focus = null;
  260.             }
  261.             else if (evt.keyCode == 27)
  262.             {
  263.                 HUDEvents.eventChatMessage(-1, "");
  264.                 Main.Chat.Chat.InputText.text = "";
  265.                 Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
  266.                 Main.stage.focus = null;
  267.             }
  268.         };
  269.         
  270.         public function chatInputEnterFrame(evt:Event):void
  271.         {
  272.             if(Main.stage.focus != Main.Chat.Chat.InputText)
  273.             {
  274.                 HUDEvents.eventChatMessage(activeChatTab, "");
  275.                 Main.Chat.Chat.InputText.text = "";
  276.                 Main.Chat.Chat.InputText.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardInput);
  277.                 
  278.                 Main.Chat.Chat.InputText.removeEventListener(Event.ENTER_FRAME, chatInputEnterFrame);
  279.             }
  280.         }
  281.     }
  282. }
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 483

Post 3+ Months Ago

It seem like your trying to make something kinda like this?
Attachments:
chat.jpg

Is this correct?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 4 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.