顯示包含「flex」標籤的文章。顯示所有文章
顯示包含「flex」標籤的文章。顯示所有文章

Flex 4 ~ disable Horizontal scroll bar

<s:Scroller  x="355" y="150"  width="600" height="440" horizontalScrollPolicy="off" >

</s:Scroller>


reference
http://stackoverflow.com/questions/204698/how-can-i-disable-horizontal-scrollbars-in-flex-components

Flex 4 ~ enable Group scroll

<s:Scroller  x="355" y="150"  width="600" height="440" horizontalScrollPolicy="off" >
<s:Group  id="ContentWrapper"   >
</s:Group>
</s:Scroller>

reference
http://help.adobe.com/en_US/flex/using/WS03d33b8076db57b9466e6a52123e854e5d5-8000.html

Flex 4 ~ overflow hide

這是在flex 4裡做到類似CSS的 overflow:hidden


<s:Group id="imageCav" x="0" y="30" width="300" height="200" clipAndEnableScrolling="true" >
<mx:Image id="PreviewImage" x="0" y="0" />
</s:Group>



reference
http://forums.adobe.com/message/2905424

Flex 4 ~ animate scale effect

MXML
--------------------------------------------------------------------------------------------------------------------------

<fx:Declarations>
<s:Scale id="scaleEffect" target="{PreviewImage}" duration="200" />
</fx:Declarations>

<mx:Image id="PreviewImage" x="0" y="0"  />



Action Script
--------------------------------------------------------------------------------------------------------------------------
private function zoomInImage():void{

scaleEffect.scaleXTo = PreviewImage.scaleX + 0.15;
scaleEffect.scaleYTo = PreviewImage.scaleY + 0.15;
scaleEffect.end();
scaleEffect.play();
}



reference
http://help.adobe.com/en_US/flex/using/WS6461B3EC-1AED-486d-A4B8-8EBD1993CE22.html

Flex 4 ~ save Group, Canvas content as image and download

MXML
--------------------------------------------------------------------------------------------------
<s:Group id="imageCav" x="0" y="30" width="300" height="200" clipAndEnableScrolling="true" >
<mx:Image id="PreviewImage" x="0" y="0" />
</s:Group>

<s:Button label="save Image" click="saveImage()" x="50" y="300">




Action Script
--------------------------------------------------------------------------------------------------

private function saveImage():void{
var bd:BitmapData = new BitmapData(imageCav.width,imageCav.height);
bd.draw(imageCav);
var ba:ByteArray = (new PNGEncoder()).encode(bd);
(new FileReference()).save(ba, "cool.png");
}




reference
http://www.jamesward.com/2009/04/16/flex-paint-2/

http://www.jamesward.com/demos/FlexPaint2/srcview/index.html

Flex 4 ~ upload image file and set image width, height

MXML
--------------------------------------------------------------------------------------------------------
<mx:Button label="Browse" click="Image_Browse();" />
<mx:Image id="PreviewImage" x="0" y="0" />
--------------------------------------------------------------------------------------------------------




Action Script
--------------------------------------------------------------------------------------------------------
private var ImageTypes:FileFilter = new FileFilter("Image (*.png, *.jpg, *.gif)", "*.png; *.jpg; *.gif");
private var UploadFilter:Array = new Array(ImageTypes);
private var FileRef:FileReference = new FileReference();

private function Image_Browse() : void {
FileRef.addEventListener(Event.SELECT, Image_Select);
FileRef.addEventListener(Event.COMPLETE, PreviewImageHandler);
FileRef.browse(UploadFilter);
}

private function Image_Select(e:Event) : void {
FileRef.load();
}

private function PreviewImageHandler(e:Event) : void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
loader.loadBytes(FileRef.data);
PreviewImage.source = FileRef.data;
}

//set image width, height
public function loader_complete (event:Event) : void {
var sourceBMP:Bitmap = event.currentTarget.loader.content as Bitmap;
PreviewImage.width = sourceBMP.width;
PreviewImage.height = sourceBMP.height;
}


--------------------------------------------------------------------------------------------------------

reference
http://stackoverflow.com/questions/3439532/flex-4-filereference-selected-image-file-dimmensions-width-and-height

Flex 4 , Flash Builder 4 ~ auto import static classes

在Flex 3

如果要用Alert

只要打Aler在Alt + /

他就會自動import

import mx.controls.Alert;


可是在Flex 4 (Flash Builder 4)

要打new Alert案enter........

改成這樣說真的比較麻煩說= =


reference
http://stackoverflow.com/questions/3906706/flash-builder-4-auto-import-not-working

Flex 4 ~ align center

<s:Group horizontalCenter="0" verticalCenter="0"> 
<s:layout>     
<s:HorizontalLayout/> 
</s:layout> 
<s:Button />   
<s:Button />
<s:Button />
</s:Group>


reference
http://stackoverflow.com/questions/1779479/centering-content-in-flex-4

Flex ~ sort DataGrid date column

這問題是當要排序日期的時候發生用字串排序的問題

所以要用sortCompareFunction去把字串轉Date物件再來做比較~


MXML
<mx:DataGridColumn width="120" headerText="Submit Time" wordWrap="true" sortable="true" textAlign="left" dataField="SubmitTime" sortCompareFunction="sortDate">
</mx:DataGridColumn>


