"happybrowndog" <webforumsuser@macromedia.com> wrote in message
news:gctmql$4t5$1@forums.macromedia.com...
> That's goddamned ridiculous. What were Flex developers thinking that you
> have
> to write a custom event to call back to a parent component?? Other GUI
> libraries such as WxWidgets, Fox, Qt, Delphi, MFC, WinForms, etc., all
> allow
> you to either call via a reference to the parent object or submit a
> callback
> function into the child object. That's just basic OO programming. Flex
> is
> looking more and more ridiculous and more like Swing - tons of unnecessary
> coding to do simple things.
You absolutely _do_ have the capability to pass in a reference to the parent
component, or to create a "hard" reference to Application.application. But
these are not recommended practices, because anything you create this way is
then tied to an environment that implements those properties and methods.
Q (3): I want to run a function in my main application from inside my
custom component. But when I try to refer to myFunction() in that
component, I get a compile time error Call to a possibly undefined function
myFunction. How can I fix this?
A: Your component has its own scope, so it doesn't know anything
about the functions in the main file. You can get around this by directly
referencing the main application scope like this:
Application.application.myFunction(). However, this makes your component
tightly coupled, which is a quick way of saying that your component is only
usable in an application that has a myFunction() function in it. You're
better off dispatching an event from your component and letting the
application decide how to handle it. For more information, check out the
following resources:
http://www.adobe.com/devnet/flex/art..._coupling.html
http://www.adobe.com/devnet/flex/art...ating_pt1.html
From
http://www.magnoliamultimedia.com/fl...s_Flex_FAQ.pdf