【问题标题】:How to change the visibility of components from different states in Flex 4如何在 Flex 4 中更改不同状态的组件的可见性
【发布时间】:2012-12-13 18:41:24
【问题描述】:

我的目标是从另一个处于另一个状态的组件中改变一个组件的可见性。我一直在阅读有关该事件的信息,但我可以灵活地工作,我得到了这个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>

【问题讨论】:

    标签: actionscript-3 apache-flex flex4


    【解决方案1】:

    发生错误是因为标签导航器更改索引时未“创建”您的 BorderContainer。有两种快速的方法可以解决这个问题:

    1) 使用callLater保证tab改变时会创建边框:

            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 设置为第二个&lt;/s:NavigatorContent&gt; 的“全部”。这样会增加应用程序的启动时间:

    <s:NavigatorContent label="State2" id="state2"  width="100%" height="100%" creationPolicy="all">
    

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 2011-03-06
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多