Tuesday, May 25, 2010

small things on flex 3.0

//parse xml based on some condition in a single line
objAudit.companyName = tempData.Company.(ObjectId == tempData.AuditIntro[auditCount].CompanyId.toString()).DisplayName.toString();

//properties and custom event
[Bindable("maxFontSizeChanged")]
public function get maxFontSize():Number
{Flocal

return _maxFontSize;
}

//use flash data in flex
http://fbflex.wordpress.com/2008/06/12/passing-data-from-flash-to-flex-and-back/

/*use php data i flex*/
http://devzone.zend.com/article/11-Integrating-Adobe-Flex-and-PHP
***********************************************
Local to global
private function PointLocalToGlobal(containerBox:ObjectHandles):Point
{
var point : Point = new Point();
point.x = containerBox.x;
point.y = containerBox.y;
var tempX : int = point.x;
var tempY : int = point.y;
point = containerBox.localToGlobal(point);
point.x = point.x - tempX ;
point.y = point.y - tempY ;
return point;
}

********************
border sides
borderSides="left right top bottom"
*********************
/*to change the object into arraycollection - it will convet single value object into arraycol*/
if(flash.utils.getQualifiedClassName(event.result.mainData.result).toString()=="mx.collections::ArrayCollection")
collection=event.result.mainData.result;
else
collection =new ArrayCollection(ArrayUtil.toArray(event.result.mainData.result));
*********************************************
/*send parameter with http service*/







{username.text}


{password.text}


{new Date().getTime()}




******************************************
useHandCursor="true" buttonMode="true" mouseChildren="false"
****************************
open new browser


