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

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?
20lbMonkeyAsked:
Who is Participating?
 
zzynxConnect With a Mentor Software engineerCommented:
>> Lets call the Components A and B.
That means that you have given the instances of those MXML components these id's:

<...  id="A"  ... >
and
<...  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:

        B.data = A.data;

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
0
 
lexxwernCommented:
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
c1.methodName()

// Calling c2's method assuming c2 lies inside c1
c1.c2.methodName()

Remember only public methods can be called from outside. Did this help?
0
 
20lbMonkeyAuthor Commented:
Thanks this is great!
0
 
zzynxSoftware engineerCommented:
You're welcome.
Thanx 4 axxepting
0
 
lexxwernCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.