2 Replies Latest reply on Oct 10, 2007 9:16 PM by kwaik

    how to call another custom component FUNCTION

    kwaik
      //---------------------------test.mxml--------------------------------------------------- ------------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
      <ns1:display x="56" y="59" id="comp_display" />
      <ns1:cal x="56" y="384" id="comp_cal" disp="{comp_display}"/>

      </mx:Application>


      //---------------------------display.mxml------------------------------------------------- ------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="60">
      <mx:Script>
      <![CDATA[
      public function func_show(s:String):void{
      text_txt.text=String(s);
      }
      ]]>
      </mx:Script>
      <mx:Text x="77" y="23" id="text_txt" text="Text" width="160"/>
      <mx:Label x="10" y="23" text="result :"/>
      </mx:Canvas>



      //---------------------------cal.mxml----------------------------------------------------- ------------------------------
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="260" height="50">
      <mx:Script>
      <![CDATA[
      public var disp:Canvas;
      function func_click():void{
      disp.func_show(text_txt.text);
      }
      ]]>
      </mx:Script>
      <mx:Button x="178" y="10" label="Button" click="func_click();"/>
      <mx:TextInput x="10" y="10" id="text_txt"/>

      </mx:Canvas>

      ------------------------------------------------------------------------------------------ ----------------------------
      i am beginner of flex, pls help me this question, how to use custom component call another custom component FUNCTION.
      always show this err msg [1061: Call to a possibly undefined method func_show through a reference with static type mx.containers:Canvas]

        • 1. Re: how to call another custom component FUNCTION
          Gregory Lafrance Level 6
          My code below has the following changes:
          1) components in components folder (just my preference)
          2) setter for _disp
          3) cast comp_display to display type

          It works.
          ------------------------------- Test.mxml ------------------------------
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="components.*">
          <ns1:display x="56" y="59" id="comp_display" />
          <ns1:cal x="56" y="384" id="comp_cal" disp="{comp_display}"/>
          </mx:Application>

          ------------------------------- display.mxml ------------------------------
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="60">
          <mx:Script>
          <![CDATA[
          public function func_show(s:String):void{
          text_txt.text=s;
          }
          ]]>
          </mx:Script>
          <mx:Text x="77" y="23" id="text_txt" text="Text" width="160"/>
          <mx:Label x="10" y="23" text="result :"/>
          </mx:Canvas>

          ------------------------------- cal.mxml ------------------------------
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="260" height="50">
          <mx:Script>
          <![CDATA[
          private var _disp:display;

          public function set disp(value:Canvas):void {
          _disp = display(value);
          }

          private function func_click():void{
          _disp.func_show(text_txt.text);
          }
          ]]>
          </mx:Script>
          <mx:Button x="178" y="10" label="Button" click="func_click();"/>
          <mx:TextInput x="10" y="10" id="text_txt"/>
          </mx:Canvas>