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>
 





Monday, April 25, 2011

Editable Tree Node (Single Click Funtion and Right Click Edit)

MXML File
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="functinality();"  layout="absolute" minWidth="1024" minHeight="768" backgroundColor="#FFFFFF">
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
            import mx.controls.Tree;
            import mx.events.ListEvent;
           
             public var parentxml:XML;
           
           
            /* Tree Rename */
           
            [Bindable]
            private var treeData: XML = <tree>
                <node label="First Node">
                    <node label="Business Form_1" id="0" name="first"/>
                    <node label="Business Form_2" name="first"/>
                </node>
   
                </tree>
           
             private var retuxmlstru:XML;
           
         
             public function retuxmlfile():void
              
               {
             
               parentxml= XML(treeControl.selectedItem).parent();
               Alert.show(parentxml);
             
             
               }
               
              protected function tree1_itemEditBeginningHandler(event:ListEvent):void
       
                {
                    event.preventDefault();
           
                         }
                
               private function appComplete (event:ListEvent):void
              
               {
                  
              
                var menu1:RightClickMenu = new RightClickMenu ();
                menu1.AddItem("Edit", function ():void {treeControl.editable=true; Tree( event.target ).editedItemPosition = { columnIndex: 0, rowIndex: event.rowIndex };});
                menu1.AssignRightClick(treeControl);
             
                }  
               
                public function samplecheck(event:ListEvent):void
                {
                    treeControl.editable=false;
                     Alert.show("This is Single Click Function ");
                }
               
                public function functinality():void
                {
                    treeControl.addEventListener(ListEvent.ITEM_CLICK, samplecheck);
                    treeControl.addEventListener(ListEvent.ITEM_EDIT_BEGINNING,tree1_itemEditBeginningHandler)
                }
                    
        ]]>
       
    </mx:Script>
   
      <mx:Tree
        x="0" y="0" width="200" height="100%" id="treeControl"
        labelField="@label"
        showRoot="false"
        itemClick="appComplete(event)"
        itemFocusOut="retuxmlfile()"
        dataProvider="{treeData}"
        >
        </mx:Tree>
   
    <mx:Button x="58" y="476" label="Return XML" click="retuxmlfile()" />
       
       
</mx:Application>


Right Click Menu Component:-
RightClickMenu.as

package
{
    import flash.events.ContextMenuEvent;
    import flash.events.MouseEvent;
    import flash.ui.ContextMenuItem;
   
    import mx.core.Application;
    import mx.core.UIComponent;
   
    public class RightClickMenu
    {
        public var MenuContents:Array = new Array ();
       
        public  function RightClickMenu(){}

        public function AddItem (name:String, func:Function):void
        {
            MenuContents.push({Name:name, Func:func});
        }

        public function AssignRightClick (uiComponent:UIComponent):void
        {
            uiComponent.addEventListener(MouseEvent.MOUSE_OVER, genEnableMenu (uiComponent));
            uiComponent.addEventListener(MouseEvent.MOUSE_MOVE, disableMenu);
        }
       
        /* Assignment */
        private function ResetContextMenu (event:MouseEvent):void
        {    //remove menu
            Application.application.contextMenu.customItems = new Array ();       
            //remove this function
            Application.application.removeEventListener(MouseEvent.MOUSE_MOVE, ResetContextMenu);       
        }
       
        private function disableMenu(event:MouseEvent):void
        {   
            //Stop the mouse move event from propagating to the application level, where we remove the menu
            event.stopImmediatePropagation();           
        }
       
        private function genEnableMenu (uiComponent:UIComponent):Function
        {                       
            return function (event:MouseEvent):void
            {       
                //add event listener to remove the menu on mouse move               
                Application.application.addEventListener(MouseEvent.MOUSE_MOVE, ResetContextMenu);           
               
                //hide current menu
                Application.application.contextMenu.hideBuiltInItems();
               
                //remove menu (ifyou right click and then move, this may not be killed.
                Application.application.contextMenu.customItems = new Array ();               
               
                //create new menu
                for (var i:Number in MenuContents)
                {
                    var menuItem:ContextMenuItem = new ContextMenuItem(MenuContents[i].Name);
                    menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, MenuContents[i].Func);                                       
                    Application.application.contextMenu.customItems.push(menuItem);   
                }   
            }           
        }
       
        private function genClickCall (func:Function):Function
        {
            return function (event:ContextMenuEvent):void
            {   
                func()
                ResetContextMenu(null);
            }

        }

    }
}

