Skip navigation
Currently Being Moderated

Flex Actionscript call parent function

Nov 28, 2013 6:49 AM

Tags: #flex #actionscript_3.0

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.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points