<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ria-coder.com &#187; FaultEvent</title>
	<atom:link href="http://ria-coder.com/blog/tag/faultevent/feed" rel="self" type="application/rss+xml" />
	<link>http://ria-coder.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 21 Apr 2010 19:35:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Handling multiple remote services with RemoteObject &#8211; the easy way!</title>
		<link>http://ria-coder.com/blog/handling-multiple-remote-services-with-remoteobject-the-easy-way</link>
		<comments>http://ria-coder.com/blog/handling-multiple-remote-services-with-remoteobject-the-easy-way#comments</comments>
		<pubDate>Tue, 05 May 2009 22:16:03 +0000</pubDate>
		<dc:creator>Danny Kopping</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[FaultEvent]]></category>
		<category><![CDATA[remoteobject]]></category>
		<category><![CDATA[ResultEvent]]></category>
		<category><![CDATA[service calls]]></category>

		<guid isPermaLink="false">http://ria-coder.com/blog/?p=271</guid>
		<description><![CDATA[Here's a quick and easy way to handle multiple service calls in two simple event handlers!]]></description>
			<content:encoded><![CDATA[<p>Ok, so you&#8217;re developing a Flex application with a bit of server-side integration (using PHP, Java, Ruby, .NET, etc) and your application is getting a little intense; multiple service calls to the server, custom logic for success and failure of said calls and everything in between.</p>
<p>You could use the following syntax for handling mutliple method-calls from a remote script (in this example <em>MyService</em>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RemoteObject</span> id=<span style="color: #ff0000;">&quot;service&quot;</span> destination=<span style="color: #ff0000;">&quot;amfphp&quot;</span> source=<span style="color: #ff0000;">&quot;MyService&quot;</span> makeObjectsBindable=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
 	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:method</span> name=<span style="color: #ff0000;">&quot;doSomething&quot;</span> result=<span style="color: #ff0000;">&quot;doSomethingResult(event)&quot;</span> fault=<span style="color: #ff0000;">&quot;doSomethingFault(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
 	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:method</span> name=<span style="color: #ff0000;">&quot;doAnotherSomething&quot;</span> result=<span style="color: #ff0000;">&quot;doAnotherSomethingResult(event)&quot;</span> fault=<span style="color: #ff0000;">&quot;doAnotherSomethingFault(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
 <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:RemoteObject</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;"> 	&lt;![CDATA[</span>
<span style="color: #339933;">		private function doSomethingResult(event:ResultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			// custom logic</span>
<span style="color: #339933;">		}</span>
&nbsp;
<span style="color: #339933;">		private function doSomethingFault(event:FaultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			// custom logic</span>
<span style="color: #339933;">		}</span>
&nbsp;
<span style="color: #339933;">		private function doAnotherSomethingResult(event:ResultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			// custom logic</span>
<span style="color: #339933;">		}</span>
&nbsp;
<span style="color: #339933;">		private function doAnotherSomethingFault(event:FaultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			// custom logic</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;"> 	]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span></pre></td></tr></table></div>

<p>I dunno about you, but to have to define <strong>special</strong> tags in MXML for each bloody method in your script is too much effort (and can leave you with some nasty/tricky bugs if you forget to add a new tag after adding a new method in your server-side script!). I used the following mechanism in my post about <a title="Integrating CodeIgniter, Flex and PHP" href="http://ria-coder.com/blog/integrating-flex-amfphp-and-codeigniter-with-value-objects/" target="_blank">integrating CodeIgniter, Flex and PHP</a> if i remember correctly&#8230; Give me a break&#8230; I was too lazy to check (it&#8217;s midnight and i&#8217;m sleepless).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RemoteObject</span> id=<span style="color: #ff0000;">&quot;service&quot;</span> destination=<span style="color: #ff0000;">&quot;amfphp&quot;</span> source=<span style="color: #ff0000;">&quot;MyService&quot;</span> makeObjectsBindable=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #000000;">result=<span style="color: #ff0000;">&quot;resultHandler(event)&quot;</span> fault=<span style="color: #ff0000;">&quot;faultHandler(event)&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;"> 	&lt;![CDATA[</span>
<span style="color: #339933;">		private function resultHandler(event:ResultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			var message:RemotingMessage = event.token.message as RemotingMessage;</span>
&nbsp;
<span style="color: #339933;">			switch(message.operation)</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				case &quot;doSomething&quot;:</span>
<span style="color: #339933;">					// custom logic</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">				case &quot;doAnotherSomething&quot;:</span>
<span style="color: #339933;">					// custom logic</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">				default:</span>
<span style="color: #339933;">					trace(&quot;Shit... Missed this one... &quot; + message.operation);</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		}</span>
&nbsp;
<span style="color: #339933;">		private function faultHandler(event:FaultEvent):void</span>
<span style="color: #339933;">		{</span>
<span style="color: #339933;">			var message:RemotingMessage = event.token.message as RemotingMessage;</span>
&nbsp;
<span style="color: #339933;">			switch(message.operation)</span>
<span style="color: #339933;">			{</span>
<span style="color: #339933;">				case &quot;doSomething&quot;:</span>
<span style="color: #339933;">					// custom logic</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">				case &quot;doAnotherSomething&quot;:</span>
<span style="color: #339933;">					// custom logic</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">				default:</span>
<span style="color: #339933;">					trace(&quot;Shit... Missed this one... &quot; + message.operation);</span>
<span style="color: #339933;">					break;</span>
<span style="color: #339933;">			}</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;"> 	]]&gt;</span>
<span style="color: #339933;">&lt;/mx:Script&gt;</span></pre></td></tr></table></div>

<p>Seems much easier, doesn&#8217;t it? Essentially all you&#8217;re doing is examining the event parameter of the ResultEvent or FaultEvent, finding which method was just called and acting accordingly&#8230; This will work with any number of method calls, from any number of different RemoteObjects. You can point them all to the same handlers!</p>
<p>If you guys have any alternative ways of doing this, let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://ria-coder.com/blog/handling-multiple-remote-services-with-remoteobject-the-easy-way/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

