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下載安裝即可。