1 Reply Latest reply on Jul 22, 2009 7:27 AM by Louder6Pounder

    Event dispatch problem

    Louder6Pounder Level 1



      I have two classes, one which dispatches an event and one which listens to it.  This has been working fine.  However now what i want to do is when a radio button is clicked i want it do pass the value to a property of the class and of dispatch an event that its been changed.  The listener class then picks this up and gets the new value form the first classes property.


      However.  For some unkown reason the class with the listener in it seems to run the listener function before the dispatch has been made.


      Here are my two classes.


      Class which dispatches an event:



           private function boolHandler(event:Event):void{
                     var radioGroup:RadioButtonGroup = event.target as RadioButtonGroup;
                     currentFieldValueBool = event.currentTarget.selectedValue;
                     Alert.show("prop" + event.currentTarget.selectedValue);     
                     currentField = radioGroup.selection.id;
                     dispatchEvent(new Event("fieldChange"));
                //  Creates a boolean input instance
                public function addRequired(label:String, type:String, value:Boolean):void{          
                     var newFormItem:FormItem = new FormItem();
                     var newRadioRequiredTrue:RadioButton = new RadioButton();
                     var newRadioRequiredFalse:RadioButton = new RadioButton();
                     var newRadioRequiredGroup:RadioButtonGroup = new RadioButtonGroup();
                     newFormItem.label = label;
                     //  Radio group     
                     newRadioRequiredGroup.addEventListener(Event.CHANGE, boolHandler);                         
                     newRadioRequiredTrue.id = type;
                     newRadioRequiredFalse.id = type; 
                     newRadioRequiredTrue.label = 'True';
                     newRadioRequiredFalse.label = 'False';
                     newRadioRequiredFalse.group = newRadioRequiredGroup;
                     newRadioRequiredTrue.group = newRadioRequiredGroup;
                     //  Set the radio button
                     if(value == true){
                          newRadioRequiredTrue.selected = true;
                          newRadioRequiredFalse.selected = true;
                     //  Add new components



      Classes which has listener:



      //  Set up propertyinstance
                public function setupProperties(propertyInstance:PropertiesForm):void{
                     propertyDescriptionInstance = propertyInstance;
                     propertyDescriptionInstance.addEventListener("fieldChange", newFormItemAddedHandler);
                     propertyDescriptionInstance.addText('Label','label', label);
                     propertyDescriptionInstance.addRequired('Required', 'required', required);               
                //  When property is changed event is fired that the propertyInstance properties have
                //  been updated.  Check which type they are relevant to with regards to the properies 
                //  within this class and update accordignly
                private function newFormItemAddedHandler(event:Event):void{
                     //  If the label has been updated
                     if(propertyDescriptionInstance.currentField == 'label'){
                          label = propertyDescriptionInstance.currentFieldValueString;
                     //  If the required is updated
                     }else if(propertyDescriptionInstance.currentField == 'required'){
                          required = propertyDescriptionInstance.currentFieldValueBool;
        • 1. Re: Event dispatch problem
          Louder6Pounder Level 1

          I've found out my own answer again.  It was a simple one.  It was because i was using the label to set the bool and being accustomed to php coding i forgot that in a language such as flex if you give bool a string its always true.  So i had to set the value of the radios basically. 


          It was nothing to do with events.