all groups > macromedia flash flash remoting > august 2004 >
You're in the

macromedia flash flash remoting

group:

returning array from CF to Flash ?


returning array from CF to Flash ? dr_bozak
8/27/2004 2:53:44 AM
macromedia flash flash remoting:
hello I am trying to substiute a query output from CF into an array for a flash
movie ...
i think that Cf will return an array instead of a recordset ...
ie
I want to replace in Flash:

myArray = ['1','2','3','4']

with

myArray = [query results from CFC]
****
the flash code looks like:
if (connected == null) {
connected = true;

NetServices.setDefaultGatewayUrl("http://localhost:8500/flashservices/gateway");
var my_conn = NetServices.createGatewayConnection();
var myService = my_conn.getService("slides",this);
}

//calls service
myService.grabSlides({search:''});

// uh ... what am I doing?
function grabSlides_Result(theArray) {
for (var i=0; i<theArray.grabSlides.items.length; i++) {
pic_arr='theArray.grabSlides.items';
trace(pic_arr);

}
}

************************

my cfc looks like:

<cfcomponent displayName="grabSlides">
<cffunction name="grabSlides" access="remote" returnType="array">
<cfargument name="search" type="string" default="%">
<cfquery name="rsGrabSlides" datasource="fresh">
SELECT Picture
FROM PICS
</cfquery>
<cfset returnArray = ArrayNew()>
<cfset returnArray.GrabSlides = GrabSlides>
<cfreturn returnArray>
</cffunction>
</cfcomponent>



***********

any suggestions or links to how this is done are greatly appreciated.


