Wednesday, November 23, 2011

Search Tree Node Variables

Search Tree Node Variables
 MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="createAccor();" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#6A6A6A, #6A6A6A]">
    <mx:XMLList id="data">
         <node>
            <node name="A">
                 <node name="A1" surname="a1" age="21" wage="1200"/>
                 <node name="A2" surname="a2" age="22" wage="1000">
                 <node name="A2.2" surname="a2" age="22" wage="1000"/>
                 <node name="A2.3" surname="a2" age="22" wage="1000">
                 <node name="A2.7" surname="a2" age="22" wage="1000"/>
                 <node name="A2.8" surname="a2" age="22" wage="1000"/>
                 <node name="A2.9" surname="a2" age="22" wage="1000"/>
                 <node name="A2.10" surname="a2" age="22" wage="1000"/>
                 </node>
                 <node name="A2.4" surname="a2" age="22" wage="1000"/>
                 <node name="A2.5" surname="a2" age="22" wage="1000"/>
                 </node>
                <node name="A3" surname="a3" age="23" wage="1200"/>
                <node name="A4" surname="a4" age="24" wage="1500"/>
            </node>
            <node name="B">
                <node name="B1" surname="b1" age="21" wage="1900"/>
                <node name="B2" surname="b2" age="22" wage="1500"/>
                <node name="B3" surname="b3" age="23" wage="1200"/>
            </node>
            <node name="C">
                <node name="C1" surname="c1" age="29" wage="1500"/>
                <node name="C2" surname="c2" age="45" wage="1500"/>
            </node>
        </node>
    </mx:XMLList>
   
    <mx:Script>
        <![CDATA[
            import mx.core.Container;
            import mx.controls.Tree;
            import mx.containers.Canvas;
            import mx.collections.XMLListCollection;
       
            [Bindable]
            private var searchResult:XMLList;
            private var searchResultIndex:uint = 0;
           
           
            public function createAccor():void
            {
                trace(data.node.length());
                for(var i:int=0; i<data.node.length(); i++)
                {
                    var AcorCan:Canvas=new Canvas();
                    AcorCan.percentWidth=100;
                    AcorCan.percentHeight=100;
                    AcorCan.label=data.node[i].@name;
                    trace("node"+data.node[i].@name);
                    pannelAcord.setStyle("fontColor","#000000");
                    var acorsectiontree:Tree=new Tree();
                    acorsectiontree.percentWidth=100;
                    acorsectiontree.percentHeight=100;
                    acorsectiontree.showRoot=true;
                    acorsectiontree.setStyle("defaultLeafIcon",null);
                    acorsectiontree.setStyle('useRollOver',true);
                    var dummyxml:XMLList=new XMLList(data.node[i].node);
                    trace("dym"+dummyxml);
                    acorsectiontree.dataProvider=dummyxml;
                    acorsectiontree.labelField="@name";
                    acorsectiontree.percentWidth=100;
                    AcorCan.addChild(acorsectiontree);
                    pannelAcord.addChild(AcorCan);
                }
            }
          
           public var val:int;
           private function findByName():void
            {
              var searchStr:String =searchtext.text;
             
              for(var i:int=0; i<data.node.length(); i++)
              {
                for(var j:int=0; j<data.node[i]..@name.length(); j++)
                {
                     if(data.node[i]..@name[j]==searchStr)
                     {
                       pannelAcord.selectedIndex=i;
                       val=new int(i);
                     }else{trace("False");}
                }
                 
              }
              ((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandChildrenOf(data[0], false);
                searchResult = data.node..node.(@name.toLowerCase().search(searchStr.toLowerCase()) > -1);
                trace("SEARCH"+searchResult);
                searchResultIndex = 0;
                if (searchResult[searchResultIndex] != undefined)
                expandNode(searchResult[searchResultIndex]);
                trace("SR"+searchResult);
            }
           
            private function expandNode(xmlNode:XML):void
            {
                while (xmlNode.parent() != null) {
                    xmlNode = xmlNode.parent();
                    ((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).expandItem(xmlNode, true, false);
                    ((pannelAcord.getChildAt(val) as Container).getChildAt(0) as Tree).selectedItem = searchResult[searchResultIndex];
                     trace("Enter"+xmlNode);
                }
            }
           
        ]]>
    </mx:Script>
    <mx:TextInput x="121" y="77" id="searchtext"/>
    <mx:Button x="289" y="77" label="Search" click="findByName()"/>
    <mx:Canvas x="121" y="122" width="233" height="337">
    <mx:Accordion id="pannelAcord" width="100%" height="100%">
    </mx:Accordion>
    </mx:Canvas>
   
   
</mx:Application>


Search Tree Node Variable Demo

Full Screen Mode

Full Screen Mode


MXML File

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/07/creating-full-screen-flex-applications/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" applicationComplete="init()">

    <mx:Script>
        <![CDATA[
            import flash.display.StageDisplayState;
            import mx.managers.SystemManager;

            private function init():void {
              
                systemManager.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
                dispState = systemManager.stage.displayState;
            }

            private function fullScreenHandler(evt:FullScreenEvent):void {
                dispState = systemManager.stage.displayState + " (fullScreen=" + evt.fullScreen.toString() + ")";
               
                if (evt.fullScreen) {
                 
                } else {
                   
                }
            }

            private function toggleFullScreen():void {
                try {
                    switch (systemManager.stage.displayState) {
                        case StageDisplayState.FULL_SCREEN:
                            /* If already in full screen mode, switch to normal mode. */
                            systemManager.stage.displayState = StageDisplayState.NORMAL;
                            break;
                        default:
                            /* If not in full screen mode, switch to full screen mode. */
                            systemManager.stage.displayState = StageDisplayState.FULL_SCREEN;
                            break;
                    }
                } catch (err:SecurityError) {
                   
                }
            }
        ]]>
    </mx:Script>

    <mx:String id="dispState" />
    <mx:Label text="width={Application.application.width}" />
    <mx:Label text="height={Application.application.height}" />
    <mx:Label text="displayState={dispState}" />

    <mx:Button label="Toggle fullscreen" click="toggleFullScreen()" />

</mx:Application>

Notes:

In your HTML wrapper, add the following property:


AC_FL_RunContent(
    "src", "main",
    "width", "100%",
    "height", "100%",
    "align", "middle",
    "id", "main",
    "quality", "high",
    "bgcolor", "#869ca7",
    "name", "main",
    "allowScriptAccess","sameDomain",
    "type", "application/x-shockwave-flash",
    "pluginspage", "http://www.adobe.com/go/getflashplayer",
    "allowFullScreen", "true"
);
Or, if you are using <object /> and <embed /> tags, you can use the following syntax instead:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        id="main" width="100%" height="100%"
        codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
        <param name="movie" value="main.swf" />
        <param name="quality" value="high" />
        <param name="bgcolor" value="#869ca7" />
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="true" />

    <embed src="main.swf" quality="high" bgcolor="#869ca7"
        width="100%" height="100%" name="main" align="middle"
        play="true"
        loop="false"
        quality="high"
        allowScriptAccess="sameDomain"
        allowFullScreen="true"
        type="application/x-shockwave-flash"
        pluginspage="http://www.adobe.com/go/getflashplayer">
    </embed>

</object>

Full Screen Mode Demo

Thursday, November 10, 2011

Generate serial number using labelFunction in datagrid

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;
       
        public function Gridview():void
        {
              numberdata.dataProvider=Xmldata.subnumber;
        }
       
        /* ***************** Serial Number Loading **************** */
        private function serialLabelFunction(item:Object, column:DataGridColumn):String
        {
            var index:int =numberdata.dataProvider.getItemIndex(item);
            if (index > -1)
                return (index + 1).toString();
            
            return "";
        }
    ]]>
</mx:Script>
<mx:XML xmlns="" id="Xmldata">
 <senumber>
<subnumber name="kaniskar" designation="FlexDeveloper"/>
<subnumber name="Banupriya" designation="Auditing"/>
<subnumber name="kaniskar" designation="FlexDeveloper"/>
<subnumber name="Banupriya" designation="Auditing"/>
<subnumber name="kaniskar" designation="FlexDeveloper"/>
<subnumber name="Banupriya" designation="Auditing"/>
<subnumber name="kaniskar" designation="FlexDeveloper"/>
<subnumber name="Banupriya" designation="Auditing"/>
<subnumber name="kaniskar" designation="FlexDeveloper"/>
<subnumber name="Banupriya" designation="Auditing"/>
</senumber>
</mx:XML>
<mx:DataGrid width="500" height="400" id="numberdata" sortableColumns="false">
    <mx:columns>
        <mx:DataGridColumn headerText="SerialNumber" labelFunction="serialLabelFunction"/>
        <mx:DataGridColumn headerText="Name" dataField="@name"/>
        <mx:DataGridColumn headerText="Designation" dataField="@designation"/>
    </mx:columns>
</mx:DataGrid>
    <mx:Button x="416" y="418" label="Load Data" click="Gridview()"/>
</mx:Application>
Output


Thursday, November 3, 2011

Custom Mouse Cursor

Custom Mouse Cursor 


MXMLFile

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/02/01/changing-the-mouse-cursor-when-rolling-over-items-in-an-mx-list-control-in-flex/ -->
<mx:Application name="MX_List_itemRollOver_cursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#C0C0C0, #C5C5C5]">

    <mx:Script>
        <![CDATA[
            import flash.utils.getDefinitionByName;
            import mx.events.ListEvent;

            [Embed("assets/accept.png")]
            public const accept:Class;

            [Embed("assets/anchor.png")]
            public const anchor:Class;

            protected function list_itemRollOverHandler(evt:ListEvent):void {
                var dat:Object = evt.itemRenderer.data;
                trace("Result"+evt.itemRenderer.data);
                if (dat.hasOwnProperty("sample")) {
                    var cursorClass:Class = this[dat.sample] as Class;
                    cursorManager.setCursor(cursorClass);
                }
            }

            protected function list_itemRollOutHandler(evt:ListEvent):void{
                cursorManager.removeAllCursors();
            }
        ]]>
    </mx:Script>
   <mx:Label text="Custom Mouse Cursor" fontSize="18" fontFamily="Arial" fontWeight="bold"/>
    <mx:List id="list"
            itemRollOver="list_itemRollOverHandler(event);"
            itemRollOut="list_itemRollOutHandler(event);" height="292" width="350" fontSize="14" fontFamily="Arial">
        <mx:dataProvider>
            <mx:ArrayCollection>
                <mx:Object label="Wrong cursor" sample="anchor" />
                <mx:Object label="default cursor" />
                <mx:Object label="Wrong cursor" sample="anchor" />
                <mx:Object label="Accept cursor" sample="accept" />
                <mx:Object label="default cursor" />
                <mx:Object label="Accept cursor" sample="accept" />
               
            </mx:ArrayCollection>
        </mx:dataProvider>
    </mx:List>

</mx:Application>

Output:-




Monday, August 29, 2011

Get Unique Value from Array

MXML FILE

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" borderColor="#8E9294"  backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#676767, #464444]">
    <mx:Script>
        <![CDATA[
           
            public var arraydata:Array;
           
            public function retriveUniqueVal():void
            {
                arraydata=new Array(1,2,4,1,"kaniskar",4,5,6,"kaniskar",8,1,2,4,5);   
                removeDuplicates(arraydata);
                outputVal.text=removeDuplicates(arraydata).toString();   
                trace(removeDuplicates(arraydata).toString());           
            }
           
        /* Unique Value function */
       
        public var tempArray:Array;        
        private function removeDuplicates(arr:Array):Array
        {
        var currentValue:String = "";
        tempArray=new Array();
        arr.sort(Array.CASEINSENSITIVE);
        arr.forEach(
        function(item:*, index:uint, array:Array):void {
        if (currentValue != item) {
        tempArray.push(item);
        currentValue= item;
        }
        }
        );
        return tempArray.sort(Array.CASEINSENSITIVE);
        }

        ]]>
    </mx:Script>
    <mx:Button x="429" y="234" label="Take Value" click="retriveUniqueVal()"/>
    <mx:Label x="133" y="181" text="Input Values are:" color="#FFFFFF" fontStyle="normal" fontWeight="normal" fontFamily="Arial" fontSize="16"/>
    <mx:Label x="120" y="231" text="Output Values are:" color="#FFFFFF" fontStyle="normal" fontWeight="normal" fontFamily="Arial" fontSize="16"/>
    <mx:TextInput x="262" y="184" editable="false" id="inputVal" text="1,2,4,1,kaniskar,4,5,6,kaniskar,8,1,2,4,5"/>
    <mx:TextInput x="263" y="234" editable="false" id="outputVal"/>
</mx:Application>

OUTPUT






Tuesday, August 9, 2011

Balloon Tooltip in Graphics

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
    <mx:Script>
        <![CDATA[
            import mx.controls.Label;
           
            public var tip:Canvas;
           
            public function drawballon():void
            {
                    var gindex:int;
                var pt:Point = new Point(80, 43);
                var global:Point = Application.application.localToGlobal(pt);
                var origin:Point =global;
                var destination:Point = new Point(122,0);
                var lineThickness:Number = 2;
                var lineColor:uint = 0xdddddd;
                var lineAlpha:Number = 1;
                //Alert.show(global.toString());
             
                tip=new Canvas();
                var varnameleng:Number;
                tip.name="stylename";
                tip.graphics.clear();
                tip.graphics.beginFill(0xffffff,1);
                tip.graphics.lineStyle(lineThickness,lineColor,lineAlpha);
                tip.graphics.drawRoundRect(70, -70,150,70,40,40);   
                tip.graphics.moveTo(origin.x,origin.y);
                tip.graphics.lineTo(destination.x,destination.y);
                tip.graphics.lineStyle(2,0xffffff,lineAlpha);
                tip.graphics.lineTo(90,0);
                tip.graphics.lineStyle(2,0xbdbdbd,1);
                tip.graphics.lineTo(origin.x,origin.y);
                tip.graphics.endFill();
                checking.addChild(tip)
            
            }
           
            public function clearGraphics():void
            {
                checking.removeChild(tip);
            }
        ]]>
    </mx:Script>
       
    <mx:Canvas x="124" y="120" width="298" height="163" id="checking" >
        <mx:Button label="Show Me" mouseOver="drawballon();" mouseOut="clearGraphics()" x="41" y="53"/>
    </mx:Canvas>
</mx:Application>


Output Image


Tuesday, May 24, 2011

About for, for..in and for each..in Statement

for

The for loop allows you to iterate through a variable for a specific range of values. You must supply three expressions in a for statement: a variable that is set to an initial value, a conditional statement that determines when the looping ends, and an expression that changes the value of the variable with each loop. For example, the following code loops five times. The value of the variable i starts at 0 and ends at 4, and the output will be the numbers 0 through 4, each on its own line.

var i:int;
for (i = 0; i < 5; i++)
{
    trace(i);
} 
 
for..in 
 
The for..in loop iterates through the properties of an object, or the elements of an array. For example, you can use a for..in loop to iterate through the properties of a generic object (object properties are not kept in any particular order, so properties may appear in a seemingly random order):

var myObj:Object = {x:20, y:30}; 
for (var i:String in myObj) 
trace(i + ": " + myObj[i]); 

// output: 
// x: 20
// y: 30 

You can also iterate through the elements of an array:
var myArray:Array = ["one", "two", "three"];
 for (var i:String in myArray)
trace(myArray[i]); 

// output: 
// one
// two 
// three 

What you cannot do is iterate through the properties of an object if it is an instance of a user-defined class, unless the class is a dynamic class. Even with instances of dynamic classes, you will be able to iterate only through properties that are added dynamically.
 
 
for each..in 

The for each..in loop iterates through the items of a collection, which can be tags in an XML or XMLList object, the values held by object properties, or the elements of an array. For example, as the following excerpt shows, you can use a for each..in loop to iterate through the properties of a generic object, but unlike the for..in loop, the iterator variable in a for each..in loop contains the value held by the property instead of the name of the property:

var myObj:Object = {x:20, y:30}; 
for each (var num in myObj) 
{
trace(num); 
}
// output:
// 20 
// 30

You can iterate through an XML or XMLList object, as the following example shows:

var myXML:XML = <users> <fname>Jane</fname> <fname>Susan</fname> <fname>John</fname> </users>;
for each (var item in myXML.fname) 
{
trace(item);
}

/* output Jane Susan John */ 

You can also iterate through the elements of an array, as this example shows:

var myArray:Array = ["one", "two", "three"]; 

for each (var item in myArray) 
{
trace(item);
}

// output: 
// one
// two 
// three

You cannot iterate through the properties of an object if the object is an instance of a sealed class. Even for instances of dynamic classes, you cannot iterate through any fixed properties, which are properties defined as part of the class definition.


For Example

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script
        >
        <![CDATA[
            import mx.controls.Alert;
           
            public function foreachfun():void
            {
                var myArray:Array = ["one", "two", "three"];
                   
                    for each (var item in myArray)
                    {
                        Alert.show(item);
                    }
                   
                }
               
                public function forloopfun():void
                {
                    var myArray:Array = ["one", "two", "three"];
                       
                        for (var i:String in myArray)
                        {
                            Alert.show(myArray[i]);
                        }

                }
                public function xmlfileforeach():void
                {
                    var myXML:XML = <users>
                     <fname>Jane</fname>
                     <fname>Susan</fname>
                     <fname>John</fname>
                      <fname>Susan1</fname>
                     <fname>John1</fname>
                    </users>;
                   
                    for each (var item in myXML.fname)
                    {
                        Alert.show(item);
                    }
                }
               
                public function custom():void
                {
                    var sam:Array=new Array("kaniskar","Banupriya","Banu");
                   
                    for each(var j in sam)
                    {
                        Alert.show(j);
                       
                        if(j=="Banupriya")
                        {
                            trace("True");
                            break;
                        }
                    }
                }
               
               
        ]]>
    </mx:Script>
   
    <mx:Button x="378" y="397" label="For each Loop" click="foreachfun();"/>
    <mx:Button x="378" y="427" label="For Loop" click="forloopfun();"/>
    <mx:Button x="378" y="457" label="For each" click="xmlfileforeach();"/>
        <mx:Button x="378" y="487" label="Break" click="custom();"/>
   
</mx:Application>