Remove item from Array/ArrayCollection

Below code remove item from Array/Arraycollection and takes care of array/arraycollections’s new indexes :

var i:int= 0;
while(i<draftsAC.length)
{
if(draftsAC[i].isSelected)// condition to remove  item
{
draftsAC.removeItemAt(i);

//do not increment i as array/arraycollcetion’s index reduced by 1 because of delete

}
else
{
//increment i

i++ ;
}
}

Posted in Uncategorized | Leave a comment

Regular expression

\b :
\b allows you to perform a “whole words only” search using a regular expression in the form of \bword\b. A “word character” is a character that can be used to form words. All characters that are not “word characters” are “non-word characters”.

Example :
sampleStr = ‘find it and replace what you find.’
regexp : /\bfind\b/g;
result: it will match at index 0 and 29
whereas
if sampleStr = ‘find it and replace what youfind.’
result: it will match at index 0 only

 

The m (multiline) flag

If the m (multiline) flag is not set, the ^ matches the beginning of the string and the $ matches the end of the string. If the m flag is set, these characters match the beginning of a line and end of a line, respectively. Consider the following string, which includes a newline character:

var str:String = “Catch me if you can\n”;
str += “catch but do not catch me if you can not”;
trace(str.match(/^\w*/g)); // Match a word at the beginning of the string.

Even though the g (global) flag is set in the regular expression, the match() method matches only one substring, since there is only one match for the ^–the beginning of the string. The output is:

Here is the same code with the m flag set:

var str:String = “Catch me if you can\n”;
str += “catch but do not catch me if you can not”;
trace(str.match(/^\w*/gm)); // Match a word at the beginning of lines.

This time, the output includes the words at the beginning of both lines:
at index 0 and 21

Posted in Uncategorized | Leave a comment

Spark combobox issue in sdk 4.1.0

selected index 4 value shown in prompt textinput on up/down array key in dropdown

<s:ComboBox id=”myCB” width=”140″ color=”#000000″ requireSelection=”true”>
<s:dataProvider>
<mx:ArrayList>
<fx:String>Red</fx:String>
<fx:String>Orange</fx:String>
<fx:String>Yellow</fx:String>
<fx:String>Blue</fx:String>
<fx:String>Green</fx:String>
</mx:ArrayList>
</s:dataProvider>
</s:ComboBox>

Spark combobox shows value corresponding to selected index 4 but does not work with selected index 0 on down/up arrow key in dropdown

do not show value for selected index = 0 on down/up arrow key in dropdown

It is an issue in Flash builder 4.1.0 sdk and solved in 4.5 sdk.

ComboBox.as

override mx_internal function changeHighlightedSelection(newIndex:int, scrollToTop:Boolean = false):void
{
super.changeHighlightedSelection(newIndex, scrollToTop);

if (newIndex > 0)// new Index is not checked for 0th index
{
var item:Object = dataProvider ? dataProvider.getItemAt(newIndex) : undefined;
if (item)
{
var itemString:String = itemToLabel(item);
textInput.selectAll();
textInput.insertText(itemString);
textInput.selectAll();

userTypedIntoText = false;
}
}
}

In Flash builder 4.5 they solved by changing condition if (newIndex >= 0).

Found by Shailesh Kadam

 

Posted in Uncategorized | Leave a comment

Singleton class for Localization in Flex

Default way of using resourceManager

resourceManager.getString(bundleName,resourceName,parameters)

We have customized way of using resourceManager by using singleton class : ResourceUtil

Modified syntax of using ResourceUtil

ResourceUtil.string(resourceName,parameters)

– It reduced the code by not using bundleName each time. Find the code below to create singleton class

ResourceUtil.as

public class ResourceUtil
{
public static const DEFAULT_BUNDLE:String = ‘ResourceFileName’;

public static function string(key:String,parameters:Array=null):String
{
return ResourceLoader.instance().getString(DEFAULT_BUNDLE,key,parameters);
}
}

