A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [Flex] simple datagrid

  1. #1
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429

    [Flex] simple datagrid

    Howdy,

    I'm trying to get familiar with the datagrid component in flex. Where I'm lost is how I connect to external data. Most likely, the data will all be passed through FlashVars so the movie will need only read vars from its embed tag.

    Can someone explain how I would do that?
    Thanks.

  2. #2
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    I think you may have to be a bit more specific as to what you want to do. You can access url params/flashvars in an MXML Application through the Application.application.parameters object.

  3. #3
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Sorry, I just opened Flex for the first time the other day. I'm fluent in AS2.0 so it's not a huge leap but it is quite new to me.
    I'm creating a store for sounds and the datagrid will be used to display search results. Two of the cells in each row need a custom button graphic w/ link but I'll start another thread for that.

    I've talked to my backend developer and I will actually need to do the equivilent of a LoadVars.sendAndLoad() to get the data I'm looking for. I'll just be calling a php page and sending it some vars, I will then need to parse the results. Is it stupid to that with anything but an XMLList object? I prefer to just loop over an array created from a split string but not if there is a better way.

  4. #4
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    I would use XML personally, but a simple parsed string would do as well. With XML, all you would have to do is set the dataProvider of the grid. In any case, here is a long winded AS3 sendAndLoad equiv (havn't checked syntax so there may be some typos &c):

    var search_request : URLRequest = new URLRequest ("search.php");

    var search_variables : URLVariables = new URLVariables ();

    search_variables.filter = "search filter";

    search_request.data = search_variables;

    var search_loader : URLLoader = new URLLoader (search_request);

    search_loader.addEventListener (Event.COMPLETE, searchCompleteHandler);

    function searchCompleteHandler (event : Event) : void {
    trace (search_loader.data);
    //total=2&img0=1.jpg&link0=1.htm&img1=2.jpg&link1=2. htm

    var result_variables : URLVariables = new URLVariables (search_loader.data);

    var soundsLen : uint = result_variables.total;
    for (var sound : uint; sound < soundsLen; sound++) {
    var img : String = result_variables["img" + sound];
    var link : String = result_variables["link" + sound];
    // add item to grid / data provider
    }
    }
    Last edited by gSOLO_01; 08-22-2006 at 02:51 PM.

  5. #5
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Omg, you just saved me a whole day! Thank you soo much.

    Not suprisingly I have a few questions.
    I can see why you would use XML. There is a really cool sample in the datagrid language reference that simply connects to an XMLlist as a dataprovider.
    Code:
            <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{employees}">
                <mx:columns>
                    <mx:DataGridColumn dataField="name" headerText="Name"/>
                    <mx:DataGridColumn dataField="phone" headerText="Phone"/>
                    <mx:DataGridColumn dataField="email" headerText="Email"/>
                </mx:columns>
            </mx:DataGrid>
    then connects some form fields to display the selected datagrid row

    Code:
    <mx:Form width="100%" height="100%">
                <mx:FormItem label="Name">
                    <mx:Label text="{dg.selectedItem.name}"/>
                </mx:FormItem>
                <mx:FormItem label="Email">
                    <mx:Label text="{dg.selectedItem.email}"/>
                </mx:FormItem>
                <mx:FormItem label="Phone">
                    <mx:Label text="{dg.selectedItem.phone}"/>
                </mx:FormItem>
            </mx:Form>
    This seems so cool to me because I didn't have to set up any listeners and everything just 'works'. So I'm assuming it's only this easy when you use an XMLlist object as a dataprovider. Is that true?

    If so I'm sure I can use the last line of your for loop to append an XML object. The question is when do I assign the object as a dataprovider, before or after its built? Does it matter?

    Thanks again for the help.

    Edit: I am also stuck on how to put a clickable image in two cells of each row.
    Last edited by jAQUAN; 08-23-2006 at 03:36 AM.

  6. #6
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789

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