2

私の目標は、別の状態にある別のコンポーネントからコンポーネントの可視性を変更することです。私はイベントについて読んでいましたが、Flex で動作させることができますTypeError: Error # 1009: Can not access a property or method of a null object reference

<<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.FlexEvent;


        protected function buttonChange_clickHandler(event:MouseEvent):void
        {
            Tab.selectedIndex=1;    
            border.visible=true;
            border.setStyle("backgroundColor",'#8000FF');

        }



    ]]>
</fx:Script>
<mx:TabNavigator x="197.7" y="147.35" width="514" id="Tab" height="335">
    <s:NavigatorContent label="State 1" width="100%" height="100%">

        <s:Button x="65" y="103" id="buttonChange" label="Change state" click="buttonChange_clickHandler(event)" />

    </s:NavigatorContent>
    <s:NavigatorContent label="State2" id="state2"  width="100%" height="100%">
        <s:BorderContainer x="191"  y="37" width="249" height="223" visible="false"  cornerRadius="20" borderWeight="5" id="border">
        </s:BorderContainer>
    </s:NavigatorContent>
</mx:TabNavigator>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

4

1 に答える 1

0

このエラーは、タブナビゲーターがインデックスを変更したときにBorderContainerが「作成」されていないために発生します。これを解決するための2つの高速な方法があります。

1)callLaterを使用して、タブが変更されたときに境界線が作成されるようにします。

        protected function buttonChange_clickHandler(event:MouseEvent):void
        {
            Tab.selectedIndex=1;
            callLater(turnVisible);
        }

        private function turnVisible():void{
                border.visible=true;
                border.setStyle("backgroundColor",'#8000FF');
        }

2)または、creationPolicyを2番目の「all」に設定し</s:NavigatorContent>ます。そうすると、アプリケーションの起動時間が長くなります。

<s:NavigatorContent label="State2" id="state2"  width="100%" height="100%" creationPolicy="all">
于 2012-12-13T19:21:12.347 に答える