2012-01-22 26 views
0

我想從titleBar皮膚中刪除標題文本,但如果我只是註釋掉,我會得到一個錯誤。我認爲這意味着它是必需的皮膚部分?Flex 4 - 如何從TitleBar皮膚中刪除titleText?

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

我試着將它設置爲text =「」和text =「random text」,但沒有效果。如果我在Main應用程序中設置了一個值,但它不適用於空字符串。

現在它顯示應用程序名稱大概來自「Main-app.xml」文件。

我該如何擺脫它?感謝任何幫助,這實在是煩我......

編輯1:TitleBar中皮膚

<!--- 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] 
+0

只需將它的'visible'和'includeInLayout'屬性設置爲'false' – RIAstar

+0

現在我看看它:'titleText'不是必需的皮膚部分,所以不能成爲問題。什麼是你收到的錯誤信息。 – RIAstar

+0

錯誤信息:「TypeError:錯誤#1009:無法訪問空對象引用的屬性或方法」。它起源於框架文件,而不是我創建的文件。我也檢查過,並且我沒有在任何地方提及標籤的ID。如果它很重要,「標題欄」在排除列表中。這可能以任何方式與hostComponent相關? – DominicM

回答

0

我只是看看TitleBar類中該行上的代碼,它看起來像一個錯誤給我。

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

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

.... 

正如你所看到的,它不檢查試圖設置其屬性text,即使titleText不是必需skinpart之前是否存在titleText

所以我檢查了Adobe JIRA錯誤數據庫。事實證明這個Bug已經提交併仍然沒有得到解決:

TitleBar lists titleText as optional, but throws exception when absent

最簡單的解決方法,我能想到的是離開titleText標籤它在哪裏,只是設置其visibleincludeInLayout性質到false

+0

很高興知道,至少這不是我的錯!visible + includeInLayout完美工作,這是一個恥辱Flex是如此的錯誤...謝謝你的見解! – DominicM

+0

@ user998368那麼現在Flex已經真正開源了,至少我們可以自己修復這些bug。 – RIAstar

+0

快速相關的問題,我在TitleBar皮膚中添加額外的按鈕,但不像關閉,最大/恢復,最小化他們響應拖動事件的按鈕(意味着容器將像你拖動標題欄時它自己移動一樣)。問題是我看不到爲皮膚中任何位置的拖動事件偵聽器添加代碼,將我指向正確的方向? – DominicM