1 Reply Latest reply on Jul 31, 2007 1:53 AM by chris.huston.t10

    Custom component calling function from main.mxml

      I have a main.mxml that has the following function in it:
      public function SubChooseField(evt:Event):void{
      Alert.show( "Sub has been chosen" );

      main.mxml also places the following custom component:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:ComboBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="180" close="parent.SubChooseField(event)">
      <mx:Object data="1" label="choice 1 />
      <mx:Object data="2" label="choice 2" />
      <mx:Object data="3" label="choice 3" />

      I want it so that when you chose one of the options in the comboBox, it will call the function SubChooseField in the main.mxml. But when I compile this, no matter what i try, i get the error:
      Error: Call to a possibly undefined method SubChooseField through a reference with static type my_custom_opponent.
      OR if i change the codeand remove the 'parent' to say: close="SubChooseField(event)"> i get error:
      Error: Call to a possibly undefined method SubChooseField.

      any help much appreciated.

        • 1. Re: Custom component calling function from main.mxml
          chris.huston.t10 Level 3
          Rather than trying to use parent, using events might help here. In your main mxml file, just listen for the change event that is dispatched from your custom component. Since it is a ComboBox component, it automatically dispatches this event. If your component was more complex, you would need to dispatch a custom event.

          If your custom component was named CustomCombo, then the mxml in your main file would look something like this:

          <ns1:CustomCombo id="cb" x="70" y="39" width="160" change="SubChooseField(event)"/>