Thursday, July 9, 2009

Masking and Drawing Shape.

private function add_Shape(type:String=""):void
{
removeOrMaskUI();
var bxShared:Sprite = new Sprite()
bxShared.graphics.beginFill(0xffffff, 100);
if(type=="circle")
bxShared.graphics.drawEllipse(0,0,xSize,ySize);
else if(type=="square")
bxShared.graphics.drawRect(0,0,xSize,ySize);
var ui:UIComponent = new UIComponent();
ui.name="currentui";
ui.addChild(bxShared);
ui.setStyle("right",xSize);
ui.setStyle("top",0);
container_object.addChild(ui);
}
public function removeOrMaskUI(isMasking:Boolean=false):void
{
var curUI:UIComponent=container_object.getChildByName("currentui") as UIComponent;
if(curUI)
{
if(isMasking)
container_object.mask=curUI;
else
container_object.removeChild(curUI);
}
}

Friday, July 3, 2009

Give Parallel Effect:

Some time we need to give more than one effect parallaly to component.
for that we can combine multiple effect in parallel tag.

For example.

"<" mx:Parallel id="eff_p" duration="1500" ">"
"<" mx:Fade alphaFrom="0" alphaTo="1" easingFunction="{Elastic.easeInOut}" /">"
"<" mx:Zoom zoomHeightFrom="0.7" zoomHeightTo="1" zoomWidthFrom="0.7" zoomWidthTo="1" easingFunction="{Elastic.easeInOut}" / ">"
"<" /mx:Parallel ">"
"<" mx:Parallel id="eff_remove" duration="800" ">"
"<" mx:Fade alphaFrom="1" alphaTo="0" easingFunction="{Elastic.easeInOut}" / ">"
"<" mx:Zoom zoomHeightFrom="1" zoomHeightTo="0.7" zoomWidthFrom="1" zoomWidthTo="0.7" easingFunction="{Elastic.easeInOut}" / ">"
"<" /mx:Parallel ">"

This will implemnt in component or item render when we need to give it.
On init function in that comonent we can play this effect.

eff_p.play([this]);

We can also give listner when we need to remove it.
for example we need to play remove effect first before closing popup
private function closePopup():void
{
eff_remove.play([this]);
eff_remove.addEventListener(EffectEvent.EFFECT_END, removeItemFromStage);
}

private function removeItemFromStage(event:EffectEvent):void
{
eff_remove.removeEventListener(EffectEvent.EFFECT_END, removeItemFromStage);
PopUpManager.removePopUp(this);
}

Sunday, June 28, 2009

Apply Dynamic Style :

We can apply dynamic style using flex movie clip object apply to class and transformation on it.
1) Extend UIComponent and apply transform in it.

package newExtend
{
import flash.geom.ColorTransform;
import mx.core.UIComponent;

public class newSkin extends UIComponent
{
[Embed(source='new/newskin.swf', symbol='appHeader_shade')]
public static const shade:Class;

[Embed(source='new/newskin.swf', symbol='appHeader_sholid')]
public static const solid:Class;

public function newSkin ()
{}

override protected function updateDisplayList(w:Number, h:Number):void
{
super.updateDisplayList(w, h);
if (getStyle("backgroundColor")!=null)
{
var child:Number = this.numChildren;
for (var num:Number=0; num {
this.removeChildAt(0);
}
child = this.numChildren;

var mc_shade:* = new shade();
var mc_solid:* = new solid();
var ct:ColorTransform = mc_shade.transform.colorTransform;
ct.color = getStyle("backgroundColor");
mc_solid.transform.colorTransform = ct;
mc_shade['width'] = w;
mc_shade['height'] = h;
mc_solid['width'] = w;
mc_solid['height'] = h;
this.addChild(mc_solid);
this.addChild(mc_shade);
}
}
}
}

2) In Css Class like.
.NewStyle
{
border-skin: ClassReference("newExtend.newSkin ");
}

3) Action script coding for changing shadow and solid color
var newStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".NewStyle");
if (newStyle.getStyle("backgroundColor")!=color)
newStyle.setStyle("backgroundColor", color);

