开发者

Call a public function (NOT in the MAIN) from another Class like showTheThumbs

开发者 https://www.devze.com 2023-01-05 11:18 出处:网络
Can I call a class public function from another class? What is the cleanest solution to do that? for example:

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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消