Yup. Closures are confusing at first, but very very cool.  And a great way to maintain local state in a way that makes it much easier to write sequential code in an asynchronous event driven way (i.e., when making remote calls, or tracking mouse movement, etc).
 
Ely.
 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of dffmyco
Sent: Thursday, September 07, 2006 11:48 AM
To: [email protected]
Subject: [flexcoders] Re: Which chart was clicked

Ely:
Thanks alot. Worked fine and I learned something about closures.
Dave

--- In [EMAIL PROTECTED]ups.com, "Ely Greenfield" <[EMAIL PROTECTED].>
wrote:
>
>
>
>
> You've got three options:
>
> 1) shove the id off into a member field, and grab it when the RO
> returns. This is the least well designed response, since it can
break
> in use cases where you've got multiple requests out and you don't
just
> want last-out-wins. Might be OK for your use case though.
>
> 2) send the id up to the RO, and have it include it in the
response. A
> little wasteful, since the RO doesn't care about the id, but in
general
> this 'cookie' pattern is a way to maintain state across RO calls.
>
> 3) use closures. you could do something like this:
>
>
> private function chartClickHandler(e:MouseEvent):void
> {
> var id:String = UIComponent(e.currentTarget).id;
> var roCB:Function = function(e:ResultEvent):void
> {
> nameList = event.result as ArrayCollection;
> currentState = "showNames";
> gridPanel.title = id;
> myRemoteObject.getNomeForNames.removeEventListener
("result",roCB);
> }
> myRemoteObject.getNomeForNames.addEventListener("result",roCB);
> myRemoteObject.getNomeForNames(id);
> }
>
> <PieChart id="..." click="chartClickHandler(event);" ... />
>
> Ely.
>
>
> ________________________________
>
> From: [EMAIL PROTECTED]ups.com
[mailto:[EMAIL PROTECTED]ups.com] On
> Behalf Of dffmyco
> Sent: Tuesday, September 05, 2006 8:28 AM
> To: [EMAIL PROTECTED]ups.com
> Subject: [flexcoders] Which chart was clicked
>
>
>
> I have 3 pie charts which when clicked run the same remoteObject
> method. Is there a way within the method that I can determine
which
> pie chart was clicked. I want to pass the id of the clicked chart
as
> a variable in the result function of the remoteObject method.
>
> Thanks, Dave
>
> <mx:PieChart id="Citrus"
> click="myRemoteObject.getNomeforNames('Citrus')"
showDataTips="true"
> dataProvider="{citrusData}"/>
>
> <mx:RemoteObject
> id="myRemoteObject"
> destination="ColdFusion"
> showBusyCursor="true"
> source="fungaldatabases.fungaldatabasesstats.stats"
> fault="Alert.show(event.fault.faultString, 'Error');">
> <mx:method name="getNomeforNames" result="showNames(event)">
>
> </mx:method>
> </mx:RemoteObject>
>
> public function showNames(event:ResultEvent):void{
> nameList=event.result as ArrayCollection
> currentState = "showNames";
> gridPanel.title = 'whould like to use the id of the chart
> selected'
> }
>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to