Search code examples
actionscript-3apache-flexdatagridflex4

flex, defined type, get data, grid


I have a data type defined like this and i want to use it in the flex4.6 dataGrid.

package data
{
    [Bindable]
    public class GridDataItem{
        protected var avatar:String;
        protected var name:String;
        protected var email:String;

        public function GridDataItem(avatar:String, name:String,email:String){
            this.avatar = avatar;
            this.name = name;
            this.email = email;
        }
    }
}

but i wondering how to reference one property in it. beside this i also want to set the source picture which is saved as avatar in this datatype object, and the first column will display the avatar for each row .

anyone have any ideas ? thx million.


Solution

  • You can add public setters and getters within the class like below.

    package data
    {
        [Bindable]
        public class GridDataItem{
        protected var _avatar:String;
        protected var _name:String;
        protected var _email:String;
    
        public function GridDataItem(avatar:String, name:String,email:String){
            this.avatar = avatar;
            this.name = name;
            this.email = email;
        }
    
        public function set avatar(String av):void{
            this._avatar = av;
        }
    
        public function get avatar():String{
            return this._avatar;
        }
        .
        .
        .
    }
    

    beside this i also want to set the source picture which is saved as avatar in this datatype object, and the first column will display the avatar for each row

    If I understood this question right, I'll set the url of the image in the avatar property of the griditem data type. Use custom Item rendered in the first column, use Image class within the itemrenderer to bind to this avatar property.