RemoteObject Scope Issue


i trying create backend air application. application poker site. can return objects coldfusion air fine, problem is, everytime make call function in cfc, acts if each call seperate "instance" of cfc.

 

below cfc using...

 

 

<cfcomponent output="false" name="deck">

 

<cfset suits = ["hearts", "diamonds", "spades", "clubs"]>

<cfset cards = ["a", "2", "3", "4", "5", "6", "7", "8", "9", "10", "j", "q", "k"]>

<cfset names = ["ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king"]>

<cfset deck = arraynew(1)>

 

 

<cffunction name="createdeck" access="remote">

<cfscript>arrayclear(deck);</cfscript>

 

<cfset cardslength = arraylen(cards)/>

<cfset suitslength = arraylen(suits)/>

 

<cfloop index="i" from="1" to=#suitslength#>

<cfloop index="j" from="1" to=#cardslength#>

<cfscript>

arrayappend(deck, [cards[j],suits[i]]);

</cfscript>

</cfloop>

</cfloop>

 

<cfscript>shuffledeck();</cfscript>

<cfreturn deck />

</cffunction>

 

 

<cffunction name="shuffledeck">

<cfset createobject("java","java.util.collections").shuffle(deck)/>

</cffunction>

 

 

<cffunction name="dealcard" access="remote">

<cfset randomnumber = randrange(1, arraylen(deck), "sha1prng")/>

<cfreturn arraylen(deck)/>

</cffunction>

 

</cfcomponent>

 

 

below sample of flex code using call cfc...

 

 

<s:windowedapplication xmlns:fx="http://ns.adobe.com/mxml/2009"

  xmlns:s="library://ns.adobe.com/flex/spark"

  xmlns:mx="library://ns.adobe.com/flex/mx"

  creationcomplete="initapp()">

 

<fx:declarations>

<!-- place non-visual elements (e.g., services, value objects) here -->

<s:remoteobject id="svc" destination="coldfusion" endpoint="http://localhost:8500/flex2gateway/" source="pokersite.cfc.deck">

<s:method name="createdeck" result="resulthandler(event)" fault="faulthandler(event)"/>

<s:method name="dealcard" result="resulthandler(event)" fault="faulthandler(event)"/>

</s:remoteobject>

</fx:declarations>

 

 

<fx:script>

<![cdata[

import mx.rpc.events.faultevent;

import mx.rpc.events.resultevent;

 

private function initapp():void

{

svc.createdeck();

}

 

private function dodeal():void

{

svc.dealcard();

}

 

private function resulthandler(e:resultevent):void

{

trace(e.result);

}

 

private function faulthandler(e:faultevent):void

{

trace(e.fault);

}

]]>

</fx:script>

 

 

<s:panel x="0" y="0" width="250" height="200">

<s:button click="dodeal()" label="deal"/>

</s:panel>

 

</s:windowedapplication>

 

 

when call createdeck() function of cfc, returns entire deck fine. however, when call dealcard() function clicking button, returns length of 0 of deck object in cfc (just returning length test deck has been created now) if deck never created. did searching online, , found might have setup remoting-config.xml file allow application level scope. setup remoting-config.xml so...

 

 

<destination id="coldfusion">

<channels>

<channel ref="my-cfamf"/>

</channels>

<properties>

<source>*</source>

<scope>application</scope>

</properties>

</destination>

 

 

yet, still fails same way. know if missing simple step? or setting application scope in wrong place? sounds problem having, when change remoting-config.xml file, doesn't seem change in way functions called.



More discussions in ColdFusion


adobe

Comments

Popular posts from this blog

Hur installera Joomla på One.com - Joomla! Forum - community, help and support

removing index.php from URL address - Joomla! Forum - community, help and support

「イメージマップのアンカー名には、...」のエラーが出ないようにしたい