The problem I see is that you never tell the label to be visible after
you hide it.  Once it disappears, it never comes back.

You also might want to assign the setTimeout call to a variable, so
you can clear your setTimeout method in the case you need to cancel it.

Here is your code, modified with a set delay of 500ms, and a variable
to clear your timeout, as well as a way to see your label after you
make a change.

Hope it helps!


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical" verticalAlign="middle"> 

        <mx:Script>
                <![CDATA[
                        import mx.controls.Alert;
                        private var alert:Alert;
                        
                        private var delay:Number = 500;
                        
                        // variable to reference setTimeout call so you can 
cancel it later
                        private var myTimeout:uint;
                        
                        private function showAndHide(delay:Number):void
                        {                
                                lbl.text="Clickedon Button ONE";
                                // make label visible, if it was hidden.
                                lbl.setVisible(true);
                                // clear the timeout, in the case you had one 
going
                                clearTimeout(myTimeout);
                                // after reseting it, call again to maintain 
proper timing
                                myTimeout = setTimeout(hideAlert, delay);
                        }
                        
                        private function hideAlert():void
                        {
                                lbl.setVisible(false);
                        }
                        
                        private function showAndHideC(delay:Number):void
                        {
                                lbl.text= "Clicked Button TWO" + (delay / 1000) 
;
                                lbl.setVisible(true);
                                clearTimeout(myTimeout);
                                myTimeout = setTimeout(hideAlert, delay);
                        }
                ]]>
        </mx:Script>

        <mx:VBox width="402" height="208">
                <mx:Button label="Launch alert" width="178"
click="showAndHide(3000);" />
                <mx:Button label="Stop Server" width="177"
click="showAndHideC(3000);" />       
                <mx:Label id="lbl" width="174" />
        </mx:VBox>
        
</mx:Application>

--- In [email protected], "Tom Preet" <[EMAIL PROTECTED]> wrote:
>
> Hi All,
> 
> In my am using two buttons when I clicked on button one it will
display the
> some text on another, it will display only for 3 seconds. same will
repeat
> when I clicked on another button. but this was happening for only
one time
> again I need to refresh the page.
> 
> I need to display the label names by clicking on continuously with out
> refreshing the page.
> 
> here am pasting my piece of code:
> 
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical"
>         verticalAlign="middle"
> >
> 
>    <mx:Script>
>         <![CDATA[
>             import mx.controls.Alert;
>             private var alert:Alert;
> 
>            private function showAndHide(delay;Number):void {
>                 lbl.text="Clickedon Button ONE";
>                   setTimeout(hideAlert, delay);
>             }
> 
>             private function hideAlert():void {
>                             lbl.setVisible(false);
>             }
>             private function showAndHideC(delay:Number):void {
> 
>                 lbl.text= "Clicked Button TWO" + (delay / 1000) ;
>                   setTimeout(hideAlert, delay);
>             }
>         ]]>
>     </mx:Script>
> 
>     <mx:VBox width="402" height="208">
>         <mx:Button label="Launch alert" width="178"
>                 click="showAndHide(3000);"  />
>         <mx:Button label="Stop Server" width="177"
>                 click="showAndHideC(3000);"  />
>         <mx:Label id="lbl" width="174"       />
>    </mx:VBox> </mx:Application>
> ==================================
> 
> can anyone heplp me how to achieve this.
> 
> 
> 
> Thanks in Advance,
> 
> Tomt.
>


Reply via email to