You don't have to make the method static; doing so would likely be useless, as you'd want the method call to do something with the component's current state, I'm guessing -- use some of its data, change its appearance, etc. What you really need is an object reference.
Since Application.application resides at the top (or actually very close to the top) of the fabled Display List, you should be able to access each component by starting at that point and then traversing the Display List -- until ultimately, upon arriving at your nested component, calling its publicly defined method.
However, I must say (with the utmost respect!) that you're venturing into dangerous OO waters, here. :) The right way to do this would really be to figure out some way to pass a reference to your custom component to the ActionScript class that requires access to it -- for example, in your MXML:
<mx:Script>
<![CDATA[
private function this_creationComplete(event:Event):void
{
var yourObject:YourClass = new YourClass(yourCustomComponent);
}
]]>
</mx:Script>
<components:YourCustomComponent id="yourCustomComponent" />
... and then in your ActionScript class:
public class YourClass
{
private var componentReference:YourCustomComponent;
public function YourClass(component:YourCustomComponent)
{
this.componentReference = componentReference;
}
private function yourMethod():void
{
this.componentReference.someMethodDefinedInYourComponent();
}
}
An approach like that would probably serve you better. Does it make sense? I'll keep an eye our for comments; post back and I'll do my best to help you through it.
import mx.rpc.AsyncToken;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.mxml.RemoteObject;
var ro:RemoteObject = new RemoteObject();
ro.destination = "Server";
ro.source = "gb.informaticasystems.Server";
ro.addEventListener( FaultEvent.FAULT, handler_backendCommunicationFails );
var query:AsyncToken = ro.executeQuery();
query.addResponder(new Responder( handler_fetchDataRequestSuccess ) );
var data:AsyncToken = ro.getData();
data.addResponder(new Responder( handler_getDataSuccess ) );
Best Answer
There are several ways of achieving this in Flex:
<mx:Script source="yourfile.as" />
You can also use the
includes="yourfile.as"
declaration w/in the Script tag:Application
):AS File:
MXML File:
Use a framework to inject the functionality you are looking for as a type of "model" which contains the data-functionality you will use. It would look something like this in Parsley:
Two frameworks which come to mind which can help w/injection are Mate or Parsley.
I'm not sure if the code-behind pattern works with the main MXML file (which extends Application), so if you're having problems, you might try breaking out the content in your Main MXML file into a separate component which is included in Main. It might look something like this:
Main.mxml:
YourComponent.mxml:
YourComponentCodeBehind.as
From what I've been able to gather from Flex architecture, this is a very common way of setting up your application: your main MXML includes a single "view" which is the entry-point to the rest of your application. This view the contains all other views which comprise the app.
Hope that makes sense :)