for any color when we update color in step 3 at that time the color transformation on apply movie clip id done in updateDiplayList.
This method is working from step 3 to 1 when running.

Thursday, June 25, 2009

Create Custom Menu Using Menu Control

1) Create menuMxmlRenderClass: Name: customMenuRender

"<" mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"
implements="mx.controls.menuClasses.IMenuItemRenderer" ">"
"<" mx:Script ">"
"<" ![CDATA[
import mx.events.StateChangeEvent;
import mx.controls.Menu;
import mx.controls.menuClasses.IMenuItemRenderer;
private function init():void
{
var obj:Object=this.data;
if(obj!=null && obj.mnu_name!=null)
{
txtName.text=obj.mnu_name;
}
}
//Function for IMenuItemRenderer
public function get menu():Menu
{
return null;
}
public function set menu(value:Menu):void
{
}
public function get measuredIconWidth():Number{return 0;}
public function get measuredTypeIconWidth():Number{return 0;}
public function get measuredBranchIconWidth():Number{return 0;}
]] ">"
"<" /mx:Script ">"
"<" mx:Text id="txtName" / ">"
"<" /mx:VBox ">"

2) Function for parent where it will be clicked.

private var l_menu:Menu;
private function openCustomMenu(event:MouseEvent):void
{
if(l_menu==null)
{
l_menu = Menu.createMenu(this,menuContentArray);
l_menu.itemRenderer = new ClassFactory(customMenuRender);
l_menu.addEventListener(MenuEvent.ITEM_CLICK , menuMouseClickHandler);
l_menu.minWidth=160;
l_menu.styleName="menuCornerRadious";
}
var item_Menu:ArrayCollection=menuContentArray;
var xPos:Number=event.stageX + (event.currentTarget.width-event.localX);
var yPos:Number=event.stageY - ((20*item_Menu.length)/2);
l_menu.show(xPos, yPos);
// Function for gettion menu item if required
setMenuEnable();
}

