A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Photo in DataGrid? Includes code so far...

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    400

    resolved [RESOLVED] Photo in DataGrid? Includes code so far...

    I'm flummoxed and I'm on deadline. I can go without a solution but I'd sure like to be able to get photos in here. So, many thanks in advance!

    I have a datagrid being fed by an xml file. That works great. Here's the xml...

    PHP Code:
    <players>
    <
    player playerphoto="bear.jpg" playername="Smokey"/>
    <
    player playerphoto="lion.jpg" playername="Leo"/>
    </
    players
    I have the DataGrid showing up and displaying everything but the photos. The datagrid looks like it's adjusting it's size to accommodate the photos but the never actually displays. I'm trying to load Adobe's "LoaderCellRenderer" class. I'm kinda new to all the Class stuff so I'm wondering if I'm loading the class wrong? Anyway, here's that Flash code...

    PHP Code:
    import fl.controls.dataGridClasses.DataGridColumn
    import fl.data.DataProvider
    import flash.net.*; 
    import flash.events.*; 
     
    var 
    request:URLRequest = new URLRequest("players.xml"); 
    var 
    loader:URLLoader = new URLLoader
      
    loader.load(request); 
    loader.addEventListener(Event.COMPLETEloaderCompleteHandler); 
     
    function 
    loaderCompleteHandler(event:Event):void 
     
        var 
    playersXML:XML = new XML(loader.data); 
     
        var 
    photoCol:DataGridColumn = new DataGridColumn("playerphoto"); 
        
    photoCol.headerText "Photo"
        
    photoCol.width 120
        
    photoCol.cellRenderer LoaderCellRenderer;
        
        var 
    nameCol:DataGridColumn = new DataGridColumn("playername"); 
        
    nameCol.headerText "Name"
        
    nameCol.width 60
         
        var 
    myDP:DataProvider = new DataProvider(playersXML); 
         
        
    aDg.columns = [photoColnameCol]; 
        
    aDg.width 200
        
    aDg.dataProvider myDP
        
    aDg.rowCount aDg.length

    As mentioned above, I'm using Adobe's LoaderCellRenderer class. Here's that code...

    PHP Code:
    package {

        
    import fl.containers.UILoader;

        
    import fl.controls.listClasses.ICellRenderer;

        
    import fl.controls.listClasses.ListData;

        
    import fl.core.InvalidationType;

        
    import fl.data.DataProvider;

        
    import flash.events.Event;



        public class 
    LoaderCellRenderer extends UILoader implements ICellRenderer {

            protected var 
    _data:Object;

            protected var 
    _listData:ListData;

            protected var 
    _selected:Boolean;



            public function 
    LoaderCellRenderer():void {

                
    super();

            }



            public function 
    get data():Object {

                return 
    _data;

            }

            public function 
    set data(value:Object):void {

                
    _data value;

                
    source value.data;

            }



            public function 
    get listData():ListData {

                return 
    _listData;

            }

            public function 
    set listData(value:ListData):void {

                
    _listData value;

                
    invalidate(InvalidationType.DATA);

                
    invalidate(InvalidationType.STATE);

            }



            public function 
    get selected():Boolean {

                return 
    _selected;

            }

            public function 
    set selected(value:Boolean):void {

                
    _selected value;

                
    invalidate(InvalidationType.STATE);

            }



            public function 
    setMouseState(state:String):void {

            }

        }



  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You had a couple of mistakes. This is the new script. You forgot to connect to the Renderer class. Then the attributes, and that is mandatory, have to be data for the image url and title for the title.
    PHP Code:
    function loaderCompleteHandler (event:Event):void
    {

        var 
    playersXML:XML = new XML(event.currentTarget.data);
        var 
    photoCol:DataGridColumn = new DataGridColumn("data");//has to be data
        
    photoCol.headerText "Photo";
        
    photoCol.width 120;
        
    photoCol.cellRenderer LoaderCellRenderer;//you forgot this line.

        
    var nameCol:DataGridColumn = new DataGridColumn("title");//has to be title
        
    nameCol.headerText "Name";
        
    nameCol.width 60;

        var 
    myDP:DataProvider = new DataProvider(playersXML);
        var 
    aDg:DataGrid = new DataGrid();
        
    aDg.columns = [photoColnameCol];
        
    aDg.width 200;
        
    aDg.rowHeight 64;
        
    aDg.dataProvider myDP;
        
    aDg.rowCount aDg.length;
        
    addChild (aDg);

    PHP Code:
    <players>
    <
    player data="bear.jpg" title="Smokey"/>
    <
    player data="lion.jpg" title="Leo"/>
    </
    players
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    Happy Friday to me!

    Thanks cancerinform!

  4. #4
    Senior Member
    Join Date
    Jun 2002
    Posts
    400
    Follow-up question...

    What if I want to add a second picture to the row? I can't have two attributes called "data" in an XML file, right? If so, I assume Flash can't tell the difference when I refer to "data", right? So I did this...
    PHP Code:
    <players>
    <
    player data="bear.jpg" playername="Smokey" secondphoto="lion.jpg"/>
    <
    player data="lion.jpg" playername="Leo" secondphoto="bear.jpg"/>
    </
    players
    I added this to the code...
    PHP Code:
        var secondPhotoCol:DataGridColumn = new DataGridColumn("secondPhoto"); 
        
    secondPhotoCol.headerText "Photo 2"
        
    secondPhotoCol.width 90
        
    secondPhotoCol.cellRenderer LoaderCellRenderer
    but it displays the same picture twice. The one from the first photoCol, the one referenced by the first "data" attribute...

    Thanks again.
    Last edited by LayneSmith; 02-27-2009 at 12:17 PM.

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You cannot do that because the variables you are using will not be recognized and you can use data as attribute only once.
    - The right of the People to create Flash movies shall not be infringed. -

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center