How do I call a Function inside of a MXML component from a main application?

Posted on 2009-04-30
Last Modified: 2012-05-06
I have a main application and with two custom components. Both components have already been instantiated. Lets call the Components A and B. I am am dispatching an event up from Compenent A and capturning it inthe main application. I want to take the data and pass it into Component B. i am new to flex and am having a hard time exposing functions to do this. Can you help a newbie out?
Question by:20lbMonkey
    LVL 12

    Expert Comment

    Okay.. Assuming we are in the main Application and component 1's id is c1 and component 2's id is c2.

    // Calling c1's public method

    // Calling c2's method assuming c2 lies inside c1

    Remember only public methods can be called from outside. Did this help?
    LVL 37

    Accepted Solution

    >> Lets call the Components A and B.
    That means that you have given the instances of those MXML components these id's:

    <...  id="A"  ... >
    <...  id="B"  ... >

    >> I am dispatching an event up from Compenent A and capturning it in the main application.
    >> I want to take the data and pass it into Component B

    Well, the function in the main application triggered when A dispatches the event will contain:


    This line first calls this getter method that is part of A:

    public function get data():Object {
         return myData;

    and uses the value of it to pass it to the setter method that is part of B:

    public function set data(value:Object) {
        _myDataVariable = value;

    Remark: I used the universal 'Object' as type but it could be whatever you like/need

    Author Closing Comment

    Thanks this is great!
    LVL 37

    Expert Comment

    You're welcome.
    Thanx 4 axxepting
    LVL 12

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now