private function setMenuEnable():void
{
if(l_menu!=null)
{
for(var i:int=0;i {
var obj:customMenuRender =l_menu.indexToItemRenderer(i) as customMenuRender;
if(obj)
{
// Calling menu item render function
}
}
}
}

Thursday, June 18, 2009

Some function for Image Edition

Here gives some useful function of image edition


1 > Set britness ,contrast ,hue ,saturation.

private function changesColorFilter(brightness:Number, contrast:Number, saturation:Number, hue:Number):void
{
var cm:ColorMatrix = new ColorMatrix();
cm.adjustColor(brightness, contrast, saturation, hue);
var colorMat:ColorMatrixFilter = new ColorMatrixFilter(cm);
img.filters = [colorMat];
}

2 > Convert hex (uint) code to RGB:

private function ConvertToRGB(hexNum:Number):Object
{
var rgbObj:Object = new Object();
rgbObj.r = hexNum >> 16;
var tmpVal:Number = hexNum ^ rgbObj.r << 16;
rgbObj.g = tmpVal >> 8;
rgbObj.b = tmpVal ^ rgbObj.g << 8;
return rgbObj;
}

3 > Chnage image color using color matrix.

private function changesColor(red:Number, green:Number, blue:Number,imgChange:Image):void
{
var ct:ColorTransform = new ColorTransform();
var rLum:Number = 0.3086;
var gLum:Number = 0.6094;
var bLum:Number = 0.0820;

var cm:Array = [rLum, gLum, bLum, red/255, 0,
rLum, gLum, bLum, green/255, 0,
rLum, gLum, bLum, blue/255, 0,
0, 0, 0, 1, 0 ];
var colorMat:ColorMatrixFilter = new ColorMatrixFilter(cm);
imgChange.filters = [colorMat];

}

Validate in flex

Validate Dynamic using Action Script:

var email_vali:EmailValidator = new EmailValidator();
email_vali.source = emailTextBox;
email_vali.property = "text";
var emailResult:ValidationResultEvent = email_vali.validate();
if (emailResult.type==ValidationResultEvent.INVALID)
{
//Invalid
}

Validate method

"<" mx:EmailValidator id="vali_Email" source="{txt_email}" property="text" "/>"
"<" mx:StringValidator id="vali_Password" source="{txt_password}" property="text" "/>"

In Validata function

var vali:Array = new Array();
vali.push(vali_Email);
vali.push(vali_Password);
var vali_Result:Array = Validator.validateAll(vali);
if (vali_Result.length==0)
{
//Validate successfully...
}

Create dynamic tooltip

private static var toolTipList:ArrayCollection = new ArrayCollection();

public static function createToolTip(event:Event, toolTip:String, style:String = 'errorTipAbove'):void
{
var target:DisplayObject = event.currentTarget as DisplayObject;
var point:Point = new Point(event.currentTarget.x, event.currentTarget.y);
point = target.parent.localToGlobal(point);

if (style=="errorTipBelow")
{
point.y += (target.height+3);
}
else if (style=="errorTipRight")
{
point.x += (target.width+3);
}

var myTip:ToolTip = ToolTipManager.createToolTip(toolTip, point.x, point.y, style) as ToolTip;

myTip.percentWidth = 100;
myTip.styleName = "toolTipStyle";


if (style=="errorTipAbove")
{
myTip.y -= (myTip.height+3);
}

toolTipList.addItem({target: event.currentTarget, toolTip:myTip});
}

public static function destroyToolTip(event:Event):void
{
ToolTipManager.destroyToolTip(getToolTip(event.currentTarget as DisplayObject));
}

private static function getToolTip(object:DisplayObject):ToolTip
{
for (var i:Number=0; i {
if (toolTipList[i].target == object)
{
var tipUI:ToolTip = toolTipList[i].toolTip;
toolTipList.removeItemAt(i);
return tipUI;
}
}
return null;
}
Create singletone class of tooltip
In mxml control
On MouseOverEvent just pass event and tooltip and on MouseOutEvent call destroyToolTip event

Set dynamic style

Using CSSStyleDecalration object we can set style of included style sheet.

var curStyle:CSSStyleDeclaration = StyleManager.getStyleDeclaration(".styleName");
curStyle.setStyle("backgroundColor", 0x876543);

Wednesday, June 17, 2009

Call javascript from MXML and viceversa.

Using ExternalInterface we can call javascript of the page.

if (ExternalInterface.available)
{
ExternalInterface.call("javascriptFunctionName",parameter );
}

if we neet to call swf file's function from the javascript .

ExternalInterface.addCallback("javascriptFunction", HandlerFunction);

private function HandlerFunction(returnValue:String):void
{
// code
}

and in html page in script block.
function javascriptFunction()
{
swfObjectId.HandlerFunction("hello");
}

Using Flash Movie Clips Color Transformation

Using Flash Movie Clips Color Transformation

public var obj_cls:Class;
public var objDetails:ApplicationDomain;

obj_cls = objDetails.getDefinition("flashclassname") as Class;
var obj_mov:MovieClip = new obj_cls() as MovieClip;

obj_mov.transform.colorTransform=0x989898;

Custom Tooltip

Create a custom Tooltip:
1) Create a custom tooltip class:
i) implements="mx.core.IToolTip"
ii) Action Script:
[Bindable]
public var objnode:Array;
private function init():void
{
if(objnode!=null)
{
//Action
}
}
public var _text:String;

public function get text():String {
return _text;
}
public function set text(value:String):void {
}
private function complateHandler():void
{
this.height=(26*objnodelength)+20;
}

2) On any control create tool tip event:

private function createToolTipHandler(event:ToolTipEvent,type:Number):void
{
var toolTip:myCustomToolTip = new myCustomToolTip();
toolTip.colornode = nodearraysource;
toolTip.percentHeight=100;
toolTip.percentWidth=100;
event.toolTip = toolTip;

}

Create User define Menu

Here i give user define menu class:

