解決樣式設定中報錯 必須使用命名空間限定 CSS 選取器“Alert”中的類型“Alert”

來源:互聯網
上載者:User

問題:

使用樣式表(css)。如果在mxml中使用<fx:style>標籤,即<fx:style>標籤必需要mxml文檔根項目的直接子項目。在給Alert設定樣式時報錯:必須使用命名空間限定 CSS 選取器“Alert”中的類型“Alert”。

 

分析:

常用的css選取器有class選取器和type選取器。使用type選取器時需要使用命名空間,文法如下:@namespace s "library://ns.adobe.com/flex/spark"; s|Button{}。

 

解決執行個體:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
 <fx:Declarations>
  <!-- 將非可視元素(例如服務、值對象)放在此處 -->
 </fx:Declarations>
 <!-- 設定應用樣式 -->
 <fx:Style>
  @namespace mx "library://ns.adobe.com/flex/mx"; mx|Alert{
   fontSize: 18pt;
  }
  @namespace s "library://ns.adobe.com/flex/spark"; s|Button{
   fontSize: 18pt;
  }
  @namespace s "library://ns.adobe.com/flex/spark"; s|TextInput{
   fontSize: 18pt;
  }
 </fx:Style>
 <fx:Script>
  <![CDATA[
   //匯入Alert類和關閉事件類別
   import mx.controls.Alert;
   import mx.events.CloseEvent;
   //定義私人函數彈出對話方塊
   private function popAlert():void{
    //修改Alert.YES和Alert.NO的顯示文本
    Alert.yesLabel = "是";
    Alert.noLabel = "否";
    //彈出對話方塊設定顯示標題為“選擇對話方塊”,提示內容為“請選擇'是'或者'否'”,顯示Alert.YES和Alert.NO兩個按鈕
    //設定關閉Alert對話方塊響應的事件,設定預設按鈕為Alert.YES
    Alert.show("請選擇'是'或者'否'","選擇對話方塊",Alert.YES|Alert.NO,this,clickSelectHandler,null,1);
   }
   //定義私人函數響應使用者對Alert對話方塊的操作
   private function clickSelectHandler(event:CloseEvent):void{
    //得到使用者點擊的按鈕
    if (event.detail==Alert.YES)
     //在TextInput組件當中顯示的內容
     displaySelect_txt.text="您選擇了是";
    else
     displaySelect_txt.text="您選擇了否";
   }
  ]]>
 </fx:Script>
 <s:Button id="popAlert_btn" y="87" label="彈出對話方塊" horizontalCenter="0" click="popAlert()"/>
 <s:TextInput id="displaySelect_txt" y="144" horizontalCenter="0"/>
</s:Application>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.