Your File Keep in this Format;

Output:-



After Edit Node Return XML




Tuesday, March 29, 2011

Server side connection in flex using php

MXML File

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#4D4B4B, #626060]">
<mx:Style source="assets/css/style.css"/>
<mx:Script>
    <![CDATA[
        import mx.managers.PopUpManager;
        import mx.controls.Text;
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import mx.controls.Alert;

     [Bindable]
     public var newuserloginDetail:NewuserLogin;
     public var alertmsgbox:alertpopup;
     public var displayhos:HospitalL2details;
     public var saml:XML;
    
     public function loginpage(evt:ResultEvent):void
     
     {
   
    if(evt.result.loginsuccess == "yes")

    {
        errorlogin.text="";
        username.text="";
          password.text="";
        displayhos=new HospitalL2details();
        this.addChild(displayhos);
    
     }

    if(evt.result.loginsuccess == "no")

     {
      username.text="";
      password.text="";
      errorlogin.text="Invalid username / password";

      }
       
     }
     
          private function login():void
   
      {
          loginHTTPservice.send();
      }
         
   
   
   
     public function createnewuser(evt:ResultEvent):void
     
     {
        
         if(evt.result.newuser == "Error")

    {
        newuserloginDetail.errormsg2.text="Error";
    
     }

    if(evt.result.newuser == "Successfully Created")

     {
     newuserloginDetail.errormsg2.text="Successfully Created";
     alertmsgbox=new alertpopup();
     PopUpManager.addPopUp(alertmsgbox,this,true);
     PopUpManager.centerPopUp(alertmsgbox);
      }
     
     }
     
     public function removemsgpopup():void
     
     {
     PopUpManager.removePopUp(alertmsgbox);   
     }
     
      public function removeallpopup():void
     
     {
     PopUpManager.removePopUp(alertmsgbox);   
      PopUpManager.removePopUp(newuserloginDetail);   
     }
     
     
     public function newuser():void
   
      {
          if(newuserloginDetail.newpassword.text != newuserloginDetail.newpassword1.text || newuserloginDetail.fname.text=="" || newuserloginDetail.lname.text=="" || newuserloginDetail.newpassword.text=="" || newuserloginDetail.newpassword1.text=="")
          {
             
            }
           
            else {
         
          createnewuserrequest.send();
           
            }
      }
     
      private function cleartexfield():void
      {
          errorlogin.text="";
          username.text="";
          password.text="";
      }   
     
      private function fault(evnt:FaultEvent):void
     
      {
          displayerrorHTTP.text=evnt.fault.faultString+'\n'+evnt.fault.faultCode+'\n'+evnt.fault.faultDetail;
      }
     
      public function newuserlogindis():void
     
      {
          newuserloginDetail=new NewuserLogin();
          PopUpManager.addPopUp(newuserloginDetail,this,true);
          PopUpManager.centerPopUp(newuserloginDetail);
     }
     
      public function romovepopupnewuser():void
      {
          PopUpManager.removePopUp(newuserloginDetail);
      }
      

    ]]>
   
</mx:Script>

<mx:HTTPService url="http://localhost/passwordresult/passoutput.php" useProxy="false" fault="fault(event)" result="loginpage(event)" method="POST" id="loginHTTPservice">

<mx:request xmlns="">
    <usernameres>{username.text}</usernameres>
    <passwordres>{password.text}</passwordres>
</mx:request>

</mx:HTTPService>

<mx:HTTPService url="http://localhost/passwordresult/newusercreate.php" method="POST" useProxy="false" result="createnewuser(event)" fault="fault(event)" id="createnewuserrequest">
   
    <mx:request xmlns="">
    <newusername>{newuserloginDetail.lname.text}</newusername>
    <newuserpass>{newuserloginDetail.newpassword.text}</newuserpass>
    </mx:request>
   