package com
{
import flash.display.DisplayObject;
import flash.events.MouseEvent;

import mx.collections.ArrayCollection;
import mx.controls.LinkButton;
import mx.core.Application;
import mx.managers.PopUpManager;

public class MgrSmallMenu
{
private static var _instance:MgrSmallMenu;
// Menu List for current generated menu
private static var menuList:ArrayCollection = new ArrayCollection();

public static function get instance():MgrSmallMenu
{
if(!_instance){
_instance = new MgrSmallMenu();
}
return _instance;
}
public static function createMenu(event:MouseEvent,clsType:*):*
{
var curState:Boolean=checkMenuOpen(event.currentTarget as DisplayObject,clsType);

destroyMenuChild();
if(!curState)
{
var target:DisplayObject = event.currentTarget as DisplayObject;
var myMnu:* = clsType(PopUpManager.createPopUp(target, clsType, false));

myMnu.x = event.stageX - (myMnu.width +event.localX+5);
if(myMnu.x<=5)
myMnu.x = event.stageX + (target.width - event.localX);
myMnu.y = event.stageY - (event.localY - 3);
menuList.addItem({myMenu:myMnu,curTarget:event.currentTarget,classType:clsType});
Application.application.addEventListener(MouseEvent.MOUSE_DOWN ,appMouseClickHandler);
return myMnu;
}
return new clsType();
}

public static function destroyMenuChild():void
{
for (var i:Number=0; i {
PopUpManager.removePopUp(menuList[i].myMenu );
menuList.removeItemAt(i);
}
Application.application.removeEventListener(MouseEvent.MOUSE_DOWN ,appMouseClickHandler);
}

public static function appMouseClickHandler(event:MouseEvent):void
{
var lnkBtn:LinkButton=event.target as LinkButton;
if(lnkBtn)
{
if(!checkCurHitObject(lnkBtn))
destroyMenuChild();
}
else
destroyMenuChild();
}
private static function checkCurHitObject(selbtn:LinkButton):Boolean
{
for each(var itemObj:Object in menuList)
{
if(itemObj.curTarget as LinkButton)
{
var openLnkBtn:LinkButton= itemObj.curTarget as LinkButton;
if(openLnkBtn == selbtn)
{
return true;
}
}
}
return false;
}
private static function checkMenuOpen(selTarget:*,selClsType:*):Boolean
{
for each(var itemObj:Object in menuList)
{
if(itemObj.curTarget==selTarget && itemObj.classType==selClsType)
{
return true;
}
}
return false;
}
}
}

Monday, June 15, 2009

AdobeAIR, Check Net Connection

Using URLMonitor we can check status of client net connection .

import mx.states.SetStyle;
import mx.controls.Alert;
import air.net.URLMonitor;
private var monitor:URLMonitor;
private function init():void
{
// URLRequest that the Monitor Will Check
var url:URLRequest = new URLRequest("http://www.google.com");
// Checks Only the Headers - Not the Full Page
url.method = "HEAD";
// Create the URL Monitor and Pass it the URLRequest
monitor = new URLMonitor(url);
// Set the Interval (in ms) - 3000 = 3 Seconds
monitor.pollInterval = 3000;
// Create the Event Listener that Will Be Fired When Connection Changes
monitor.addEventListener(StatusEvent.STATUS,on_connection);
// Start the URLMonitor
monitor.start();
}
private function on_connection(event:StatusEvent):void
{
txt_NetStatus.setStyle("fontWeight","bold");
if(monitor.available==true) // OR USED if(event.code=="Service.available")
{
txt_NetStatus.text="NET CONNECTION AVAILABLE";
txt_NetStatus.setStyle("color","green");
vb.setStyle("backgroundColor","#B0EA8F");
}
else if(monitor.available==false) // OR USED if(event.code=="Service.unavailable")
{
txt_NetStatus.text="NO NET CONNECTION FOUND";
txt_NetStatus.setStyle("color","red");
vb.setStyle("backgroundColor","#FFAF56");
}
}

Friday, June 12, 2009

PopUpManager Closing using voGlobal Class

Here give voGlobal class in this common function of closing popup

----------------------
package com.newVlaueObject.vo
{
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import mx.core.IFlexDisplayObject;
import mx.managers.PopUpManager;

public class voGlobal
{
private static var _instance:voGlobal;
public function voGlobal(enforce:SingletonEnforcer):void
{
}
public static function get instance():voGlobal
{
if(voGlobal._instance == null){
voGlobal._instance = new voGlobal(new SingletonEnforcer());
}
return voGlobal._instance;
}
public function titleWindow_keyDown(event:KeyboardEvent):void
{
if (event.charCode == Keyboard.ESCAPE) {
PopUpManager.removePopUp(event.currentTarget as IFlexDisplayObject);
}
}
}
}
class SingletonEnforcer{}
--------------------------------------------

In each Popup object give keydown Event and init event

KeyDown Event is

keyDown="{voGlobal.instance.titleWindow_keyDown(event)}"

In Init event you just focus any one component of popup object
like

txtName.setFocus();

Thursday, June 11, 2009

Check for hit with other object

In flex it gives function hitTestObject(curObject) that gives boolean value that current object is hit with there parent 's or not.
Here give sample code

var bl:Boolean = parentObject..hitTestObject(current);
if(bl)
Alert.show("object is hit with parent","",4);

Dragging , UIComponent

In Flex each container have it's own UIComponent .
We can use dragging using this UIComponent and also set current child position of canvas.

private function dgMouseUp(event:MouseEvent):void
{
UIComponent(event.currentTarget).stopDrag();
}
private function dgMouseDown(event:MouseEvent):void
{
Canvas(can_name).setChildIndex(UIComponent(event.currentTarget),_dp.length-1);
var area:Rectangle = new Rectangle(0, 0, can_name.width - event.currentTarget.width, can_name.height - event.currentTarget.height);

UIComponent(event.currentTarget).startDrag(false, area);
}

Monday, May 25, 2009

Apply Move Effect To List

I have give some example coding in below image
in that just give dataprovider to horizonatal list and apply some login for next / previous /paging
it's give moving effect to list

mxml Syntax for moving

"< "mx:Move id="eff_project_move" duration="500" easingFunction="{Exponential.easeInOut}" target="{box}" /">"

"<" mx:Canvas ">"
"<"mx:HBox id="bx" moveEffect="{eff_project_move}">"
"<"mx:HorizontalList id="lst" columnWidth="323" /">"
"<"/mx:HBox"> "
"<"/mx:Canvas">"

and In any button Just put syntax like

bx.x = bx.x - lst.columnWidth;

for moving next 1 record

//SOME SWEET LOGIN OF MOVING LIST
Private var totalLen:Number=0;

private var current:Number=0;
private var _pageSize:Number=3;

private var tbtnSrc:ArrayCollection=new ArrayCollection();

private function init():void
{
list_object.dataProvider = ary_dataProvider;
list_object.columnCount = ary_dataProvider.length;

totalLen=list_object.dataProvider.length;
current=1;
setPage();
}

private function setPage():void
{
var tp:int= totalLen/_pageSize;
var tp1:Number= totalLen/_pageSize;
var pageLen:Number=0;

if(tp==tp1)
{
pageLen=tp;
}
else
{
pageLen=tp+1;
}
tbtnSrc.removeAll();

for(var i:int=1;i<=pageLen;i++)
{
var obj:Object=new Object();
obj.curPage=i.toString();
tbtnSrc.addItem(obj);
}
btnPage.dataProvider=tbtnSrc;
if (tbtnSrc.length>0)
btnPage.selectedIndex=0;
}

private function itemClickBtbar(event:ItemClickEvent):void
{
var selInd:Number=Number(event.item.curPage);
var moveVal:Number=(selInd*_pageSize)-(current*_pageSize);
var xfrom:Number=0;
var xto:Number=0;
if(eff_project_move.isPlaying)
{
eff_project_move.stop();
}
xfrom= - ((current-1)*_pageSize*list_object.columnWidth);
xto= xfrom - (moveVal*list_object.columnWidth);

eff_project_move.xFrom=xfrom;
eff_project_move.xTo=xto;
eff_project_move.play();
current=selInd;
}

Tuesday, May 12, 2009

Read XML and read through value object

Create new singleToneClass and write function for request xml type and result handler.
set return function to returnFunction variable for call function after result geting.

public function loadXmlData(xmlUrl:String, rFunction:Function):void
{
var serviceData:HTTPService = new HTTPService();
serviceData.url = xmlUrl;
serviceData.addEventListener(ResultEvent.RESULT, loadXmlResultHandler);
serviceData.send();
returnFunction = rFunction;
}


Result is get in two type if result have single object or single value then give direct object value
If result have multiple object then it give array of object value.
result value object is fill in listObject array / arrayColloction.

private function loadXmlResultHanlder(event:ResultEvent):void
{
var resultData:Object = event.result.itemInfo;
var itemValueObject:clsValueObject;

if(resultData.item as ArrayCollection)
{
for each (var Item:Object in resultData.item)
{
itemValueObject = new clsValueObject();
itemValueObject.setData(Item);
listObject.addItem(itemValueObject); }
}
else
{
itemValueObject = new clsValueObject();
itemValueObject.setData(resultData.item);
listObject.addItem(itemValueObject);
}
if(returnFunction!=null)
{
returnFunction();
returnFunction=null;
}
}

Thursday, May 7, 2009

Set dynamic height/width of swf object using Action Script

In any flex application you run on web it's height is default set to display html page's height.
If swf object height is greter than html page size then it give's horizontal scrolling in swf object.
Here gives some tips to how can we set swf object size and html page size dynamically.

1. Create class in that set changing parameter.

private var objHeight:Number = 0;
private var timer:uint = 0;
public function setScrollSize(objUi:VBox):void
{
if (objUi)
{
objHeight = Application.application.height;
objUi.minHeight = objHeight;
BindingUtils.bindSetter(update_height_handler,objUi, "height");
}
}
private function update_height_handler(objVal:Number):void
{
clearTimeout(timer);
timer = setTimeout(Timeout_handler, 5, objVal);
}
private function Timeout_handler(objVal:Number):void
{
if (objHeight>objVal)
objVal = MinHeight;

resizeObject_handler(0,objVal);
}
public function resizeObject_handler(objWi:Number = 0,objHi:Number = 0):void
{
if (ExternalInterface.available)
{
ExternalInterface.call("java_resizeObject", objWi, objHi);
}
}


2. Set Javascript in your html page

function java_resizeObject(width,height)
{
var _object = document.getElementById("swfFileName");
if(width != undefined && width != 0)_object.style.width = width;
if(height != undefined && height != 0)_object.style.height = height;
}


3. Call this function at the init() event of application pass the container object in that.

Set multiple language at run time / set Resource file.

We can create multilingual application using resource manager.
1. Create folder eg. LocalRes/en_US and LocalRes/fr_FR
2. Create builder.properties file in both folder
2. Set key and value in according to language like
key1=value1
key2=value2
3. Right Click on project -> Properties ->Flex Compiler
4. Set Additional Compiler argumnets:
-locale en_US fr_FR -source-path=LocalRes/{locale} -allow-source-path-overlap=true
5. Open main Application mxml file set -> resourceManager.localeChain = "en_US"; // according to language
6. Get Resource file key value using -> resourceManager.getString('builder', 'key1');
7. In project you can give set string using this resourceManager.
8. In .as file you can use ->ResourceManager.getInstance().getString('builder', 'key1');
9. Set matadata in main Application mxml file
"<"mx:Metadata">"
[ResourceBundle("builder")]
"<" /mx:Metadata ">"

Set resource file dynamically

Some times we need to set resource file dynamically like we need to set language english / french;
we can do this by passing parameter in flash object.

In script tag in html page we find AC_FL_RunContent() function in that all variable of flash object is set.
we can add variable || "FlashVars", "language=fr_FR" || in that function this variable is give static or dynamic in javascript.

in main Application mxml page's preinitialize event we get setting parameter which given below.

var objLan:String="";
if(Application.application.parameters.hasOwnProperty("language") && Application.application.parameters.language!="")
{
objLan=Application.application.parameters.language;
}
resourceManager.localeChain = [objLan];

Store content value in local

Some time we need to keep previous setting of application in our local system.
We can do this by SharedObject.

private var appHeight:Number=200; // Default height 200
private var appWidth:Number=200; // Default width 200
private var sharedObj:SharedObject; // SharedObject

Save Setting in SharedObject

sharedObj.data.setting = new Object();
sharedObj.data.setting.appHeight = appHeight;
sharedObj.data.setting.appWidth = appWidth;

Get Setting in SharedObject

sharedObj =SharedObject.getLocal("GeneralSetting");
appHeight = so.data.setting.appHeight;
appWidth = so.data.setting.appWidth;

Read and Write file in encrypted format without using encryption

Read File :-

private function readEncryptedFile(objFile:File):String
{
var objFileStream:FileStream = new FileStream();
objFileStream.open(objFile, FileMode.READ);

var objByt:ByteArray = new ByteArray();
objFileStream.readBytes(byt, 0, objFileStream.bytesAvailable);
objByt.uncompress(CompressionAlgorithm.DEFLATE);
var retStr:String = byt.readObject();
return retStr;
}


Write File :-

public function writeEncryptedFile(objFile:File, writeDataStr:String):void
{
var objFileStream:FileStream = new FileStream();
objFileStream.open(objFile, FileMode.WRITE);

var objByt:ByteArray = new ByteArray();
objByt.writeObject(objDataStr);
objByt.position = 0;
objByt.compress(CompressionAlgorithm.DEFLATE);

ojbFileStream.writeBytes(objByt, 0, objByt.length);
objFileStream.close();
}

Wednesday, May 6, 2009

Capturing & Copying Image

var objCan:Canvas= new Canvas();
var img:Image=new Image();//Source Image
var imgSave:Image=new Image();//Destination Image
var sourceBMP:BitmapData = new BitmapData(img.width,img.height);
var gbheight:Number=500;
var gbwidth:Number=500;
var gbX:Number=5;
var gbY:Number=5;

//Capture Bitmap of Canvas
var objBitmapData:BitmapData = ImageSnapshot.captureBitmapData(objCan);
//Dwaw image in Source BitmapDatObject
sourceBMP.draw(objBitmapData, new Matrix());
//Get New BitmapData
var destBMPData:BitmapData= new BitmapData(gbwidth,gbheight);;
//set Destination Bitmap data as per x,y and height,width from source bitmap data object
destBMPData.copyPixels(sourceBMP, new Rectangle(gbX,gbY,gbwidth,gbheight),new Point(0,0));
//convert destination bitmapdata to bitmap
var bitmap:Bitmap= new Bitmap(destBMPData);
// Apply smoothing for smooth image
bitmap.smoothing=true;
//Give source of destination image
imgSave.source= bitmap;

Tuesday, May 5, 2009

Add Sprite into Container . Use ClassFactory for itemRenderer.

Sprite : - It's needed when any flash component is add into container.
UIComponent :- It is used for adding Flash component.

If we want to add flash component into canvas then
1. Create flash component object.
2. Create Sprite object and add flash component object.
3. Create UIComponent object and add Sprite object.
4. Get Canvas container object "objCan" then add UIComponent object.
objCan.rawChildren.addChild(objUIComponent);

Here we need rawChildern property for adding objUIComponent.

ClassFactory : - When any dynamic Grid, TileList , List component need ItemRender which is also dynamic then we need to create ClassFactory Object for applying dynamic ItemRender.


var itemRenderer:ClassFactory = new ClassFactory(itemReaderClassType)
tl.itemRenderer = itemRenderer;

On Item Render need override method :
override public function set data(value:Object):void
{
if (value!=null)
{
super.data = value;

}
}

Monday, May 4, 2009

Drag Drop Componet



Container who can accept dragged component have two event

1. Drag Enter : when drag component is enter. Accept drag component here.
2. Drag Drop : When drop component. Get Dragged Component and add to container.

Saturday, May 2, 2009

Flex Introduction

  • Flex is adobe's language which are used for developing web / Air(desktop) application.
  • Flex end product is .swf (flash) file so u only need flash player for browser to run web application.
  • We can say this type of application is RIA (Reach Internet Application) .
  • Web Site's which are developing in Flex no need to refresh browser's page.
  • All the connectivity of database in Flex is using , Remote Object , Web Service and Http Service calling.
  • Back end business logic is developing in .net / php / cold fusion etc... which sql server , my sql etc...