Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Remoting / August 2005



Tip: Looking for answers? Try searching our database.

passing an array from CFC to Flash

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sacal - 02 Aug 2005 19:16 GMT
Hello there,

I want to pass an array from cold fusion into Flash, but I can't get the
values with Action Script.  The NetConneciton Debugger shows that the values I
want were indeed passed to Flash, but I can't get to them with ActionScript.

Here's the CFC script (where I first pass values from flash into coldFusion):

<cffunction name="getSpecificDuration" access="remote">
   
        <!-- params from FLASH -->
        <!-- create local array to loop array.length times -->
        <cfset areas = ArrayNew(1)>
            <cfset areas[1] = "#Flash['areaOne']#">
            <cfset areas[2] = "#Flash['areaTwo']#">
            <cfset areas[3] = "#Flash['areaThree']#">
            <cfset areas[4] = "#Flash['areaFour']#">
   
        <!-- create empty array to store values that will be passed back to Flash -->
        <cfset durations = ArrayNew(1)>
       
        <cfloop index="i" from="1" to="#ArrayLen(areas)#">
             <cfquery name="appendOne" datasource="dbusertracking">
                SELECT Sum(contDuration)
                   FROM tb_contarea
                  WHERE contName = '#areas#'
              </cfquery>
            <cfset ArrayAppend(durations, appendOne)>
        </cfloop>
       
        <cfreturn durations>
    </cffunction>


--------------------------------------------------------------------------------
-----------------------
After calling this CF function, the NetConneciton Debugger displays:

DebugId: 0
EventType: "Result"
MovieUrl: "........my.swf"
Protocol: "http"
Source: "Client"
Time: 1123004416148
Date (object #1)
....."Tue Aug 2 13:40:16 GMT-0400 2005"
Result (object #2)
.....[0] (object #3)
..........length: (undefined)
..........mRecordsAvailable: 1
..........serverInfo: (undefined)
..........uniqueID: 1
..........items (object #4)
...............[0] (object #5)
....................Sum(contDuration): 109
....................__ID__: 0
..........mTitles (object #6)
...............[0]: "Sum(contDuration)"
..........views (object #7)
...............No properties
.....[1] (object #8)
..........length: (undefined)
..........mRecordsAvailable: 1
..........serverInfo: (undefined)
..........uniqueID: 1
..........items (object #9)
...............[0] (object #10)
....................Sum(contDuration): 48
....................__ID__: 0
..........mTitles (object #11)
...............[0]: "Sum(contDuration)"
..........views (object #12)
...............No properties
.....[2] (object #13)
..........length: (undefined)
..........mRecordsAvailable: 1
..........serverInfo: (undefined)
..........uniqueID: 1
..........items (object #14)
...............[0] (object #15)
....................Sum(contDuration): 41
....................__ID__: 0
..........mTitles (object #16)
...............[0]: "Sum(contDuration)"
..........views (object #17)
...............No properties
.....[3] (object #18)
..........length: (undefined)
..........mRecordsAvailable: 1
..........serverInfo: (undefined)
..........uniqueID: 1
..........items (object #19)
...............[0] (object #20)
....................Sum(contDuration): 117
....................__ID__: 0
..........mTitles (object #21)
...............[0]: "Sum(contDuration)"
..........views (object #22)
...............No properties


--------------------------------------------------------------------------------
------------------------------------
My AS function that retrieves this "array" is:

function getInfo(whichData)      //---- get server response ----//
{
    //receives data returned from the method
    this.onResult = function(result) {
        //trace("Data received from server : " + result);
        for (var i=0; i < result.length; i++) {
              thisDuration = result.item;
             trace("duration "+ i + " = "+ result.);   //*********
                          }       
                     }
};

--------------------------------------------------------------------------------
--------------------
When I use:
trace("duration "+ i + " = "+ result.);     The output window displays:
duration 0 = [object Object]

When I use:
trace("duration "+ i + " = "+ result.item);  I get:  duration 0 = undefined

What am I doing wrong??
cdrabik - 02 Aug 2005 21:20 GMT
Couple of things..  First of all, in order to be able to reliably access your
query field, you should name it:

 <cfquery name="appendOne" datasource="dbusertracking">
SELECT Sum(contDuration) AS duration
FROM tb_contarea
WHERE contName = '#areas#'
</cfquery>

So that you can reliably refer to the column name in the resulting query -
different DBMSs will name it differently and I'd hate to have that change on me
when I upgraded or switched the database.  Now instead of having a field named
"Sum(contDuration)" which is not a legal variable name, you have "duration"
which is.

Second thing..  Your queries by definition will contain only one row and one
column.  Why bother with the hassle and added expense of the query's baggage in
your array?  Instead of:

 <cfset ArrayAppend(durations, appendOne)>

use:

 <cfset ArrayAppend(durations, appendOne.duration)>

so you're only appending a number and not a query object.

Now the array returned will be more simplistic to deal with - you'll have an
array of numbers in result.  You could then refer to them as result[0],
result[1]...result and those will be numbers.  The way you have it now, result
is a query object.

If you have a situation where you really need an array of queries, you ust
need to address a little better.  result[0] refers to the first query object in
your array.  The query object has several properties that you can see in the
debugger output, the most interesting to us being _items.  This is an array of
Objects which represent your rows.  Your rows have only one column, so your row
Objects have only one property (which is called god knows what because the
column name isn't a legal variable name).  If you had renamed the column as
"duration", the duration property in the first row of the first query in your
dump would be:

result[0]._items[0].DURATION

Note the upper-case as CF returns the column names in all upper-case.

Hopefully this helps (and I haven't made any typos or other mistakes).
sacal - 03 Aug 2005 18:05 GMT
THANK YOU SOOOOOOOOOOOOOOOOOOOOO MUCH!!!  :beer;

I did figure out yesterday I was getting an object back from the server. So I
was using recursive loops to drill it down to the values I wanted.  What a
pain!!!

But now!  Thanks to you, all I get back is the array with the 4 values I want,
and nothing else!  You're such a genius!

Thank you again for taking the time in reading, analyzing and responding to my
question!  :-D
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.