?
Solved

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

Posted on 2009-04-30
5
Medium Priority
?
622 Views
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?
0
Comment
Question by:20lbMonkey
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:lexxwern
ID: 24276690
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
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 24285767
>> 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
 

Author Closing Comment

by:20lbMonkey
ID: 31576678
Thanks this is great!
0
 
LVL 37

Expert Comment

by:zzynx
ID: 24292894
You're welcome.
Thanx 4 axxepting
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 24292936
:)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Social messanging services like WhatsApp and Facebook can help businesses in ways that many owners don't even imagine, giving new opportunities to connect with customers. Discover some of the most innovative things they can do for your company.
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

862 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