Flex:如何在主应用程序中调用自定义组件的公共功能?

Lax*_*idi 0 apache-flex function custom-component

如何从主应用程序调用自定义组件的公共功能.例如,我有一个计时器组件MyTimer.

在主应用程序中,我想调用startTimer()或stopTimer().

在主应用程序中,我有:

<visualcomponent:MyTimer />
Run Code Online (Sandbox Code Playgroud)

在组件中,我有:

public function startTimer():void {
     baseTimer = getTimer();
     t.start();
     }
Run Code Online (Sandbox Code Playgroud)

有什么建议?谢谢.

-Laxmidi

Ste*_*fan 5

您需要为组件设置ID,以便可以引用实例:

<visualcomponent:MyTimer id="myTimer" />
Run Code Online (Sandbox Code Playgroud)

现在您可以在主应用程序的脚本代码中说:

myTimer.startTimer();
Run Code Online (Sandbox Code Playgroud)