0

Flexの初心者である私は、アプリケーションの「firstView」であるビューで宣言されたパブリックメソッドを呼び出す方法を見つけようとしています。参照を取得するにはどうすればよいですか?

メインビュー

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160"  firstView="views.loaderView" creationComplete="init()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            private function init():void{
                //how do I access this method?
                        loaderView.setLoaderMsg("My Message");
            }
        ]]>
    </fx:Script>
</s:ViewNavigatorApplication>

ローダービュー

    <fx:Declarations>
        <s:RadioButtonGroup id="rg"/>
    </fx:Declarations>

    <s:layout>
        <s:VerticalLayout paddingTop="10" paddingBottom="15" paddingLeft="15" paddingRight="15" gap="15" 
                          horizontalAlign="center" verticalAlign="middle"/>
    </s:layout>
    <s:BusyIndicator/>  
    <s:Label id="loaderMsg" text="Loading..." />

</s:View>
4

2 に答える 2

3

デフォルトでは、MXMLで定義されたすべての子はパブリック名前空間にあるため、ドット表記を使用して簡単にアクセスできます。これは、Flexの最初のステップの最も簡単な方法です。

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                            xmlns:s="library://ns.adobe.com/flex/spark" 
                            applicationDPI="160"
                            firstView="views.loaderView"
                            creationComplete="init()">
  <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
  </fx:Declarations>
  <fx:Script>
    <![CDATA[
      private function init():void{
        trace(navigator.activeView);
        // const first:loaderView = navigator.activeView as loaderViewM
        // first.loaderMsg.text = "My Message";
      }
    ]]>
  </fx:Script>
</s:ViewNavigatorApplication>
于 2012-06-10T12:50:52.950 に答える
1

FlexGlobals.topLevelApplication.myPublicFunctionを使用します

于 2012-06-10T14:44:03.817 に答える