Can I call a class public function from another class? What is the cleanest solution to do that?
for example:
Main -------------------------- Menu
|---------- buttonClicks
-------------------------- Thumbs
开发者_JS百科 |--------- showTheThumbs
a button which is instanced in Menu, run showTheThumbs method, in Thumbs.
use an event
When working with Flex, you accomplish these things by dispatching an event and listening to it from another class.
This way, your classes are loosely coupled and nothing will break when you'll change something.
What it sounds like you want is a Static Method that relates to the Class Thumbs
but not the instance of the class. This is a way they can be accessed [Edited after seeing what Avi wrote, yes this does create coupling :( ]. As long as there are all in the same package, this should work
In Menu
public function buttonClicks(event:MouseEvent):void {
Thumbs.showTheThumbs();
}
In Thumbs
public static function showTheThumbs():voud{
TheDoSomethingFunction();
}
精彩评论