October 29th, 2007 by Kyle
Posted in: Flex, mxml

I have come across a few cases where it was useful to have the column and row positions within an itemRenderer and so have made this sample to demonstrate how to do that.

Here is the application code:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  >
    <mx:Script>
        <![CDATA[
            import mx.events.DataGridEvent;
            import mx.collections.ArrayCollection;
           
            private static var object1:Object = new Object();
                                object1.name = "Object 1";
           
            private static var object2:Object = new Object();
                                object2.name = "Object 2";
               
            private static var object3:Object = new Object();
                                object3.name = "Object 3";

            private static var object4:Object = new Object();
                                object4.name = "Object 4";
                               
            private static var object5:Object = new Object();
                                object5.name = "Object 5";

            private static var object6:Object = new Object();
                                object6.name = "Object 6";

            private static var object7:Object = new Object();
                                object7.name = "Object 7";

            private var things:Array = [object1, object2, object3, object4, object5, object6, object7];
           
            [Bindable]
            public var thingsAC:ArrayCollection = new ArrayCollection(things);
           
        ]]>
    </mx:Script>

       

    <mx:DataGrid id="dg" width="510" height="100"
         draggableColumns="false" dataProvider="{thingsAC}"
         horizontalScrollPolicy="on"
         rowCount="4">
        
        <mx:columns>
            <mx:DataGridColumn width="200" headerText="Name" dataField="name"  />         
            <mx:DataGridColumn width="200" headerText="Column 2" itemRenderer="MyIR" />
            <mx:DataGridColumn width="200" headerText="Column 3" itemRenderer="MyIR" />
            <mx:DataGridColumn width="200" headerText="Column 4" itemRenderer="MyIR" />
        </mx:columns>
    </mx:DataGrid>

</mx:Application>
 

Here is the code for my itemRenderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center"
    implements="mx.controls.listClasses.IDropInListItemRenderer"
    preinitialize ="init();">
   
    <mx:Script>
    <![CDATA[
        import mx.controls.DataGrid;
        import mx.controls.dataGridClasses.DataGridListData;
        import mx.controls.listClasses.BaseListData;
        import flash.events.Event;   
        import mx.collections.ArrayCollection;       
   
        [Bindable]
        public var _lbl:String;
       
        private function onChange(event:Event):void{
            var myListData:DataGridListData = DataGridListData(listData);
        }
   
        private var _listData:BaseListData;
        private var myDG:DataGrid;

        public function get listData():BaseListData {
          return _listData;
        }
        public function set listData( value:BaseListData ):void {
            _listData = value;
            myDG = _listData.owner as DataGrid;
           
        }  
   
        public function init():void {
            addEventListener("dataChange", handleDataChanged);
        }   

        public function handleDataChanged(event:Event):void {
            // Cast listData to DataGridListData.
            var myListData:DataGridListData = DataGridListData(listData);
 
            var row:int=myListData.rowIndex+myDG.verticalScrollPosition;
            //to make 1 based
            var col:int=myListData.columnIndex+1;

            _lbl="row: " + String(row) +
                " column: " + String(col);
                 
        }   
       
               
        ]]>
    </mx:Script>
    <mx:Label id="lbl" text="{_lbl}"/>
</mx:VBox>
 

Here is the running application:

This movie requires Flash Player 9

Browse the source of this example.
Download a zipfile containing the source to this sample.


No Comments »

October 26th, 2007 by Kyle
Posted in: Flex, mxml

I was helping a customer with a simple sample and couldn’t find one that was specifically what I needed. The docs did have a sample for filtering an arraycollection bound to a combobox (I think) and this wasn’t much of a stretch, but I thought it would be useful to post the sample for the datagrid scenario so that it was no stretch.

Here is the application code:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
    <mx:Script>
        <![CDATA[
            import mx.collections.*;
            import mx.events.ItemClickEvent;             
   
            private var selectedRegion:String;
   
            public function regionFilterFunc(item:Object):Boolean {
                if (selectedRegion=="all")
                    return true
                else
                    return item.region == selectedRegion;
            }
           
            // Function to apply the filter function the ICollectionView.
            public function filterAC(event:ItemClickEvent):void {
                selectedRegion=event.label;
                myAC.filterFunction=regionFilterFunc;
                //Refresh the collection view to apply the filter.
                myAC.refresh();
            }

        ]]>
    </mx:Script>

    <!– An ArrayCollection with an array of objects. –>
    <mx:ArrayCollection id="myAC">
        <mx:Array id="myArray">
            <mx:Object state="LA" city="Baton Rouge" region="west"/>
            <mx:Object state="NH" city="Concord" region="east"/>
            <mx:Object state="TX" city="Austin" region="west"/>
            <mx:Object state="MA" city="Boston" region="east"/>
            <mx:Object state="AZ" city="Phoenix" region="west"/>
            <mx:Object state="OR" city="Salem" region="west"/>
            <mx:Object state="FL" city="Tallahassee" region="east"/>
            <mx:Object state="MN" city="Saint Paul" region="east"/>
            <mx:Object state="NY" city="Albany" region="east"/>
        </mx:Array>   
    </mx:ArrayCollection>

    <mx:ToggleButtonBar id="tbb" horizontalGap="5" itemClick="filterAC(event);">
            <mx:dataProvider>
                <mx:Array>
                    <mx:String>all</mx:String>               
                    <mx:String>east</mx:String>
                    <mx:String>west</mx:String>
                </mx:Array>
            </mx:dataProvider>
        </mx:ToggleButtonBar>

    <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{myAC}">
        <mx:columns>
            <mx:DataGridColumn dataField="state" headerText="State"/>
            <mx:DataGridColumn dataField="city" headerText="City"/>
            <mx:DataGridColumn dataField="region" headerText="region"/>
        </mx:columns>
    </mx:DataGrid>

