Extract data from services:views into flash datagrid, arrays

Events happening in the community are now at Drupal community events on www.drupal.org.
vizint's picture

I'm successfully pulling data from services using views.getView:

var pc:PendingCall = views.getView("courselist");

I'm able to populate a datagrid like this:
myDG.dataProvider = re.result;

and I can map fields directly to columns in the datagrid.

I am also pulling selected fields when a user selects a row from the data grid:

//Create listener object from recordset
var listListener:Object = new Object();
listListener.change = function(evt_obj:Object) {
selected_dg_txt.text = myDG.selectedItem["title"];
body_txt.htmlText = myDG.selectedItem["body"];
price_txt.text = "$ "+myDG.selectedItem["list_price"];

var created_date = myDG.selectedItem["created"];
};
// Add listener.
myDG.addEventListener("change", listListener);

My problem is that I am struggling with the proper AS2 syntax for pulling the data out of the array.

In the example below, how do I pull the [filename] out of the array?

(view body)

Array
[files] => Array
                (
                    [165] => stdClass Object
                        (
                            [fid] => 165
                            [nid] => 46
                            [filename] => test_doc.doc
                            [filepath] => files/test_doc.doc
                            [filemime] => application/msword
                            [filesize] => 34304
                            [vid] => 46
                            [description] => test_doc.doc
                            [list] => 0
                        )

                    [166] => stdClass Object
                        (
                            [fid] => 166
                            [nid] => 46
                            [filename] => test_pdf.pdf
                            [filepath] => files/test_pdf.pdf
                            [filemime] => application/pdf
                            [filesize] => 19324
                            [vid] => 46
                            [description] => test_pdf.pdf
                            [list] => 0
                        )

                )

I really appreciate any help on this...

Thanks,
VIZINT

Comments

The syntax is completely the

Fixdit's picture

The syntax is completely the same, but here is what it looks like for AS3 and it should help for AS2:

var filePath = result.files[0].filename;

What you could do is change the "files[0]" to "files[j]" and iterate through all the Objects in the array using a loop

var filePath:Array = new Array();

for (var j:int=0; j < 11; j++) {
    filePath[j] = result.files[j].filename;
}

Trace out the result of the loop and it should be:
filePath[0] = test_doc.doc
filePath[1] = test_pdf.pdf

Hope this helps, let me know how it goes.
BeechyBoy

possum4all's picture

I was struggling with finding object and element IDs for an AS3 / AMFPHP / Drupal home page I'm developing. I realized that Devel Module isn't just for template development. It does a great job of letting you tunnel down into a node or view's particular IDs so that you can use them in your AS3 or AS2 class files and function calls. Probably a "duh" thing for savvy Drupal developers... but I'm a bit "thick" for a designer-type.

Hopefully this will help when others come across this in the search engines. :)

same problem with another version of drupal

ventoline's picture

Hi Beechy boy,

I have the same problem extracting data out of a view and a menu, but unlike Vizint i don't have the array's name; mine would looks like :

Array
(
[165] => stdClass Object
(
[fid] => 165
[nid] => 46
[filename] => test_doc.doc
[filepath] => files/test_doc.doc
[filemime] => application/msword
[filesize] => 34304
[vid] => 46
[description] => test_doc.doc
[list] => 0
)

                [166] => stdClass Object
                    (
                        [fid] => 166
                        [nid] => 46
                        [filename] => test_pdf.pdf
                        [filepath] => files/test_pdf.pdf
                        [filemime] => application/pdf
                        [filesize] => 19324
                        [vid] => 46
                        [description] => test_pdf.pdf
                        [list] => 0
                    )

            )

and "result[0].filename;" doesn't work...

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: