We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


How to access components from inside class methods

spiritwithin asked
Medium Priority
Last Modified: 2013-11-11
Hi folks,

i think this is pretty straightfoward & easy ..

I am learning to use ADOBE FLEX and i am having trouble finding out about (or just understanding) the correct way to access MXML-defined components from inside a class i created, that is part of a package (which i also created). Naturally i tried using the ID of the component to refer to it. I guess its the wrong approach and it does not even work (see code).

Now, if i, for example, have a very basic TextArea in my MXML file, and i want to access this component from within any other class, what is the correct way to accomplish this?

Best regards!
// the error i get when trying to use the component through its ID
1120: Access of undefined property infoDisplay

Open in new window

Watch Question


After obtrusively seeking out the solution on the net, i ended up with using "Application.application" and calling the component through that.


Application.application.myTextBoxID.text = "test";

This seems weird but if there is nobody coming up with another (and actually "better") solution, i'd assume that i found the correct answer myself. I'll wait 24 hours before requesting to close this question.

It is wierd.  That way works but you are meant to use events to pass information around.

This is the initial problem that comes up when starting with Flex.  Effectively what you are doingis accessing Applicaiton as a global variable.  Have you considered looking at one of the Flex frameworks?
zzynxSr. Software engineer

>> Application.application.myTextBoxID.text = "test";
That one works because "myTextBoxID" is defined in your main mxml. But it wouldn't work if it was in one of your other mxml files.

I agree with Jones911 that events are the way to go.

Instead of making your sub class change the main app's text area, you should let your main app listen to the sub class throwing a custom event.
When the sub class throws the custom event, your main app is triggered and can then change the content of its text area.

Have a read about Using Events in Flex: http://livedocs.adobe.com/flex/3/html/help.html?content=events_01.html


Thank you,

basically i must say that until now i did not know there was a way to import MXML files using the "import" directive.

Aside from that however, i can not agree that events triggered from components are the way to go, because for example with a loose timer i will never have an event of a specific component that triggers a specific method. Hence i can not rely on using events.

You can write your own custom events.  Trust us events are the way to pass messages between components.

Its possible and does make sense to pass messages without events in many circumstances so perhaps show some code and we can better understand your need.
zzynxSr. Software engineer

>> i will never have an event of a specific component that triggers a specific method
I wouldn't know why not.
At least, I already programmed such behaviour...


My statement looses every consistence of course, given without its context. But when i am relying entirely on timers that run absolutely independetly from any components, i have no components to call events from.
zzynxSr. Software engineer

>> when i am relying entirely on timers that run absolutely independetly from any components, i have no components to call events from.
Sorry, I don't understand what you're trying to say
I mean that if i am using a Timer that frequently calls a method of a class which then wants to deal with one of the components in my application, i have no event of any of those components, which i could use to trigger a / this method. Thus i end up with a method that is triggered by a timer but both have no practical connection to any component.

Anyway, given the fact that i can "import" MXML declarations/definitions into any package, the ID of the components contained becomes available in that scope. This is what i was looking for, and it is a better way to deal with the issue, instead of using Application.application to refer to the component.

I am thankful for tries to help me, and appreciate the people's efforts.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.