Action Script
(SubmitTime is one of dataProvider's field)

private function sortDate(obj1:Object, obj2:Object):int {
var dateA:Date = new Date(Date.parse(obj1.SubmitTime));
var dateB:Date = new Date(Date.parse(obj2.SubmitTime));
return ObjectUtil.dateCompare(dateA, dateB);
}



reference
http://blog.flexexamples.com/2007/08/12/sorting-date-columns-in-a-datagrid/

Flex ~ submit form by return key ~enter key

Action Script
filterForm.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent):void{
if(e.charCode == 13){
//do something
}
});


MXML
<mx:Form id="filterForm">
</mx:Form>

reference
http://cookbooks.adobe.com/post_Submit_form_with_enter_key-12752.html

Flex ~DateField get date value format YYYY-MM-DD

MXML
<mx:DateField id="toDate" formatString="YYYY-MM-DD" />


Action Script
trace(toDate.text);


output
2010-12-28

Flex ~ FileReference can't download, FileReference download problem

如果是把FileReference宣告在function裡就會無法下載

要宣告在全域變數..........

---------------------------------------------------------------------------------
private var file:FileReference = new FileReference();
private function DoDownload(e:MouseEvent):void{

var url:String = _downloadAddress + "?R=";

var ran:Number = Math.random();
var req:URLRequest = new URLRequest(url + ran);

file.addEventListener(ProgressEvent.PROGRESS, StartDownload);
file.addEventListener(Event.COMPLETE, FileCompleteEvent);
file.download(req);

}
---------------------------------------------------------------------------------

如果寫在裡面 ~~~~~就會跟我一樣~~~~~ 一下載就整個卡住不會動~~~~

private function DoDownload(e:MouseEvent):void{

private var file:FileReference = new FileReference();

blablablablablablablablablablablablablablablablablabla
}


這問題鳥爆了..........害我弄超久............


reference:
http://www.learnosity.com/techblog/index.cfm/2007/7/16/Filereference-download-problem--solved

Flex ~ send http request ~ HTTPService

傳url後面要帶亂數GET參數

不然他不會重新request~~~~會取cache~XD

public function sentBehavior(i:int):void
{
var myHttp:HTTPService;
myHttp = new HTTPService();
myHttp.url = 'http://localhost:1234/test3.php?o=' + Math.random().toString();
myHttp.addEventListener(ResultEvent.RESULT, qqq);
myHttp.send();
}

public function qqq(event:ResultEvent):void
{
trace(event.result);
}

http://blog.riaproject.com/flex/82.html

Flex ~ get List control allowMultipleSelection="true" values

Action Script
var xx:XML = <root><node label="GGYY" TypeID="3"></node><node label="YYGG" TypeID="4"></node></root>
copyToSiteList.dataProvider = xx.node;

for(var i:int=0; i < copyToSiteList.selectedItems.length; i++)
{
trace(copyToSiteList.selectedItems[i].@TypeID);
}


MXML
<mx:List allowMultipleSelection="true" id="copyToSiteList" labelField="@label" >
</mx:List>

Flex ~ ComboBox length, set selectedIndex example

this is a example if combobox item's SkuID == p.mainSkuID

then set index


Action Script
for(var i:int =0; i < MainSkuID.dataProvider.length; i++){
if(MainSkuID.dataProvider[i].@SkuID == p.mainSkuID)
{
MainSkuID.selectedIndex = i;
}
}

MXML
<mx:ComboBox labelField="Label" id="MainSkuID" >
</mx:ComboBox>


http://flex.sys-con.com/node/312098

Flex ~ assing item for List control by XML

Action Script
var xx:XML = <root><node label="GGYY"></node><node label="GGYY22222"></node><node label="Parts Sto123re"></node></root>

copyToSiteList.dataProvider = xx.node;


MXMXL
<mx:List allowMultipleSelection="true" id="copyToSiteList" labelField="@label" >
</mx:List>

http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_2.html

Flex ~ TabNavigator

Action Script
private function indexChangeHandler(event:IndexChangedEvent):void {
switch(priceTab.selectedIndex)
{
case 0:
trace('click tab 1');
break;
case 1:
trace('click tab 2');
break;
}
}

MXML
<mx:TabNavigator id="priceTab" change="indexChangeHandler(event)">
</mx:TabNavigator>

http://icediv.javaeye.com/blog/352000

Flex ~ xml

XML
<root Label="aaaaaaaaa" Icon="Root">
<Option >
<Unit UnitID="2651" Label="xxxx">
<Sku SkuID="3490" Label="aaaaaaa" />
</Unit>
</Option>
</root>

Action Script
MainSkuID.labelField = '@Label';
MainSkuID.dataProvider = xml.Option.Unit.(@UnitID==2651).Sku;

MXML
<mx:ComboBox x="115" y="61" labelField="Label" textAlign="left" id="MainSkuID" >
</mx:ComboBox>

http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_03.html

FLEX ~ change Label font color

//uint
labelQQ.setStyle('color', 0x00FFFF);

//string
labelQQ.setStyle('color', '#FF00FF');


<mx:Label x="350" y="330" id="labelQQ" alpha="1" color="#FFFFFF" fontWeight="bold" />

Flex ~ set cursor to HandCursor, pointer cursor

<mx:Canvas height="250" width="75" id="cavLeft" useHandCursor="true" buttonMode="true" >

http://www.riafox.com/2008/09/usehandcursor-in-flex-component/