public function imageClick():void
{
var url:String = "http://www.averq.com";
var request:URLRequest = new URLRequest(url);
navigateToURL(request,"_blank");//self
*****************************
store value in share object in the system

public var shObj:SharedObject=SharedObject.getLocal("Help");

if(shObj.data.mission != true)
{
var objpop:HelpPopUp = HelpPopUp(PopUpManager.createPopUp(this,HelpPopUp,true));
objpop.x = 100;
objpop.y = 130;
objpop.helpTextArea.htmlText = SpyGameModelLocater.getInstance().applicationHelpArr[1];

shObj.data.mission = true ;
shObj.flush();
***************************************************
no navigation browser in java script
/*java script code

function noNavigationBrowser()
{
window.open('http://www.google.com','as','menubar=0,status=0');
}
//window.open('URL','Sale Invoice','left=0,top=0,width=250,height=150,resizable=yes');

//call function in flex
ExternalInterface.call("noNavigationBrowser");
***************************************
single line if-else statement
data.submenu==1? ' '+data.Name:data.Name
***********************************
to make single node to arraycollection

if(flash.utils.getQualifiedClassName(event.result.PlayerInfo.Template).toString()=="mx.collections::ArrayCollection")
collection=event.result.PlayerInfo.Template;
else
collection =new ArrayCollection(ArrayUtil.toArray(event.result.PlayerInfo.Template));
**************************
//confirmation message

Alert.show("Are you sure you want to delete this item?","Delete Item Alert",Alert.YES|Alert.NO,null,alertListener);

private function alertListener(eventObj:CloseEvent):void
{
if (eventObj.detail==Alert.YES) {}
}
************************
image sepia and black white

private var matrixSepia:Array = [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0];
private var matrixBW:Array = [0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0.3,0.59,0.11,0,0,0,0,0,1,0];//red,green,blue,alpha

private function shadeImage(currentImage:Image,arr:Array):void
{
grayscaleFilter = new ColorMatrixFilter(arr);
currentImage.filters = [grayscaleFilter];
}
**********************************
9-slice scalling in flex

[Embed( source="assets/fancy_border.png",
scaleGridTop="55", scaleGridBottom="137",
scaleGridLeft="57", scaleGridRight="266"

)]
***********************************
form item css

FormItem
{
labelStyleName
: customTextAlignLabel;
}

.customTextAlignLabel
{
textAlign
: left;
}
***********************
reduce coding

this["lbl_"+num].styleName = "lblSelAddItem";

***************
capture bitmap

private function takeSnapshot(source:IBitmapDrawable):BitmapData
{
var imageBitmapData:BitmapData = ImageSnapshot.captureBitmapData(source);
return imageBitmapData;
}

********************
embed font in css
@font-face
{
src: url("assets/css/MyriadPro-Regular.otf");
fontFamily: Myriad Pro;
}
******************************
aray collection format
private var indusries:ArrayCollection = new ArrayCollection( [
{ IndustryID: 1, industryName: "A" ,metaTag:"m1" ,Status:"A" },
{ IndustryID: 2, industryName: "B" ,metaTag:"m2" ,Status:"A" },
{ IndustryID: 3, industryName: "C" ,metaTag:"m3" ,Status:"A" },
{ IndustryID: 4, industryName: "D" ,metaTag:"m4" ,Status:"A" },
{ IndustryID: 5, industryName: "E" ,metaTag:"m5" ,Status:"A" },
{ IndustryID: 6, industryName: "F" ,metaTag:"m6" ,Status:"A" },
{ IndustryID: 7, industryName: "G" ,metaTag:"m7" ,Status:"A" },
{ IndustryID: 8, industryName: "H" ,metaTag:"m8" ,Status:"A" },
{ IndustryID: 9, industryName: "I" ,metaTag:"m9" ,Status:"A" } ]);

***********************************
setter getter

public function get ImgText():String
{
return imgText ;
}
public function set ImgText(ImgText:String):void
{
this.imgText = ImgText;
}

*****************************
var getUserEvent:OnlineAccountingEvent = new OnlineAccountingEvent(OnlineAccountingEvent.SAVE_KEYCONTACTS);
getUserEvent.OnlineAccountEventObjectInitialise(keycontactVO);
OnlineAccountingModelLocator.getInstance().AddEventToArrayCollection(OnlineAccountingEvent.SAVE_KEYCONTACTS);
CairngormEventDispatcher.getInstance().dispatchEvent(getUserEvent);
************************
filter function

categoryCol.filterFunction = function(item:Object):Boolean{return(catName.text==item.categoryName?true:false)}
categoryCol.refresh();
*************************************
/* use flash vars*/
http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html


************

***********

/*syntax of call later*/

callLater(
function() {
code
}
);
*************************
matriz link

http://livedocs.adobe.com/flex/3/langref/flash/geom/Matrix.html
*************************






************************

to check when the object intersect
hitTest()

*************************************
/*datagrid check boxes*/







/**************************************/
change size of hslider thumb

http://blog.flexexamples.com/2007/09/12/changing-a-slider-controls-thumb-skin/

/**************************************************/
split escape character from a string
fineName = fineName.substring((fineName.lastIndexOf('\\'))+1,fineName.length);

used link - http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001869.html
//**************************************************************************************
browse and save a file in air

private var file:File;

private function addAttatchmentClickHandler():void
{
file = new File();
file.addEventListener(FileListEvent.SELECT_MULTIPLE, file_selectMultiple);
file.browseForOpenMultiple("Please select a file or more...");
}

private function file_selectMultiple(evt:FileListEvent):void
{
for(var i:int=0;i

***********************************************
sort the arraycollection

var sortA:Sort = new Sort();
sortA.fields=[new SortField("label")];
myAC.sort=sortA;
//Refresh the collection view to show the sort.
myAC.refresh();

*******************************************************
to get list drop index (on dragdrop event )

evt.preventDefault();
var dropTarget:List = List(evt.currentTarget);
var dropLoc:int = dropTarget.calculateDropIndex(evt);

****************************************************
prevent the flex default event behaviour

evt.preventDefault();
************************************
Load style at run time

var evtDispatcher:IEventDispatcher = StyleManager.loadStyleDeclarations('CSSStyles/fusionfont.swf');
evtDispatcher.addEventListener(StyleEvent.COMPLETE,abc);
evtDispatcher.addEventListener(StyleEvent.ERROR,abc1);
******************************************
Item render in AS
tileView.itemRenderer = new ClassFactory(ThumbnailPod);
***********************************************
cancat to array collection

public function copyArrayCollection (src1:ArrayCollection, src2:ArrayCollection):ArrayCollection
{
var result:ArrayCollection = new ArrayCollection(src1.source.concat(src2.source));
return result;
}

***********************************************
trim function in action script

function trim(str:String):String
{
var stripCharCodes = {
code_9 : true, // tab
code_10 : true, // linefeed
code_13 : true, // return
code_32 : true // space
};
while(stripCharCodes["code_" + str.charCodeAt(0)] == true) {
str = str.substring(1, str.length);
}
while(stripCharCodes["code_" + str.charCodeAt(str.length - 1)] == true) {
str = str.substring(0, str.length - 1);
}
return str;
}
***********************************************
difference between Two dates

private function calcuateDays( start:Date, end:Date ) :int
{
var daysInMilliseconds:int = 1000*60*60*24
return ( (end.time - start.time) / daysInMilliseconds );
}
*********************************

get the version of flash player

var customMenuItem1:ContextMenuItem = new ContextMenuItem("Flex SDK " + mx_internal::VERSION, false, false);
var customMenuItem2:ContextMenuItem = new ContextMenuItem("Player " + Capabilities.version, false, false);

//*************************************
right click event in flex

contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,rightClickHandler);
//************************
dispatch manual event

layoutChose.dispatchEvent(new ListEvent(ListEvent.CHANGE, true ,false));
//****************************

pagin link

http://www.darklump.co.uk/blog/?p=112
//*****************************************************
browser close event

window.onbeforeunload = function ()
{
if(!fusionbook.cancloseornot)
{
return 'true';
}
}

private function appClick():void
{
Alert.show("");
ExternalInterface.addCallback("cancloseornot",cancloseornot);
}

public function cancloseornot():Boolean
{
return true;
}
//**********************************************************************
// get number of unique recods from arraycollection
//******************************************************

public function getUniqueValues (collection : ArrayCollection) : ArrayCollection {
var length : Number = collection.length;
var dic : Dictionary = new Dictionary();

//this should be whatever type of object you have inside your AC
var value : Object;
for(var i : Number = 0; i < length; i++){
value = collection.getItemAt(i);
dic[value] = value;
}

//this bit goes through the dictionary and puts data into a new AC
var unique = new ArrayCollection();
for(var prop :String in dic){
unique.addItem(dic[prop]);
}
return unique;
}

No comments:

Post a Comment