2 Replies Latest reply on Jul 5, 2010 10:10 PM by ltambs

    how to pass parameter to function when confirm(Alert.show) closed?

    ltambs Level 1

      <![CDATA[
      import mx.controls.*;
      import mx.events.*;
      private function deleteItem(guid:String):void
      {
      Alert.show("Are sure you want to delete?", "Confirm Delete", Alert.YES|Alert.NO, this, alertClicked);
      }
      private function alertClicked(event:CloseEvent) {

      if(event.detail == Alert.YES) {
        Alert.show("yes "+guid); //<-- here I want to get guid
      }
      else if (event.detail == Alert.NO){
        Alert.show("no ");
        return;
      }
      }
      ]]>

       

      Thanks.

        • 1. Re: how to pass parameter to function when confirm(Alert.show) closed?
          BhaskerChari Level 4

          Hi Itambs,

           

          You can do the following:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="deleteItem('Dummy GUID VALUE')">
          <mx:Script>
            <![CDATA[
             import mx.controls.*;
             import mx.events.*;
             private var myAlert:Alert;
            
             private function deleteItem(guid:String):void
             {
              myAlert = Alert.show("Are sure you want to delete?", "Confirm Delete", Alert.YES|Alert.NO, this, alertClicked);
              myAlert.data = guid;
              myAlert.height = 150;
                          myAlert.width = 300;
             }
             private function alertClicked(event:CloseEvent):void{
            
              if(event.detail == Alert.YES) {
              
                 //Alert.show("yes "+guid); //<-- here I want to get guid
                 Alert.show("yes "+ myAlert.data);
              }
              else if (event.detail == Alert.NO){
                 Alert.show("no ");
                 return;
              }
             }

            ]]>
          </mx:Script>
          </mx:Application>

           

          Note: you can also do this in another way by decalring a global variable guid as ...... private var _guid:String="";

           

          set _guid = guid; in deleteItem() function and then in alertClicked() function you can access the value as _guid again...which holds the saved value...

           


          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari