2011年11月30日 星期三

HTML學習三:版本資訊

資料內容皆是W3C釋出文件
2.HTML的版本資訊(HTML version information)
HTML 4.01 specifies three DTDs, so authors must include one of the following
document type declarations in their documents. The DTDs vary in the elements
they support.

DTD(Document Type Definition):文件類型定義,用來檢驗文件上文法是否正確。

DOCTYPE的宣告可以使用以下三種:
  • The HTML 4.01 Strict DTD includes all elements and attributes that have not been deprecated or do not appear in frameset documents. For documents that use this DTD, use this document type declaration:
         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
         "http://www.w3.org/TR/html4/strict.dtd">

         (嚴格模式)
  • The HTML 4.01 Transitional DTD includes everything in the strict DTD plus deprecated elements and attributes (most of which concern visual presentation). For documents that use this DTD, use this document type declaration:
       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
        (寬鬆的,過渡期的,一般皆使用這個宣告,可以有較好的相容性)
  • The HTML 4.01 Frameset DTD includes everything in the transitional DTD plus frames as well. For documents that use this DTD, use this document type declaration:
       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
        "http://www.w3.org/TR/html4/frameset.dtd">
       (使用Frame架構時使用)



The URI in each document type declaration allows user agents to download the
DTD and any entity sets that are
needed. The following (relative) URIs refer to DTDs and entity
sets
for HTML 4:
參考資料
W3C文件
http://www.w3.org/TR/html401/struct/global.html

HTML學習二:HTML結構

本篇資料皆是W3C官方文件的整理
1.HTML結構介紹
(Introduction to the structure of an HTML document)

An HTML 4 document is composed of three parts:

一個HTML4的文件是由以下三個部分所組成
  • 一段宣告HTML版本的訊息,例如:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
一個簡易的HTML Document範例


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD>
     <TITLE>My first HTML document</TITLE>
  </HEAD>
  <BODY>
     <P>Hello world!
  </BODY>
</HTML>


or

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
  <HEAD>
   <TITLE>A simple frameset document</TITLE>
  </HEAD>
 <FRAMESET cols="20%, 80%">
 <FRAMESET rows="100, 200">
  <FRAME src="contents_of_frame1.html">
  <FRAME src="contents_of_frame2.gif">
 </FRAMESET>
 <FRAME src="contents_of_frame3.html">
  <NOFRAMES>
   <P>This frameset document contains:
   <UL>
    <LI><A href="contents_of_frame1.html">Some neat contents</A>
    <LI><IMG src="contents_of_frame2.gif" alt="A neat image">
    <LI><A href="contents_of_frame3.html">Some other neat contents</A>
   </UL>
  </NOFRAMES>
 </FRAMESET>
</HTML>


------------------------------------------
|Frame 1     |Frame 3       |Frame 4       |
|            |              |              |
|            |              |              |
|            |              |              |
|            |              |              |
|            |              |              |
|            |              |              |
|            |              |              |
-------------|              |              |
|Frame 2     |              |              |
|            |              |              |
|            |              |              |
------------------------------------------



資料來源
W3C
http://www.w3.org/TR/html401/struct/global.html

HTML學習一:HTML 簡介

什麼是 World Wide Web (WWW)?
World Wide Web(www)是一個網路上的訊息資源,他主要依賴以下三種機制:
    1.)A uniform naming scheme for locating resources on the Web (e.g., URIs). 
     一個統一的命名方案,用在網路上定位資源所在。(例如 : URIs)

    2.)Protocols, for access to named resources over the Web (e.g., HTTP). 
    協定,網路上用來存取資源的一種溝通方法。(例如:HTTP)

    3.)Hypertext, for easy navigation among resources (e.g., HTML). 
     超本文,用來對各類資源輕易的導覽。

    URI(Universal Resource Identifier)簡介
    Every resource available on the Web -- HTML document, image, video clip, program, etc. -- has an address that may be encoded by a Universal Resource Identifier, or "URI".


    網頁HTML-Document中每個可用資源,image, video clip, program, etc,
    有一個位址他也許是經過編碼的Universal Resource Identifier或稱URI。


    URI是由下列三個項目構成:
    • The naming scheme of the mechanism used to access the resource.
    • The name of the machine hosting the resource.
    • The name of the resource itself, given as a path. 
    example:
    http://www.w3.org/TR
    http是通訊協定,www.w3.org是Server所在的網路位置,/TR 是機器(Server)上的資料路徑。


    <A href="mailto:jt@gmail.com">JT</A>


    片段識別 (Fragment identifiers)

    http://somesite.com/html/top.html#section_2

    #section_2就是一個片段識別。


    What is HTML?
    • HTML stands for Hyper Text Markup Language
    • HTML is not a programming language, it is a markup language
    • A markup language is a set of markup tags
    • HTML uses markup tags to describe web pages

    2011年11月11日 星期五

    Flex4 TIleLayout 在width 100% 下出現的奇怪的row


    <?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:Script>
    <![CDATA[ 
    protected function addItem(event:MouseEvent):void
    { 
    var item:Button = new Button();
    item.label = String(testContainer.numElements);
    item.width = 50;
    item.height = 50;
    testContainer.addElement(item); 
    } 
    
    protected function clearAll(event:MouseEvent):void
    { 
    testContainer.removeAllElements(); 
    }
    
    protected function clearLastItem(event:MouseEvent):void
    {
    if(testContainer.numElements > 0)
    {
    testContainer.removeElementAt(testContainer.numElements - 1); 
    } 
    } 
    ]]>
    </fx:Script>
    <s:controlBarContent>
    <s:Button click="addItem(event)" label="add item"/>
    <s:Button click="clearLastItem(event)" label="clear last "/>
    <s:Button click="clearAll(event)" label="clearAll"/>
    </s:controlBarContent>
    
    
    <s:SkinnableContainer id="testContainer" 
    backgroundColor="0xcccccc" 
    alpha="0.8" 
    width="100%" 
    >
    
    <s:layout> 
    <s:TileLayout id="tileLayout" 
    clipAndEnableScrolling="true" 
    paddingLeft="5"
    paddingRight="5"
    orientation="rows" 
    /> 
    </s:layout> 
    </s:SkinnableContainer> 
    </s:Application>
    


    一個解決的方式是繼承TileLayout並override updateDisplayList 如下:
    override public function updateDisplayList(unscaledWidth:Number , unscaledHeight:Number):void
      {
       super.updateDisplayList(unscaledWidth , unscaledHeight);
       (target as GroupBase).explicitHeight = Math.ceil(rowCount * (rowHeight + verticalGap) - verticalGap);
      }
    
    

    詳細內容請參考:http://forums.adobe.com/thread/565055

    簡單的虛線Components


    這是一個簡單的虛線元件,還未做記憶體管理效率化以及點的大小動態更改處理。
    <?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" xmlns:view="ut.view.*">
     <s:VGroup width="100%" paddingTop="5" paddingLeft="5" paddingRight="5">
      <view:DottedLine width="100%" dotteLineMode="line" color="0x0000FF"/>
      <view:DottedLine width="100%" dotteLineMode="dot" color="0x0000FF"/>
      <view:DottedLine width="100" dotteLineMode="line" color="0xFF0000"/>
      <view:DottedLine width="100" dotteLineMode="dot" color="0xFF0000"/> 
     
      <s:HGroup>
       <view:DottedLine width="100" dotteLineMode="dot" color="0xFF0000" rotation="90"/>
       <view:DottedLine width="100" dotteLineMode="line" color="0xFF0000" rotation="90"/>
       <view:DottedLine width="100" dotteLineMode="line" color="0xFF0000" rotation="90"/>
       <view:DottedLine width="100"  dotteLineMode="dot" color="0xFF0000" rotation="90"/>
      </s:HGroup>
     </s:VGroup>
    </s:Application>
    

    package ut.view
    {
     import flash.display.Bitmap;
     import flash.display.BitmapData;
     import flash.display.DisplayObject;
     import flash.display.Graphics;
     import flash.display.Shape;
     import flash.utils.getTimer;
     
     import mx.graphics.BitmapFillMode;
     
     import spark.primitives.BitmapImage;
     
     import ut.enum.DottedLineMode;
     
     public class DottedLine extends BitmapImage
     {  
      public function DottedLine(color:uint = 0xD4D4D4 , dotteLineMode:String=DottedLineMode.DOT)
      {  
       this.color = color
       this.dotteLineMode = dotteLineMode;
        
      }  
        
      private var _color:uint;
      /**虛線的顏色*/
      public function get color():uint
      {
       return _color;
      }
      public function set color(value:uint):void
      { 
       if(_color != value)
       {
        _color = value;
        changeSource();
       }
      }
      
      
      private var _dotteLineMode:String;
      /**選則點或線的虛線,可由DottedLineMode選擇輸入參數*/ 
      [Inspectable(category="General", enumeration="dot,line", defaultValue="stretch")]
      public function get dotteLineMode():String 
      {
       return  _dotteLineMode;
      }  
      public function set dotteLineMode(dottedLineMode:String):void
      {  
       if(dottedLineMode == DottedLineMode.DOT || dottedLineMode == DottedLineMode.LINE)
       {  
        if(_dotteLineMode != dottedLineMode)
        {
         _dotteLineMode = dottedLineMode; 
         changeSource();
        }
       }
      }  
     
      
      /**bitmapImage所要填入source*/
      private function changeSource():void
      {
       switch(dotteLineMode)
       {
        case DottedLineMode.DOT:
         setSource(createDotDotted);
         break;
        case DottedLineMode.LINE:
         setSource(createLineDotteed);
         break;
        default:
         
       }
      }
      
      /**預設為點狀態的虛線*/
      private function setSource(createMethod:Function):void
      { 
       this.source = null;
       this.source = getBitmap(createMethod(color));
       this.fillMode = BitmapFillMode.REPEAT;
      }  
      
     
      /**將畫好的圖轉換成bitmap  (displayObject to bitmap)*/
      private function getBitmap(target:DisplayObject):Bitmap
      {
       var _bitMapData:BitmapData = new BitmapData(target.width , target.height , true  , 0x000000);
        _bitMapData.draw(target);   
       var _bitMap:Bitmap = new Bitmap(_bitMapData);
       return _bitMap;   
      }
      
      
      /**畫兩個圓依照color,其中一個是看不見,如此bitmap在repeat時方有間隔*/
      protected function createDotDotted(color:uint=0xD4D4D4 ,  ellipseX:Number=0 , ellipseY:Number=0 , ellipseWidth:Number=2 , ellipseHeight:Number=2):DisplayObject
      {   
       var grapgics:Shape = new Shape();
        //first ellipse alpha is 1
        grapgics.graphics.beginFill(color);
        grapgics.graphics.drawEllipse(ellipseX , ellipseY , ellipseWidth , ellipseHeight);     
        //second ellipse alpha is 0 
        grapgics.graphics.beginFill(0xFFFFFF , 0);
        grapgics.graphics.drawEllipse(ellipseX+ellipseWidth , ellipseY , ellipseWidth , ellipseHeight);
        //end fill
        grapgics.graphics.endFill();
       return grapgics;
      }
      
      /**畫兩個線段*/
      protected function createLineDotteed(color:uint=0xD4D4D4 ,  rectX:Number=0 , rectY:Number=0 , rectWidth:Number=3 , rectHeight:Number=1):DisplayObject
      {
       var grapgics:Shape = new Shape();
       //first line
       grapgics.graphics.beginFill(color);
       grapgics.graphics.drawRect(rectX , rectY , rectWidth , rectHeight);   
       //second line
       grapgics.graphics.beginFill(0xFFFFFF , 0);
       grapgics.graphics.drawRect( rectX + rectWidth , rectY , rectWidth , rectHeight);
       //end fill 
       grapgics.graphics.endFill();
       return grapgics; 
      }
     }
    }
    


    package ut.enum
    {
     public class DottedLineMode
     {
      static public const DOT:String =  "dot";
      static public const LINE:String = "line";
      public function DottedLineMode()
      {
      }
     }
    }
    

    Flex4 Rect and Style Metadata


    有時候Layout時只是想用到border或是只想要用到BackgroundColor的時候可以考慮在Group中使用Rect,並加上Style Medatata就可以達到而不用使用到SkinnableContner或是BorderContainer,用法如下。

    <?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"    
          xmlns:itemrenderers="itemrenderers.*"
          >
     <fx:Style source="css/Test.css"/>
     <s:HGroup paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5">  
      <itemrenderers:Rect_Style_BackgroundColor width="200" height="200"/>
      <itemrenderers:Rect_Style_Border width="200" height="200"/>  
     </s:HGroup> 
    </s:Application>
    


    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"
       >
     <fx:Metadata>
      [Style(name="backgroundColors", inherit="no", type="uint" ,  theme="spark")]
     </fx:Metadata>
     <fx:Script>
      <![CDATA[
       import mx.events.FlexEvent;
       
       override public function styleChanged(styleProp:String):void
       {
        super.styleChanged(styleProp);
        if(styleProp == "backgroundColors")
        {
         invalidateDisplayList();
        }
       }
       
       override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
       {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        myBackgroundColor.color = getStyle("backgroundColors");
       }
        
      ]]>
     </fx:Script>
     <s:Rect left="0" right="0" top="0" bottom="0">
      <s:fill>
       <s:SolidColor id="myBackgroundColor" color="0x00ff00"/>
      </s:fill>
     </s:Rect>
    </s:Group>
    


    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"
       width="100%"
       >
     <fx:Metadata>
      [Style(name="borders", inherit="no", type="uint")]
     </fx:Metadata>
     
     <fx:Script>
      <![CDATA[
       import mx.events.FlexEvent;
       
       override public function styleChanged(styleProp:String):void
       {
        super.styleChanged(styleProp);
        if(styleProp == "borders")
        {
         invalidateDisplayList();
        }
       }
       
       override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
       {
        super.updateDisplayList(unscaledWidth, unscaledHeight);
        myBorder.color = getStyle("borders");
       }
       
      ]]>
     </fx:Script> 
     <s:Rect 
       left="0" right="0" top="0" bottom="0"
       radiusX="5" radiusY="5">
      <s:stroke>   
       <s:SolidColorStroke id="myBorder"  weight="2" color="0x00ff00"/>
      </s:stroke>
     </s:Rect> 
    </s:Group>
    


    /* CSS file */
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace mx "library://ns.adobe.com/flex/mx";
    @namespace itemrenderers "itemrenderers.*";
    @namespace spark "spark.skins.spark.*";
    
    
    itemrenderers|Rect_Style_BackgroundColor
    {
     backgroundColors:#f63b5e;
    }
    
    itemrenderers|Rect_Style_Border
    {
     borders:#3e95ef;
    }
    

    SWF在google瀏覽器下無法切換輸入法

    問題:Flash / Flex SWF在google瀏覽器下無法做輸入法切換
    平台: Windows7
    瀏覽器:chrome 15.0.874.106 m

    解決方法:
    1.在chrome網址列中輸入chrome://plugins/打開plugins頁面。
    2.點擊詳細資訊
    3.在flashPlayer項目中將gcswf32.dll項目關閉,留下NPSWF32.dll啟動。
    PS.若你有手動安裝過flashPlayer會有NPSWF32.dll,若沒有到Adobe下載安裝即可。