</mx:Application>
 

Here is the running sample:

This movie requires Flash Player 9

Browse the source of this example.
Download a zipfile containing the source to this sample.


No Comments »

October 23rd, 2007 by Kyle
Posted in: Flex, mxml

I can’t count the number of times upon starting to work on a datagrid issue that I turn to the flex docs and copy the code sample at the bottom of the Datagrid API page. Then I usually search around for a simple sample of an itemRenderer that fits my needs. I decided it was high time I posted a simple sample that combined those needs into one sample and was located in an easy place for me and everyone else to find…my blog.

Here is the sample code for the app:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:XMLList id="employees">
        <employee>
            <name>Christina Coenraets</name>
            <phone>555-219-2270</phone>
            <email>ccoenraets@fictitious.com</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Joanne Wall</name>
            <phone>555-219-2012</phone>
            <email>jwall@fictitious.com</email>
            <active>true</active>
        </employee>
        <employee>
            <name>Maurice Smith</name>
            <phone>555-219-2012</phone>
            <email>maurice@fictitious.com</email>
            <active>false</active>
        </employee>
        <employee>
            <name>Mary Jones</name>
            <phone>555-219-2000</phone>
            <email>mjones@fictitious.com</email>
            <active>true</active>
        </employee>
    </mx:XMLList>      

   
    <mx:DataGrid dataProvider="{employees}" width="600" height="400" editable="true">
        <mx:columns>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
            <mx:DataGridColumn headerText="Phone" dataField="phone"/>
            <mx:DataGridColumn headerText="Email" dataField="email" itemRenderer="EmailRenderer" />
        </mx:columns>
    </mx:DataGrid>

</mx:Application>
 

Here is the code for the itemrenderer:

<?xml version="1.0" encoding="utf-8"?>
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml"
    width="100%" height="100%" paddingLeft="3"
    fontWeight="{currentWeight}" fontStyle="{currentStyle}" >

    <mx:Script>
        <![CDATA[
       
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.listClasses.BaseListData;
            import mx.events.FlexEvent;

            private var _listData:DataGridListData;  
            [Bindable]
            private var currentWeight:String = "normal";
            [Bindable]
            private var currentStyle:String = "normal";

            [Bindable]
            override public function set data(value:Object):void{
                super.data = value;
                if(data){
                    currentStyle = (data.active == "false" ? "italic" : "normal");       
                }   
                dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
            }
           
            override public function get data():Object {
                return super.data;
            }

            [Bindable("dataChange")]
            override public function get listData():BaseListData
            {
                return _listData;
            }
       
            override public function set listData(value:BaseListData):void
            {
                _listData = DataGridListData(value);
                text=_listData.label;
                currentWeight = _listData.label == "ccoenraets@fictitious.com" ? "bold" : "normal";
                if(data){
                    currentStyle = (data.active == "false" ? "italic" : "normal");       
                }   
            }         
        ]]>
    </mx:Script>
</mx:Label>
 

Here is the running app:

This movie requires Flash Player 9

Browse the source of this example.
Download a zipfile containing the source to this sample.


No Comments »

October 17th, 2007 by Kyle
Posted in: Flex, actionscript

I recently had an issue from a customer regarding figuring out the correct syntax to get at a few nodes in an XML object that had namespaces using e4x. Now I don’t know about you, but if I don’t use e4x often, I forget things and get rusty. If your e4x-foo is weak, here are a few references that I found useful:

http://www.darronschall.com/weblog/archives/000223.cfm
(In fact Darren has a few e4x entries aside from this one.)

http://www.partlyhuman.com/blog/roger/as3-e4x-rundown

Hope this helps,

-Kyle


No Comments »

October 11th, 2007 by Kyle
Posted in: Flex, Flash Player

I had seen references describing how to do this, but hadn’t seen a complete example, so I whipped this one up for a customer.

Using RemoteClass metadata triggers code gen in in the compilter to ensure that the class is registered with the VM before the application can use it, this includes receiving it from a network request. The only case in which this could be a problem is if it was being used with remoting and there wasn’t a corresponding server class that also implemented the flash.utils.IExternalizable interface.

Externalizable interface doesn’t effect the ability to be serialized in AS3, it just provides customization of what gets serialized. Generally it is only used to serialize private data or hide public data from serialization. Marking the class with [RemoteClass] is what allows the typed serialization of the object (again just mxmlc code gen at the right point using the registerClassAlias() method).