ResourceLoader.as :

package
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;

import mx.resources.IResourceManager;
import mx.resources.ResourceManager;

[ResourceBundle("ResourceFileName")]
public class ResourceLoader extends EventDispatcher
{
public static const DEFAULT_LOCALE:String=’en_US’ ;
public static var _instance:ResourceLoader ;
private var _resourceManager:IResourceManager ;

public static function instance():ResourceLoader
{
if(_instance == null)
{
_instance = new ResourceLoader(PrivateSingletonEnforcer);
}

return _instance ;
}

public function ResourceLoader(singletonEnforcer:Class)
{
if(singletonEnforcer!=PrivateSingletonEnforcer)
{
throw new Error(‘ResourceLoader cannot be instantiated directly.’)
}
_resourceManager = ResourceManager.getInstance();
}

public function getString(bundleName:String,resourceName:String,parameters:Array = null):String
{
var value:String = _resourceManager.getString(bundleName,resourceName,parameters);
if(value == null)
return resourceName ;
else
return value ;
}

}
}

class PrivateSingletonEnforcer
{
}

Posted in Flex | Leave a comment

Spark TabBar with different image as skin for each button

Problem:

To show each tab in TabBar with  different images as skin

Solution :

Spark TabBar with dataprovider

<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]private var tabs:ArrayCollection = new ArrayCollection([
{label:'Fabric',imageIcon:'color.png',id:'FABRIC'},
{label:'Design',imageIcon:'design.png',id:'DESIGN'},
{label:'Color Contrast',imageIcon:'fabric.png',id:'COLOR_CONTRAST'},
{label:'Measurement',imageIcon:'measurment.png',id:'MEASUREMENT'}
]);
]]>
</fx:Script>

<s:TabBar skinClass=”TabBarSkin” dataProvider=”{tabs}” height=”25″
labelField=”label”/>

 

TabBarSkin.mxml

<s:DataGroup id=”dataGroup” width=”100%” height=”100%”>
<s:layout>
<s:ButtonBarHorizontalLayout gap=”-1″/>
</s:layout>
<s:itemRenderer>
<fx:Component>
<s:ButtonBarButton skinClass=”IconButtonSkin” />
</fx:Component>
</s:itemRenderer>
</s:DataGroup>

IconButtonSkin:

In script file:

– create Class type for each image

[Embed(source="measurment.png")]
private var image1:Class;
[Embed(source="color.png")]
private var image2:Class;
[Embed(source="design.png")]
private var image3:Class;
[Embed(source="fabric.png)]
private var image4:Class;
– Override function  updateDisplayList

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);

var btnId:String = (this as Object).hostComponent.data.id;

var label:String = (this as Object).hostComponent.data.label;
labelDisplay.text = label ;

switch(btnId)
{
case ‘FABRIC’:
icon.source = image1 ;
break;
case ‘DESIGN’:
icon.source = image2 ;
break;
case ‘COLOR_CONTRAST’:
icon.source = image3;
break;
case ‘MEASUREMENT’:
icon.source = image4 ;
break;
}

this.width = this.hostComponent.width;
this.minWidth = this.hostComponent.width;
}

<s:Label id=”labelDisplay” visible=”false” includeInLayout=”false”
textAlign=”center”
verticalAlign=”middle”
maxDisplayedLines=”1″
horizontalCenter=”0″ verticalCenter=”1″
left=”10″ right=”10″ top=”2″ bottom=”2″>
</s:Label>

<s:BitmapImage id=”icon” smooth=”true” width=”91″ height=”101″ visible=”true”
/>

 

 

 

 

 

 

Posted in Uncategorized | Leave a comment

Advanceddatagrid with HTML Header Renderer

Problem:  Show header and subheader text in each column of AdvancedDataGrid. Subheader is optional and always  come below mainheader text. for e.g.: Delhi\n(India)

Solution:

1) Created custom AdvancedDataGridHeaderRenderer

