7 Replies Latest reply on May 10, 2009 7:51 AM by Starlover_jacob

    alert with checkbox.

    Starlover_jacob Level 1

      Hi there,

       

      I am using an alert window to ask my user if he wants to share stuff with Internet.
      In the alert window there is a yes/no button.
      I know how i can catch the button that's clicked, but now my problem;

       

      In the alert window i want to have a checkbox with the option; save this settings.
      So the user doesn't have to answer this question over and over again.

       

      How do i get an alert window with a checkbox option in it, and how can i see whether that box is checked or not?

       

      Please some help,
      Greets, jacob

        • 1. Re: alert with checkbox.
          Michael Borbor Level 4

          Hi Jacob, yes there is

           

          Alert.show("Test","Test",Alert.YES | Alert.NO);
          
          • 2. Re: alert with checkbox.
            Starlover_jacob Level 1

            Hi there,

            i will add some code i use:

             

            What i want is a checkbox inside the alert window with a yes/no button.

            So i can let my users check it and the setting is getting saved.

             

            code i know/use.

            -------------------------------

            Alert.yesLabel="yes i want";
            Alert.noLabel="No i don't";               
            var myAlert2:Alert= Alert.show("Do you want to share your data with other users? \n\n All data will be saved on the web."
                                    ,'', Alert.NO | Alert.YES,null,function (event:Object):void
                                    {
                                        if( event.detail == 1)//yes button is clicked
                                        {
                                        // go and save all info at internet
                                        goshare();
                                        }

             

                                    });
            // Set the height and width of the Alert control.
            myAlert2.height=170;
            myAlert2.width=350;

            ------------------------------------

             

            Greets, jacob

            • 3. Re: alert with checkbox.
              Michael Borbor Level 4

              Oh I see Jacob, I think that in that case what you need to do is create a custom component that isn't very complicated, a TitleWindow, a Label and the CheckBox.

              • 4. Re: alert with checkbox.
                Starlover_jacob Level 1

                Hi,

                You mean i need to create my own popup?

                (like this example? http://www.aboutflex.net/flex/customalert/ )

                Or could i give my custom component to the alert function?

                 

                And when i create mypopup, where would i have my button handling?

                I prefer to have the button and checkbox handling at the place where i call the popup, so the save settings code is all at the same place.. (makes it easyer to understand)

                (like in the code i now use i call the function at the same place i show the alert)

                 

                Greets, J.

                • 5. Re: alert with checkbox.
                  Michael Borbor Level 4

                  Yes a custom component that you display using a PopUp, if you give the CheckBox and the Button an id, you could create the event listeners inside the the application displaying the PopUp. And yes something like that, that's a pretty example, but that complexity isn't necessary in your case.

                  • 6. Re: alert with checkbox.
                    Starlover_jacob Level 1

                    Thanx for helping me out!

                    I used a simple popup to create my own alert window.

                    Here my code:

                     

                    alert_with_checkbox.mxml

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:localcanvas="*">
                    <mx:Script>
                         <![CDATA[
                              import mx.core.Application;
                              import mx.managers.PopUpManager;
                              
                              
                              public var pop2:question;
                              public function showpop():void
                              {
                                   pop2=new question();
                                   pop2 = question(PopUpManager.createPopUp(Application.application as Sprite,question,true));
                                   PopUpManager.centerPopUp(pop2);     
                                   pop2.settingno.addEventListener(MouseEvent.CLICK,function (e:MouseEvent):void
                                   {
                                        //no is clicked
                                        PopUpManager.removePopUp(pop2);
                                        if(pop2.savesharecheck.selected==true)
                                        {
                                             //call to savesettings function here and save the no option.
                                        }
                                        
                                   });
                                   pop2.settingyes.addEventListener(MouseEvent.CLICK,function(e:MouseEvent):void
                                   {
                                        //yes is clicked
                                        PopUpManager.removePopUp(pop2);
                                        if(pop2.savesharecheck.selected==true)
                                        {
                                             //call to savesettings function here and save the yes option.
                                        }
                                   });     
                              }     
                         ]]>
                    </mx:Script>
                    <mx:Button id="mybutton" label="Ask me!" click="{showpop()}"/>     
                    </mx:WindowedApplication>
                    

                     

                    question.mxml

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" 
                         width="324" 
                         height="214" 
                         styleName="titlewindow" 
                         horizontalScrollPolicy="off" 
                         verticalScrollPolicy="off">
                    <mx:Style>
                    .titlewindow
                    {
                         color : #0f3177;
                         title-style-name : alertTitle;
                         header-height:19;
                         border-thickness: 1;
                         drop-shadow-enabled: true;
                         drop-shadow-color :#d1ddf7;
                         background-color: #ffffff;
                         corner-radius :6;
                         border-style :solid;
                         header-colors : #90a4d1, #0202a1;
                         footer-colors : #9db6d9, #ffffff;
                         border-color : #5970a0;
                         padding-top: 30;
                         padding-bottom: 10;
                         padding-left:-5;
                         }
                    .alertTitle
                    {
                         font-family :Verdana;
                         font-size :10;
                         font-weight :bold;
                         text-align :left;
                         color :#ffffff;
                    }     
                    </mx:Style>
                    <mx:Canvas horizontalScrollPolicy="off" verticalScrollPolicy="off" width="311" height="77">
                         <mx:Text text="Do you want to share this data with other users? &#xa;&#xa; All data will be saved at a central place." width="100%" textAlign="center" />
                    </mx:Canvas>
                    <mx:Canvas width="311">
                    <mx:CheckBox id="savesharecheck" label="Save this setting." textAlign="center" width="303"/>
                    </mx:Canvas>
                    <mx:HBox width="311" horizontalAlign="center">
                    <mx:Button id="settingyes" label="Yes" width="74"/>
                    <mx:Button id="settingno" label="No" width="74"/>
                    </mx:HBox>
                    </mx:TitleWindow>
                    

                     

                    Greets, Jacob

                    • 7. Re: alert with checkbox.
                      Michael Borbor Level 4

                      You're welcome Jacob, don't forget to close the thread.