There aren’t any issues, at least none that we have hit, with LSO storage and custom serialization using IExternalizable. As long as the SWF that is retrieving the data from the LSO has the IExternalizable classes linked in and registered (potentially with a “dummy variable”) then I don’t know of any reason why that wouldn’t work.

The real work behind the scenes is done by using flash.net.registerClassAlias() and it is documented (although hard to find) at:
http://livedocs.adobe.com/flex/201/html/lsos_087_3.html

Browse the source of this example.
Download a zipfile containing the source to this sample.

This movie requires Flash Player 9

Read the rest of this post»


No Comments »

October 8th, 2007 by Kyle
Posted in: Flex, actionscript

I had a customer that was trying to use masking to make menus appear with rounded corners. I had gotten this to work, but there was something I could not figure out that caused a flicker as menus were selected and appeared. I put this on the back shelf for a while and recently revisited it. To my surprise, the issue I had previously seen had gone away. Either something in the Flex framework had changed or a more recent version of the player had a beneficial effect. Whatever the cause, I decided it was good enough and that I should post this code.

In this sample, I extended the default MenuBar, so I could get a handle on new menus as they are shown to apply the mask. I also implemented a new style “corner-radius” and a custom menuItem renderer.

Browse the source of this example.
Download a zipfile containing the source to this sample.

This movie requires Flash Player 9

Read the rest of this post»


1 Comment »

October 4th, 2007 by Kyle
Posted in: Flex

I had a customer that was wondering how they could close all the popup windows in one fell swoop. They knew they could keep track of each popup they created in say an array, then when they wanted to close them all, they could just iterate the array and close each one, but there must be a better way. And there is!

The code and sample below show how to do this. Check the code comments for some interesting details.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
    viewSourceURL="wp-content/code/Flex2.0.1hf2/739stl_CloseAllPopUps/srcview/index.html">
    <mx:Script>
        <![CDATA[
            import mx.managers.PopUpManager;
            import mx.managers.PopUpManagerChildList;

            private function openPopup(popUpScope:String):void{
                var pop:Popup = Popup(PopUpManager.createPopUp(this,Popup,false,popUpScope));
            }
           
            private function closeAll():void{
                // if you scope your popups to PopUpManagerChildList.POPUP
                // this is all you should have to check to clear all popups
                while(systemManager.popUpChildren.numChildren > 0){
                    PopUpManager.removePopUp(Popup(systemManager.popUpChildren.getChildAt(0)));
                }
                // if you scope your popups to other than PopUpManagerChildList.POPUP
                // you need to scan this and check the class name to decide if you need to remove the child
                for (var i:int = systemManager.numChildren-1;i>=0;i–){
                    trace(getQualifiedClassName(systemManager.getChildAt(i)));
                    if(getQualifiedClassName(systemManager.getChildAt(i))==‘Popup’){
                        systemManager.removeChildAt(i);
                    }
                }
            }
     
        ]]>
    </mx:Script>
    <mx:Button label="open popup - PopUpManagerChildList.POPUP" click="openPopup(PopUpManagerChildList.POPUP)" />
    <mx:Button label="open popup - PopUpManagerChildList.APPLICATION" click="openPopup(PopUpManagerChildList.APPLICATION)" />
    <mx:Button label="open popup - PopUpManagerChildList.PARENT" click="openPopup(PopUpManagerChildList.PARENT)" />
   
    <mx:Button label="close all" click="closeAll()" /> 

</mx:Application>

 

Browse the source of this example.
Download a zipfile containing the source to this sample.

This movie requires Flash Player 9

Here is the simple popup that I use:

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
    width="400" height="300" x="100" y="100" showCloseButton="true" >

    <mx:Text text="PopUp"/>

</mx:TitleWindow>
 


No Comments »

October 1st, 2007 by Kyle
Posted in: Flex, Coldfusion

This issue came to me from a customer who wanted to catch the timeout of a webservice and then repeatedly re-dispatch the same webservice passing the parameters/data from the original call, but with a larger timeout, until some max timeout or max number of tries was reached.

Read the rest of this post»


No Comments »


Professional Medicines, Online Pharmacy buy clomid buy viagra buy cialis buy tramadol buy soma buy levitra buy propecia buy ultram buy acomplia buy phentermine buy xenical buy kamagra Online Pharmacy Products
cialis consultation delivery discount health man cialis cialis forum cialis side eefects low cost generic generic cialis pills effectiveness viagra levitra cialis cheapest generic viagra and cialis pills cat 6 cialis bargain levitra levitra cialis dysfunction erectile levitra viagra 2003 cyalis levitra market sales viagra clarinex stimula levitra aldara pay pal order diflucan viagra, cialis, levitra, diflucan, clomid buy generic soma dream levitra online order pharmaceutical zithromax price soma prescriber information soma aura soma color therapy essences soma carisoprodol 350mg soma restaurant scottsdale buy pfizer viagra viagra buying online story viagra viagra before and after viagra substituts modo de empleo viagra viagra suppositories side effects viagra testemonials viagra videos