2) assign it as headerrenderer to AdvancedDataGrid column.

3) provide headertext as ‘mainheadertext/nsubheadertext’. Internally it differentiate text for header and subheader.

HTMLTextADGHeaderRenderer :

import flash.display.DisplayObject;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
    import mx.controls.advancedDataGridClasses.AdvancedDataGridHeaderRenderer;
    import mx.core.UITextField;

    public class HTMLTextADGHeaderRenderer extends AdvancedDataGridHeaderRenderer
    {
        private var htmlHeaderText:UITextField;

        public function HTMLTextADGHeaderRenderer()
        {
            super();
        }

        override protected function createChildren():void
        {
            super.createChildren();
            htmlHeaderText=new UITextField();
            htmlHeaderText.percentWidth=100;
            htmlHeaderText.background=false;
            htmlHeaderText.border=false;

            addChild(DisplayObject(htmlHeaderText));
        }

        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);

            htmlHeaderText.htmlText = AdvancedDataGridColumn(this.data).headerText;
            var arr:Array=AdvancedDataGridColumn(this.data).headerText.split(‘\\n’);
            if (arr.length > 1)
            {
                htmlHeaderText.htmlText=’<TEXTFORMAT><P ALIGN=”CENTER”>’ + arr[0] + ‘\n’ + arr[1] + ‘</P></TEXTFORMAT>’;
            }
            else
            {
                htmlHeaderText.htmlText=’<TEXTFORMAT><P ALIGN=”CENTER”>’ + AdvancedDataGridColumn(this.data).headerText + ‘</P></TEXTFORMAT>’;
            }

            htmlHeaderText.width=unscaledWidth – 5;
            htmlHeaderText.wordWrap=true;

            this.label.visible=false;
            this.label.includeInLayout=false;

        }
    }

Posted in Uncategorized | Leave a comment

Center tag: keep everything in middle

<html>

<body>

<center>

… put any content, it will be aligned in the center of browser page
… I think we have to keep content size lesser than browser size
to fit into middle
</center>

</body>

</html>

 

 

 

Posted in Browser, Flex, Flex4, Flex_Hack, IE | Leave a comment

Regular Expression To Strip Off Non-ASCII characters from text..

By Abhijit Ghatnekar
Most websites today provide textareas in the form of editors and people copy + paste text in them from all sorts of text editors. Editors like MS-Word introduce unwanted special characters in the text which go as well into the back end. It’s quite flummoxing and intriguing and sometimes the text appears valid but does not bypass the validation mechanisms of the server-side web application.

To Strip these off… employ the following Regex…..

$output = preg_replace(‘/[^(\x20-\x7F)]*/’,”, $output);

This will strip of all Non-ASCII

This actually is PHP… but it could be translated into any equivalent web scripting language.

Posted in Archive_Code | 1 Comment

Flex : Find the URL of the Server / Local file location based on the Application server type

This code is used to find the URL of the Server / Local file location based on the Application server type (java, php,.. / none).

- by Abdul

Posted in Flex4, Flex_Hack, Flex_Training | Leave a comment

My life’s principle & corresponding Mentor’s list

A real thanks to all of them for being in my life & contributing something to my life.

My life’s principle & corresponding Mentor’s list:
1) HardWork : My parents
2) Entrepreneurship: Nirav Mehta(Magnet Technologies,CEO),Rohan Fernandes(Flex Flash Developer),Anand Kumar(Super 30,Patna)
3) Community : Landmark Education Forum, Anand Kumar
4) Style: My Wife
5) Programming: Anuj Pandey(e10.in),Nirav Mehta, Megha Shah(Flex developer)
6) Business: My Father
7) Computer Hardware: Sonathan Paul(Hardware Engineer)
8) Girls-Interest: Nidhi Singh(Friend), Pramod Shrivastav(QA)
9) Comedy : Raju Shrivastav(comedian)

Posted in Community | Leave a comment