Re: returning array from CF to Flash ? ginx75
8/27/2004 1:08:01 PM
function grabSlides_Result(theArray) {

when using 'grabSlides_Result' you need to use grabSlides_Result(result) {
instead of 'theArray'. either 'result'or the name that you return from CF.
grabSlides_Result(returnArray ) {

To trace the array and see if it worked....
trace(result.length);
trace(result); // outputs: a,b,undefined,undefined,undefined

function grabSlides_Result(return) {
trace(result.length);
trace(result); // outputs: a,b,undefined,undefined,undefined
}

not sure about the CF. let me know if this gets you on the right track.

cd

Re: returning array from CF to Flash ? dr_bozak
8/27/2004 3:19:28 PM
hmm ... well ...
didn't quite work ...

I'll keep randomly guessing.

wish macromedia had provided at least one example on how to do this since it
seems like a basic task.

flash documentation on this is really poor.


Re: returning array from CF to Flash ? dr_bozak
8/27/2004 3:25:30 PM
maybe I don't really need to pass an array?

basically what I am trying to do is replace an array with a recordset from CF
for a photoslide show.

it seems really limited to hard code images into a slide show with an array.

is there a better way to do this (like have flash read through the recordset
into an array?)

I thought the whole point of remoting was that so one can pass complex
strcutures from CF to flash (ie recordset, array, strcutures, etc.)

Macromedia ..

how bout some docs or a link to an example of how this can work?



Re: returning array from CF to Flash ? tek333
8/28/2004 10:31:18 PM
Re: returning array from CF to Flash ? dr_bozak
8/30/2004 7:08:00 PM
thanks for the link which has a nice demo of how to do remoting slideshow
(although somewhat devoid of a few key features of any dynamic page).
I did work through the above link and added features that should have been
their ..
(1.not staticly setting the max records next button, but rather using the
recordcount returned by the CFC
2. using a different directory to hold the images
3. actually using a real query instead of using the temp query )

one thing I found really weird about flash, is that it totally unforgiving on
displaying jpegs that are not saved correctly (ie progressive jpegs). I
couldn't figure out why it wouldn't display any jpegs I had, until I resaved
them as non-progressive.

this is probably basic for a flash developer, but a web developer who is used
to the truly forgiving <img src> code, which can resize gifs and jpegs of
multiple formats, the flash images seem really really unforgiving.

still ... example doesn't return an array which is really what I was after.

I have several flash developer friends who make slide shows with a static
array, who'd like to use a database to populate the array ...

so still the question is:

can one replace

myArray = ['1','2','3','4']

with

myArray = [query results from CFC as an array]


???
Re: returning array from CF to Flash ? tek333
8/31/2004 4:40:44 AM
Flash Remoting can pass any CF structure, so arrays would be included. Here's
some code fragments that have worked for me:

Assuming there's a function called "getImages" in your CFC, code like this can
be in the function (either hardcoded like below or extracted from a <cfquery>
of a database)
:
<CFSET myPhoto.1 = "C:\inetpub\wwwroot\myWebRoot\images\photo1.jpg">
<CFSET myPhoto.2 = "C:\inetpub\wwwroot\myWebRoot\images\photo2.jpg">

Then in your actionscript, this code will loop through the array:

function getImages_Result(result) {
RecordCount=result.getLength()-1;
for (i=0; i <= recordCount; i++) {
Pictures=result.items.myPhoto;
......do something usefull with the string variable 'Pictures' here.......
}

The Flash documentation stated the progressive jpeg's aren't supported, so
there shouldn't be any surprise there. I can't say I miss it. Most developers
would have access to image processing software that could convert them to
regular jpeg's. And every supported image format that gets added to the Flash
plugin, just increases the size of the plugin that much more.
Re: returning array from CF to Flash ? dr_bozak
8/31/2004 2:56:02 PM
thanks for the example. I will give that a try.

Re: returning array from CF to Flash ? dr_bozak
8/31/2004 4:08:23 PM
what am I missing? I get zero output in output window.
I'll give ANYONE twenty bucks if they can provide a COMPLETE WORKING EXAMPLE
of how this is done.
if it's so easy ... easy money right?
I've spent 4 days trying this posting in this forum. I get a different partial
solution from everyone .. none of them work.



here is what I got so far:

slide.cfc code:
**************************************************************************
<cfcomponent displayName="getImages">
<cffunction name="getImages" access="remote" returnType="any">

<cfquery datasource="fresh" name="imageArray">
select Photo from Pictures
</cfquery>
<!--- ?????
some code here to build an array from the imageArray query
and make it available as an array to flash
don't know how .. don't care how ...

???? ---->

</cffunction>
</cfcomponent>

******************************************
.fla code:

if (connected == null) {
connected = true;

NetServices.setDefaultGatewayUrl("http://flashfusion.net/flashservices/gateway")
;
var my_conn = NetServices.createGatewayConnection();
var myService = my_conn.getService("slides",this);
}
// call service
myService.getImages();

// handle results from service call
function getImages_Result(result) {
RecordCount=result.getLength()-1;
for (i=0; i <= recordCount; i++)
{
Pictures=result.items.myPhoto;
trace(pictures);
//build an array here from cfc result.
//replace pic_arr = ['1','2','3','4']
//with pic_arr=[query results from cfc as an array]
}
};


first person to show me the answer gets twenty bucks.



Re: returning array from CF to Flash ? Rob 98765
11/2/2004 6:10:43 AM
Maybe this helps - Building a 1 dimensional array from a query call //cfc
<cfcomponent> <cffunction name='getImages' access='remote' returnType='query'>
<cfargument name='passeddata'> <cfquery name='getdata'
datasource='#datasource#'> SELECT photo FROM pictures WHERE photo =
#arguments.passeddata# </cfquery> <cfreturn getdata> </cffunction>
</cfcomponent> //flash myService.getImages(passeddata); function
getimages_Result (result) { arraycounter = result.getLength (); for (i = 0; i
< arraycounter; i++) { pic_arr = result.getItemAt (i).photo; } } There is a
problem I am having with this - I can't get this array to be a global variable.
See my other post. N.B. The result set starts at item 0 not 1 so I sometimes
use [i+1] so my array starts at 1
Re: returning array from CF to Flash ? John Rock
11/3/2004 12:31:07 AM
This is how it's done : THE CFC (myCFC.cfc)
------------------------------------------------------------------------
<cfcomponent> <cffunction name='myMethod' access='remote' output='false'
returntype='array' hint='returns a simple array'> <cfset myArray =
ArrayNew(1)> <!--- Put stuff in the array ---> <cfscript> myArray[1] =
'value1'; myArray[2] = 'value2'; myArray[3] = 'value3'; </cfscript>
<cfreturn myArray> </cffunction> </cfcomponent> IN FLASH
-----------------------------------------------------------------------------
(gateway stuff...) theCfcArray = gatewayConnnection.getService('myCFC', this);
theCfcArray.myMethod(); function myMethod_Result(result) { arrayValue1 =
result[0]; arrayValue2 = result[1]; arrayValue3 = result[2]; } TIP : always
test your CFC in CF before trying to use it in Flash so you know it works, else
your Flash movie will crash every time. Cheers, JP
Re: returning array from CF to Flash ? TiGGi
11/3/2004 6:24:27 PM
try smething like this' // uh ... what am I doing? function
grabSlides_Result(result) { for (var i=0; i<theArray.grabSlides.items.length;
i++) { var pic_arr=result.items.picture; trace('Records: ' +
result.getNumberAvailable()); trace(pic_arr);
AddThis Social Bookmark Button