【问题标题】:Flex 4 - How to remove titleText from TitleBar skin?Flex 4 - 如何从 TitleBar 皮肤中删除 titleText?
【发布时间】:2012-01-22 21:52:23
【问题描述】:

我想从 titleBar 皮肤中删除标题文本,但如果我只是注释掉就会出错。我想这意味着它是必需的皮肤部分?

<!-- title -->
<!--- @copy spark.components.windowClasses.TitleBar#titleText -->
<s:Label id="titleText" minWidth="0" maxDisplayedLines="1" width="100%" />

我尝试将其设置为 text="" 和 text="random text" 但没有效果。如果我在主应用程序中设置一个值,它可以工作,但不适用于空字符串。

现在它显示的应用程序名称大概来自“Main-app.xml”文件。

我怎样才能摆脱它?任何帮助表示赞赏,这真的让我很烦恼......

编辑 1:标题栏皮肤

<!--- The default skin class for the title bar of the Spark WindowedApplication component
      and Spark Window component when you use Flex chrome.  
      The title bar skin includes the close, minimize, and maximize buttons, the 
      title icon, and the title text.

      <p>The Flex chrome is defined by the SparkChromeWindowedApplicationSkin skin class 
      in the spark.skins.spark package. 
      To use the Flex chrome, set <code>systemChrome</code> to "none" in the application's .xml file,
      and set the <code>skinClass</code> style to spark.skins.spark.SparkChromeWindowedApplicationSkin. </p>

      @langversion 3.0
      @playerversion Flash 10
      @playerversion AIR 1.5
      @productversion Flex 4

      @see spark.components.WindowedApplication
      @see spark.components.Window
      @see spark.skins.spark.SparkChromeWindowedApplicationSkin


    This Skin is based on "TitleBar";
-->
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
             xmlns:fb="http://ns.adobe.com/flashbuilder/2009" xmlns:mx="library://ns.adobe.com/flex/mx" 
             minHeight="40" creationComplete="created()" >

    <fx:Metadata>
        [HostComponent("spark.components.windowClasses.TitleBar")]
    </fx:Metadata>

    <fx:Script fb:purpose="styling">


        import mx.core.FlexGlobals;
        import mx.events.StateChangeEvent;

        /* Exclude the titleBar and scroller because they are SparkSkins and we
         * don't want to colorize them twice. */
        static private const exclusions:Array = ["titleBar"];

        override public function get colorizeExclusions():Array
        {
            return exclusions;
        }

        override protected function initializationComplete():void
        {
            useChromeColor = true;
            super.initializationComplete();
        }

        public var ifo:Boolean;

        public function created():void
        {
            this.hostComponent.parentApplication.addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE, buttonToggle);
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            //trace(hostComponent.parentApplication.currentState);
            backgroundRect.radiusX = getStyle("cornerRadius");

            super.updateDisplayList(unscaledWidth, unscaledHeight);
        }

        private function returnButtonHandler(event:MouseEvent):void
        {
            this.hostComponent.parentApplication.currentState = "Home";
        }

        private var lastState:String;

        private function buttonToggle(event:StateChangeEvent):void
        {
            lastState = event.oldState;

            if(event.newState == "Home")
            {
                returnButton.visible = false;
                settingsButton.label = "Settings";
            }
            else if(event.newState == "MoviePage")
            {
                returnButton.visible = true;
                settingsButton.label = "Settings";
            }
            else
            {
                returnButton.visible = false;
                settingsButton.label = "Back";
            }
        }

        private function settingsButtonHandler(event:MouseEvent):void
        {
            if(settingsButton.label == "Settings") // if button label is settings
            {
                hostComponent.parentApplication.currentState = "Settings";
            }
            else // if button label is back
            {
                hostComponent.parentApplication.currentState = lastState; // return to previous state
            }
        }

    </fx:Script>

    <s:states>
        <s:State name="normal" />
        <s:State name="disabled" />
        <s:State name="normalAndMaximized" stateGroups="maximizedGroup" />
        <s:State name="disabledAndMaximized" stateGroups="maximizedGroup" />
    </s:states>

    <!-- fill -->
    <!--- Defines the background color of the title bar. -->
    <s:Rect id="backgroundRect" left="0" right="0" top="0" bottom="0" >
        <s:fill>
            <s:LinearGradient id="bgFill" rotation="90">
                <s:GradientEntry color="0xFFFFFF" />
                <s:GradientEntry color="0xBABABA" />
            </s:LinearGradient>
        </s:fill>
    </s:Rect>

    <!-- title bar content -->
    <s:Group id="titleBar" minHeight="40" width="100%" height="100%" left="3" right="2" >
        <s:layout>
            <s:HorizontalLayout verticalAlign="middle" gap="5" />
        </s:layout>

        <!-- title bar icon -->
        <!--- @copy spark.components.windowClasses.TitleBar#titleIconImage -->
        <s:BitmapImage id="titleIconImage" minWidth="0" fillMode="clip"/>

        <!-- return button -->
        <s:Button id="returnButton" label="Return" click="returnButtonHandler(event)" visible="false" />

        <!-- title -->
        <!--- @copy spark.components.windowClasses.TitleBar#titleText -->
        <s:Label id="titleText" visible="false" includeInLayout="false" minWidth="0" maxDisplayedLines="1" width="100%" /> !!!!!!!! Error if this line is deleted !!!!!!!!!

        <!-- settings / back button -->
        <s:Button id="settingsButton" label="Settings" click="settingsButtonHandler(event)" visible="true" />

        <!-- minimize button -->
        <!--- 
            By default, the button uses the spark.skins.spark.windowChrome.MinimizeButtonSkin class
            to define the skin for the mimimized button.
            @copy spark.components.windowClasses.TitleBar#minimizeButton 
            @see spark.skins.spark.windowChrome.MinimizeButtonSkin 
        -->
        <s:Button id="minimizeButton" verticalCenter="0"
            skinClass="skins.CustomMinimizeButtonSkin" />

        <!-- maximize button -->
        <!--- 
            By default, the button uses the spark.skins.spark.windowChrome.MinimizeButtonSkin class
            to define the skin for the maximized button.
            @copy spark.components.windowClasses.TitleBar#maximizeButton
            @see spark.skins.spark.windowChrome.MaximizeButtonSkin 
        -->
        <s:Button id="maximizeButton" verticalCenter="0"
                  skinClass="skins.CustomMaximizeButtonSkin"
                  skinClass.maximizedGroup="skins.CustomRestoreButtonSkin" />

        <!-- close button -->
        <!---
            By default, the button uses the spark.skins.spark.windowChrome.MinimizeButtonSkin class
            to define the skin for the close button.
            @copy spark.components.windowClasses.TitleBar#closeButton
            @see spark.skins.spark.windowChrome.CloseButtonSkin
        -->
        <s:Button id="closeButton" verticalCenter="0"
            skinClass="skins.CustomCloseButtonSkin" />
        <s:Spacer />

    </s:Group>

</s:SparkSkin>

应用程序皮肤代码片段:

<!-- layer 3: title bar + content -->
    <s:Group left="0" right="0" top="0" bottom="0" minHeight="0" minWidth="0" >
        <s:layout>
            <s:VerticalLayout gap="0"/>
        </s:layout>

        <!-- title bar -->
        <s:TitleBar id="titleBar" width="100%" minHeight="40" skinClass="skins.CustomTitleBarSkin" />

        <!-- content -->
        <s:Group id="contentGroup" width="100%" height="100%" minHeight="0" minWidth="0" />

    </s:Group>

    <!-- layer 4: gripper -->
    <!--- @see spark.skins.spark.windowChrome.GripperSkin -->
    <s:Button id="gripper" right="6" bottom="5" tabEnabled="false" 
              skinClass="spark.skins.spark.windowChrome.GripperSkin" /> 

</s:SparkSkin>

错误:

[SWF] Main.swf - 5,439,008 bytes after decompression
TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at spark.components.windowClasses::TitleBar/commitProperties()[E:\dev\4.y\frameworks\projects\airspark\src\spark\components\windowClasses\TitleBar.as:443]
    at mx.core::UIComponent/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:8219]
    at mx.managers::LayoutManager/validateProperties()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:597]
    at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:783]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1180]

【问题讨论】:

  • 只需将其visibleincludeInLayout 属性设置为false
  • 现在我看了一下:titleText 不是必需的皮肤部件,所以这不是问题。您收到的错误消息是什么。
  • 错误是:“TypeError:错误 #1009:无法访问空对象引用的属性或方法。”它起源于框架文件,而不是我创建的文件。我还检查了,我没有在任何地方引用标签的 ID。如果重要,“TitleBar”在排除列表中。这可能与 hostComponent 有任何关系吗?
  • 你能展示你的整个皮肤吗?还有一个会重现错误的样本?以及完整的错误文本?还要让我们知道您要剥皮的组件;因为我在 SDK 中找不到名为 TitleBar 的 Spark 组件。
  • 添加了代码示例,有标题栏皮肤(您可能想为主应用​​创建“spark.skins.spark.SparkChromeWindowedApplicationSkin”皮肤,然后您将看到带有 skinClass 属性的标题栏)。顺便说一句,我正在使用 v4.6

标签: apache-flex skinning titlebar


【解决方案1】:

我刚刚查看了 TitleBar 类中该行的代码,对我来说它看起来像一个 错误

override protected function commitProperties():void {
    super.commitProperties();

    if (titleChanged) {
        titleText.text = _title;
        titleChanged = false;   
    }

....

如您所见,在尝试设置其text 属性之前,它不会检查titleText 是否存在,即使titleText 不是必需的皮肤部件。

所以我检查了 Adob​​e JIRA 错误数据库。原来这个bug已经提交了,还没有解决:

TitleBar lists titleText as optional, but throws exception when absent

我能想到的最简单的解决方法是将titleText标签留在原处,并将其visibleincludeInLayout属性设置为false

【讨论】:

  • 很高兴知道,至少这不是我的错! visible+includeInLayout 完美运行,可惜 Flex 有这么多错误...感谢您的见解!
  • @user998368 现在 Flex 已经“真正”开源了,至少我们可以自己修复错误。
  • 快速相关的问题,我在 TitleBar Skin 中添加了额外的按钮,但与关闭、最大/恢复、最小化按钮不同,它们响应拖动事件(意味着容器会像你拖动标题栏本身一样移动)。问题我在皮肤的任何地方都看不到拖动事件侦听器的代码吗,请指出正确的方向?
  • 只需在额外按钮触发的 MOUSE_DOWN 事件上调用 event.stopPropagation()。这将阻止 TitleBar 的 mouseDownHandler(它开始拖动)被执行,因为事件将不再冒泡到 TitleBar。
猜你喜欢
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
  • 2011-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-09
相关资源
最近更新 更多