1 Reply Latest reply on Dec 4, 2013 1:50 AM by Craberoid

    Flex Actionscript call parent function

    Yue_Hong Level 1

      I have an actionscript file in my flex project. I loaded the actionscript into flex via addElement()

       

      MXML File:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                        
      xmlns:s="library://ns.adobe.com/flex/spark"
                        
      xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">
      <fx:Script>
          <![CDATA[
              import mx.events.FlexEvent;
              public var sv:Myastest;
              protected function init(event:FlexEvent):void
              {
                  sv = new Myastest();
                  addElement(sv);
                  sv.classfunc();
              }

              public function mainfunc():void
              {
                  trace("mainfunc called");
              }
          ]]>
      </fx:Script>

      </s:WindowedApplication>

       

      ActionScript File:

       

      package
      {
      import flash.events.Event;

      import mx.core.UIComponent;

      [SWF(frameRate="25", backgroundColor="#000000")]
      public class Myastest extends UIComponent
      {

         
      public function Myastest()
         
      {
              trace
      ("loaded..");
              addEventListener
      (Event.ADDED_TO_STAGE, onAddedToStage);
         
      }

         
      private function onAddedToStage(event:Event):void
         
      {
              trace
      ("added to stage");
         
      }

         
      public function classfunc():void
         
      {
              trace
      ("classfunc called");
         
      }

      }
      }

       

      How can I call mainfunc() from the actionscript file? Thank you.