Returning a list or array of objects

Jan 6, 2010 at 8:31 PM

First off, wanted to thank you for posting this project out there.

Trying to modify Example 3 to do the following...  I would like to return either an IList<StockData> or StockData[].  My call seems to be working, but I am not able to pull apart the result in actionscript.

My WCF code looks like this...

public Contract.StockData[] GetItemList()
            return new Contract.StockData[] {
                new Contract.StockData { Name = "MSFT", Price = 14.00, Quantity = 4 },
                new Contract.StockData { Name = "ADB", Price = 20.00, Quantity = 6 }

AS2 code looks like this...

function handleStockDataReturn(re:ResultEvent) {
    trace("Got result of type "+typeof(re.result[0]));

Any help would be greatly appreciated. 

Jan 8, 2010 at 3:35 PM

Hmm, I hadn't tried returning an array of objects.  I thought it would just work as you have described it, but if it doesn't... I'll open it up shortly and check it out.

Unfortunately, I'm not really a flash developer, so after a bit of stumblling around, hopefully I can figure something out for you.

Jan 8, 2010 at 3:46 PM

As it turns out, the answer was easier to find than I realized.  Remember that re.result is an array of your MessageBody parts - re.result[0] is the value you're actually returning in Example 3.  So, try using this, instead:


function handleStockDataReturn(re:ResultEvent) {
    var i;
    for (i = 0; i < re.result[0].length; i++) {
        trace("Got result of type "+typeof(re.result[0][i]));


Hope this answer found you in time!

Jan 8, 2010 at 6:07 PM

mdekrey, you are a genius!  Works like a champ.  I was looping through the 1st level of the array.

Thanks again.

Jan 8, 2010 at 6:59 PM

I'm glad you enjoy the project.  I've added the code to Example 3 to include both the single item and the array.