</mx:HTTPService>

    <mx:Panel x="406" y="241" width="453" height="287" layout="absolute" title="Login Page">
        <mx:Label x="52" y="59" text="User Name:" fontFamily="Arial" fontSize="13" fontWeight="bold"/>
        <mx:Label x="61" y="119" text="Password:" fontSize="13" fontFamily="Arial" fontWeight="bold"/>
        <mx:TextInput x="166" y="57" id="username"/>
        <mx:TextInput x="166" y="117" id="password" displayAsPassword="true"/>
        <mx:Button x="166" y="188" label="Submit" click="login()"/>
        <mx:Button x="271" y="188" label="Clear" click="cleartexfield();"/>
        <mx:Label x="20" y="219" text="New User Login" fontWeight="bold" buttonMode="true" useHandCursor="true" color="#0C8FAB" textDecoration="underline" click="newuserlogindis();"/>
        <mx:Label x="166" y="153" id="errorlogin" width="257" color="#ED1807"/>
    </mx:Panel>
    <mx:Label x="406" y="536" id="displayerrorHTTP" width="225" height="58" color="#FFFFFF"/>
   
</mx:Application>

HospitalL2details.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" backgroundColor="#4C4B4B">
<mx:Script>
    <![CDATA[
        import mx.core.Application;
        public function removethiscontainer():void
       
        {
            Application.application.removeChild(this);
        }
       
    ]]>
</mx:Script>

    <mx:Label x="24" y="14" text="Hospital Details" color="#F9FCFD" fontSize="16" fontFamily="Arial" fontWeight="bold"/>
    <mx:Label  right="10" y="19" buttonMode="true"  text="Logout" color="#FEFEFE" fontWeight="bold" fontFamily="Arial" fontSize="12" click="removethiscontainer();"/>
    <mx:Panel  left="10" right="10" top="64" y="57" width="100%" bottom="10" height="100%" layout="absolute" styleName="topspacepanel">
    </mx:Panel>
   
</mx:Canvas>

NewuserLogin.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="428" styleName="Panelcol" height="408" layout="absolute" borderColor="#6E6F6F">

<mx:Script>
    <![CDATA[
        import mx.core.Application;
       
       
        public function validationtext():void
       
        {
            if(fname.text=="" || lname.text=="" || newpassword.text=="" || newpassword1.text=="")
           
            {
              errormsg.text="Fill the All Fileds";   
            }
            else
            {
               
                errormsg.text="";   
            }
       
        }
       
        public function validationtext1():void
        {
           
           
            if(newpassword.text != newpassword1.text || newpassword.text=="")
           
            {
                errormsg1.text="Please Enter Same Password";
            }
            else
            {
                 
              errormsg1.text="";   
            }
        }
       
        public function cleartextfield():void
       
        {
            fname.text="";
            lname.text="";
            newpassword.text="";
            newpassword1.text="";
        }
       
       
    ]]>
</mx:Script>


    <mx:Label text="Name" x="30" y="53" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="User Name" x="30" y="99" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="Password" x="32" y="150" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Label text="Conform Password" x="30" y="204" fontSize="13" fontWeight="normal" fontFamily="Arial"/>
    <mx:Button x="180" y="273" label="Submit" click="validationtext(),validationtext1(),Application.application.newuser(),cleartextfield();"/>
    <mx:Button x="281" y="273" label="Clear" click="cleartextfield();"/>
    <mx:TextInput x="180" y="54" id="fname"/>
    <mx:TextInput x="180" y="100" id="lname"/>
    <mx:TextInput x="180" y="151" displayAsPassword="true" id="newpassword"/>
    <mx:TextInput x="180" y="203" displayAsPassword="true" id="newpassword1"/>
    <mx:Label x="317" y="8" text="Close Window" fontWeight="bold" useHandCursor="true" buttonMode="true" color="#0C8FAB" textDecoration="underline" click="Application.application.romovepopupnewuser();"/>
    <mx:Label x="9" y="7" text="New User Login" fontWeight="bold" useHandCursor="true" color="#4D6F05" textDecoration="normal" fontSize="14" fontFamily="Arial"/>
    <mx:Label x="176" y="327" width="173" height="20" color="#F43705" id="errormsg"/>
    <mx:Label x="10" y="233" width="173" height="20" color="#F43705" id="errormsg2"/>
    <mx:Label x="177" y="177" width="173" height="20" color="#F43705" id="errormsg1"/>
    <mx:Image source="assets/images/newuser.jpg" width="100" height="96" x="30" y="251"/>
</mx:Panel>


alertpopup.MXML Component

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="272" height="118">
<mx:Script>
    <![CDATA[
            import mx.core.Application;
    ]]>
</mx:Script>
    <mx:Panel width="100%" height="100%" styleName="topspacepanel" layout="absolute">
        <mx:Label text="Do you want to create new user" x="8" y="39" fontWeight="bold"/>
        <mx:Label text="Successfully Created" x="58" y="11" fontWeight="bold" fontSize="12" color="#FC0D0D"/>
        <mx:Button x="55" y="68" label="Yes" click="Application.application.removemsgpopup();" />
        <mx:Button x="140" y="68" label="No" click="Application.application.removeallpopup();" />
       
    </mx:Panel>
</mx:Canvas>


style.CSS

/* CSS file */
.Panelcol {
   borderColor: #6e6f6f;
   borderAlpha: 1;
   borderThicknessLeft: 10;
   borderThicknessTop: 0;
   borderThicknessBottom: 11;
   borderThicknessRight: 10;
   roundedBottomCorners: true;
   cornerRadius: 9;
   headerHeight: 22;
   backgroundAlpha: 1;
   highlightAlphas: 0.5, 0;
   backgroundColor: #ffffff;
   dropShadowEnabled: true;
   shadowDistance: 2;
   shadowDirection: left;
}

.topspacepanel

{
   borderAlpha: 0.59;
   borderThicknessLeft: 5;
   borderThicknessTop: 0;
   borderThicknessBottom: 4;
   borderThicknessRight: 4;
   roundedBottomCorners: false;
   cornerRadius: 0;
   headerHeight: 5;
   backgroundAlpha: 1;
   highlightAlphas: 0.06, 0.19;
   dropShadowEnabled: true;
   shadowDistance: 2;
   shadowDirection: left;


}
Your file keep in this Format



Server Side Files
passoutput.php

<?php
$serv ='localhost';
$usern ='root';
$passw ='';
$databasename = 'flexsample';

$sqlcon = mysql_connect($serv, $usern, $passw) or die(mysql_error());
mysql_select_db($databasename);

$username=mysql_real_escape_string($_POST["usernameres"]);
$password=mysql_real_escape_string($_POST["passwordres"]);

$query = "SELECT * FROM hospitallogin WHERE username = '$username' AND pass = '$password'";
$result = mysql_fetch_array(mysql_query($query));

$output = "<loginsuccess>";

if(!$result)
{
$output .= "no";       
}
else{
$output .= "yes";   
}

$output .= "</loginsuccess>";

//output all the XML
print ($output);
mysql_close($sqlcon);

?>
newusercreate.PHP

<?php
$lhoste='localhost';
$uname='root';
$passval='';
$DatabaseN='flexsample';

$sqlcon = mysql_connect($lhoste, $uname, $passval) or die(msql_error());
mysql_select_db($DatabaseN);

$newusername = mysql_real_escape_string($_POST['newusername']);
$newpasdwod = mysql_real_escape_string($_POST['newuserpass']);

$query = "INSERT INTO hospitallogin VALUES('$newusername','$newpasdwod')";
$result = mysql_fetch_array(mysql_query($query));

$output = "<newuser>";

if(!$result)
{
$output .= "Successfully Created";
}
else{
$output .= "Error";
}

$output .= "</newuser>";
print ($output);
mysql_close($sqlcon);
?>

MYSQL  FORMAT




Output Screen Shots