<?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>Buzzy And Me &#187; Flex</title>
	<atom:link href="http://blog.buzzyand.me/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.buzzyand.me</link>
	<description>Our take on the Web Technology..</description>
	<lastBuildDate>Wed, 23 Sep 2009 09:47:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Build a Silverlight-Flex Chat Application Using LiveCycle Data Services</title>
		<link>http://blog.buzzyand.me/2008/10/build-a-silverlight-flex-chat-application-using-livecycle-data-services/</link>
		<comments>http://blog.buzzyand.me/2008/10/build-a-silverlight-flex-chat-application-using-livecycle-data-services/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 22:09:55 +0000</pubDate>
		<dc:creator>buzzy</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[LiveCycle]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[LiveCycle Data Services]]></category>

		<guid isPermaLink="false">http://blog.buzzyand.me/?p=41</guid>
		<description><![CDATA[With the recent release of Silverlight 2 RC1 and Flash Player 10, things in the RIA world have never looked more interesting. I was going over the forums on Silverlight.net and realised that some of the criticism directed towards Silverlight was regarding the lack of support for a binary protocol similar to AMF, which is [...]]]></description>
			<content:encoded><![CDATA[<p>With the recent release of Silverlight 2 RC1 and Flash Player 10, things in the RIA world have never looked more interesting. I was going over the forums on Silverlight.net and realised that some of the criticism directed towards Silverlight was regarding the lack of support for a binary protocol similar to AMF, which is supported by the Flash Player. Data transfer using AMF is definitely faster than the more verbose XML.</p>
<p>I am sure that better ways of data transfer with Silverlight will emerge soon, but currently, our options are limited. I tried a few examples using sockets but it seemed like too much work, especially when you are used to RPC using the RemoteObject tag in Flex <img src='http://blog.buzzyand.me/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>There is a workaround (more of a hack) to this problem. We could use the HTML DOM integration of the Silverlight runtime and Flash Player to pass messages between the two. The Flash application will have no UI elements (in fact, it can be hidden). It only receives the messages and passes the data to the DOM, which is then sent to the Silverlight application. The JavaScript required for this purpose is not too complicated. This is not an elegant solution but it will have to do for now.</p>
<p>Though I initially started exploring this approach only to call ColdFusion CFC’s from a Silverlight application without resorting to XML Web Services, I quickly realised that the same approach could be used to build a simple Chat application using the Messaging features of LCDS.<br />
So here is a quick tutorial on creating a Flex Silverlight Chat application using LiveCycle. I am using the version of LiveCycle that is integrated into the ColdFusion 8 server.</p>
<p><strong>Step 1: Configuring LiveCycle Messaging Endpoints</strong><br />
The first step is to configure a “destination” in the messaging-config.xml file that resides in the WEB-INF/flex folder of your web root.</p>
<p>Give the destination an appropriate ID, and then specify the appropriate adapter. In the default installation of LCDS on ColdFusion 8, the default adapter is “cfgateway”. We want to use the “actionscript” adapter, so it has to be explicitly mentioned.</p>
<pre class="brush: xml;">
&lt;adapter ref=&quot;actionscript&quot;/&gt;
</pre>
<p>The second step is optional. Switch the “allow-subtopics” server property to true. This way, our chat application can listen to and send messages on multiple topics. For further information regarding the server properties and other security information, refer to the LiveCycle LiveDocs.</p>
<pre class="brush: xml;">
&lt;properties&gt;
      &lt;server&gt;
        &lt;allow-subtopics&gt;true&lt;/allow-subtopics&gt;
      &lt;/server&gt;
&lt;/properties&gt;
</pre>
<p>The next step is to specify the channel over which we want to transfer data. The “java-rtmp” channel enables messages to be transferred in real time. However, it uses a non standard port for communication which may cause issues with Firewalls. So, as a backup, we specify another channel “java-polling-amf” which uses polling to check if data needs to be transferred. Be sure to check that these channel definitions are uncommented in the services-config.xml file. You can adjust the settings of these endpoints too, but the defaults should work fine for our purposes.</p>
<pre class="brush: xml;">
  &lt;destination id=&quot;chat&quot;&gt;
    &lt;adapter ref=&quot;actionscript&quot;/&gt;
    &lt;properties&gt;
      &lt;server&gt;
        &lt;allow-subtopics&gt;true&lt;/allow-subtopics&gt;
      &lt;/server&gt;
    &lt;/properties&gt;
    &lt;channels&gt;
      &lt;channel ref=&quot;java-rtmp&quot;/&gt;
      &lt;channel ref=&quot;java-polling-amf&quot;/&gt;
    &lt;/channels&gt;
  &lt;/destination&gt;
</pre>
<p>And thats it, save both the services-config.xml and messaging-config.xml file and restart your server.</p>
<p><strong>Step 2: Building the Flex Application</strong><br />
The next step is to build the Flex application that will actually handle the data transfer between the server and the HTML DOM. This application will have no UI elements. You can specify a really tiny size.<br />
Create a Flex ColdFusion 8 project that uses LiveCycle Data Services instead of Flash Remoting. Now instantiate the Producer and the Consumer objects in MXML. </p>
<pre class="brush: xml;">
&lt;mx:Producer id=&quot;producer&quot; destination=&quot;chat&quot; subtopic=&quot;buzzy&quot; /&gt;
&lt;mx:Consumer id=&quot;consumer&quot; destination=&quot;chat&quot; subtopic=&quot;buzzy&quot; message=&quot;gotMessage(event)&quot; /&gt;
</pre>
<p>The destination property of these objects is the one specified in the messaging-config.xml. Since subtopics are allowed, specify a subtopic of your choice. This feature will come in handy when you are building a more full featured chat application.<br />
Add a “message” event handler to your consumer. This event handler will call an external JavaScript method, passing it the message that the consumer just received.</p>
<pre class="brush: java;">
private function gotMessage(e:MessageEvent):void
{
    flash.external.ExternalInterface.call(&quot;receiveMessage&quot;, (e.message.body as String));
}
</pre>
<p>On the “creationComplete” event of the Application, register a callback method. This ActionScript method will be called when the appropriate JavaScript method is called in the HTML page. This ActionScript method receives one argument with which it constructs an AsyncMessage and sends it using the Producer.</p>
<pre class="brush: java;">
private function init(e:FlexEvent):void
{
        consumer.subscribe();
        flash.external.ExternalInterface.addCallback(&quot;sendMessage&quot;, sendMessage);
}
private function sendMessage(str:String):void
{
        var message:AsyncMessage = new AsyncMessage();
        message.body = str;
        producer.send(message);
}
</pre>
<p>The complete MXML code is given below:</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; creationComplete=&quot;init(event)&quot; layout=&quot;absolute&quot; height=&quot;5&quot; width=&quot;5&quot;&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.messaging.events.MessageFaultEvent;
			import mx.controls.Alert;
			import mx.messaging.events.MessageEvent;
			import mx.messaging.messages.AsyncMessage;
			import mx.events.FlexEvent;
			private function init(e:FlexEvent):void
			{
				consumer.subscribe();
                                flash.external.ExternalInterface.addCallback(&quot;sendMessage&quot;, sendMessage);
			}
			private function sendMessage(str:String):void
			{
				var message:AsyncMessage = new AsyncMessage();
				message.body = str;
				producer.send(message);
			}
			private function gotMessage(e:MessageEvent):void
			{
                                flash.external.ExternalInterface.call(&quot;receiveMessage&quot;, (e.message.body as String));
			}
		]]&gt;
	&lt;/mx:Script&gt;
	&lt;mx:Producer id=&quot;producer&quot; destination=&quot;chat&quot; subtopic=&quot;buzzy&quot; /&gt;
	&lt;mx:Consumer id=&quot;consumer&quot; destination=&quot;chat&quot; subtopic=&quot;buzzy&quot; message=&quot;gotMessage(event)&quot; /&gt;
&lt;/mx:Application&gt;
</pre>
<p><strong>Step 3: Building the Silverlight Application</strong><br />
We are finally done with the Flex application, moving on to the Silverlight application itself. All the UI elements of the application have to be created here. The details are really up to you, but the basic elements of the UI will be a TextBox which will act as a message area and another TextBox which will act as a message input area. I quickly drew the UI in Blend. This is what I ended up with:</p>
<pre class="brush: xml;">
&lt;UserControl x:Class=&quot;FlexSilverlightChat.Page&quot; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;  xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; Width=&quot;800&quot; Height=&quot;600&quot; Background=&quot;#FF1E8AB6&quot;Foreground=&quot;#FF1E8AB6&quot; xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot; xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot; mc:Ignorable=&quot;d&quot;&gt;
&lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;#FF1372B0&quot;&gt;

    	&lt;Rectangle Height=&quot;55.294&quot; Margin=&quot;8.412,0,121.941,7.882&quot; VerticalAlignment=&quot;Bottom&quot; Fill=&quot;#FFD8D8D8&quot; Stroke=&quot;#FF000000&quot; StrokeThickness=&quot;4&quot; d:LayoutOverrides=&quot;Height&quot; d:IsLocked=&quot;True&quot;/&gt;
    	&lt;Button Click=&quot;Button_Click&quot; Height=&quot;55&quot; HorizontalAlignment=&quot;Right&quot; Margin=&quot;0,0,8.001,7.882&quot; VerticalAlignment=&quot;Bottom&quot; Width=&quot;109.586&quot; Content=&quot;Send&quot; d:LayoutOverrides=&quot;Width&quot;/&gt;
    	&lt;Rectangle Margin=&quot;8.001,7.882,8.001,66.94&quot; Fill=&quot;#FFD8D8D8&quot; Stroke=&quot;#FF000000&quot; StrokeThickness=&quot;4&quot; Opacity=&quot;0.43&quot; d:IsLocked=&quot;True&quot;/&gt;
    	&lt;TextBox Margin=&quot;18.823,18.591,21.884,77.586&quot; x:Name=&quot;messageArea&quot; Opacity=&quot;1&quot; Background=&quot;{x:Null}&quot; Text=&quot;&quot; TextWrapping=&quot;Wrap&quot; IsReadOnly=&quot;True&quot;/&gt;
    	&lt;TextBox Height=&quot;34.649&quot; Margin=&quot;18.969,0,135.295,17.114&quot; x:Name=&quot;inputText&quot; VerticalAlignment=&quot;Bottom&quot; Background=&quot;{x:Null}&quot; Text=&quot;&quot; TextWrapping=&quot;Wrap&quot;/&gt;

    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>
<p>The Send button is wired to an event handler which calls a JavaScript method called “sendMessage” which in turn calls the ActionScript method (also named “sendMessage”) that sends the message using the Producer. It is invoked as follows:</p>
<pre class="brush: csharp;">
void Button_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke(&quot;sendMessage&quot;, inputText.Text);
inputText.Text = &quot;&quot;;
}
</pre>
<p>Invoking Javascript methods from C# is simple enough but the reverse is not as easy as registering a callback method, as in the case of ActionScript.</p>
<p>First, the “Page” class has to be marked as a “ScriptableType” and all the methods that have to be called from JavaScript must be marked as “ScriptableMember”</p>
<p>Then, register an event handler that responds to the “Loaded” event. The “Page” class which is marked as a “ScriptableType” must be registered as a Scriptable Object.</p>
<pre class="brush: csharp;">
void Page_Loaded(object sender, RoutedEventArgs e)
{
HtmlPage.RegisterScriptableObject(&quot;Page&quot;, this);
}
</pre>
<p>The complete C# code is given below:</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace FlexSilverlightChat
{
    [ScriptableType]
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Page_Loaded);
        }
        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            HtmlPage.RegisterScriptableObject(&quot;Page&quot;, this);
        }
        void Button_Click(object sender, RoutedEventArgs e)
        {
            HtmlPage.Window.Invoke(&quot;sendMessage&quot;, inputText.Text);
            inputText.Text = &quot;&quot;;
        }
        [ScriptableMember]
        public void gotMessage(String message)
        {
            messageArea.Text = &quot;Message: &quot; + message + &quot;\n&quot; + messageArea.Text;
        }
    }
}
</pre>
<p>We are now in the home stretch. Generate the release builds of the Flex application using Flex Builder and the Silverlight TestPage using Visual Studio. You will now have the Silverlight and Flex applications residing on two separate pages.</p>
<p>Copy the appropriate HTML code fragments from both pages onto a single HTML Page.<br />
Now it’s time to write the JavaScript that will wire the ActionScript methods in the Flex application with the C# methods in the Silverlight application.</p>
<p>Both methods are fairly trivial and self explanatory.</p>
<pre class="brush: jscript;">
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
  	function sendMessage(message)
	{
		document['FacelessChat'].sendMessage(message);
	}
	function receiveMessage(obj)
	{
		document.getElementById('slChat').Content.Page.gotMessage(obj);
	}
&lt;/script&gt;
</pre>
<p>And that’s it. Copy the assets to the appropriate folder under the web root and run it. You will see that the messages you type into the text input at the bottom appear in the message area above. In reality, the message is being transferred from the Silverlight client to the HTML DOM which in turn passes it to the Flex application whose Producer sends the message. As the Consumer in the Flex application receives the message, it sends it back to the DOM from which it is passed to the Silverlight client. </p>
<p>Open the same application in a couple of other windows and see if the messages sent from one instance of the application are seen in the other.</p>
<p>Here is a quick video I made of the applications in action:<br />
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/j8G7sGiCUPc&#038;hl=en&#038;fs=1&#038;rel=0&#038;color1=0x3a3a3a&#038;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/j8G7sGiCUPc&#038;hl=en&#038;fs=1&#038;rel=0&#038;color1=0x3a3a3a&#038;color2=0x999999" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>Buzzy</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.buzzyand.me/2008/10/build-a-silverlight-flex-chat-application-using-livecycle-data-services/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex vs. Silverlight: My Views</title>
		<link>http://blog.buzzyand.me/2008/04/flex-vs-silverlight-my-views/</link>
		<comments>http://blog.buzzyand.me/2008/04/flex-vs-silverlight-my-views/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 21:52:17 +0000</pubDate>
		<dc:creator>buzzy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://extremeblue.wordpress.com/?p=5</guid>
		<description><![CDATA[I have been developing on both Flex and Silverlight for some  time, and now is as good a time as any to evaluate these two exciting  technologies. My goal was to create two similar applications on both Flex and  Silverlight. I decided to redo the Stockastica application. It is an online  [...]]]></description>
			<content:encoded><![CDATA[<p>I have been developing on both Flex and Silverlight for some  time, and now is as good a time as any to evaluate these two exciting  technologies. My goal was to create two similar applications on both Flex and  Silverlight. I decided to redo the Stockastica application. It is an online  stock trading simulation. Last year it was done using ASP.NET. This year I  decided to use the new RIA technologies to dive into the world of Web 2.0.</p>
<p>A word of caution here.   I might be slightly biased towards Flex because I have been developing  on Flash for quite some time and I find it simply fantastic. Also, I used the  Silverlight 2 Beta 1 to build the application. It is obvious that the final  release of the product will address some of the issues described here.</p>
<p>I will put up screencasts showing both the applications in  action soon.</p>
<p>So, let’s begin…</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="319" valign="top">Flex</td>
<td width="319" valign="top">Silverlight</td>
</tr>
<tr>
<td width="319" valign="top">Almost everyone has Flash Player 9 installed on their systems. So    there are no extra downloads required to view these apps.</td>
<td width="319" valign="top">Installing the Silverlight 1.0 plugin was a hassle for me. Then the    upgrade to the 2.0 version was not as seamless as I had expected. Almost no    one has the Silverlight plugin (But Microsoft has Windows update on their    side, one ‘Critical Update’ and the problem is solved <img src='http://blog.buzzyand.me/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   ).</td>
</tr>
<tr>
<td width="319" valign="top">Flex has a rich control library ready for use.</td>
<td width="319" valign="top">Even in Beta 1,  many controls    are missing. Though I expect this problem to be solved by the final release    of the product.</td>
</tr>
<tr>
<td width="319" valign="top">Supports all image formats.</td>
<td width="319" valign="top">Does not support the GIF format. Why? Wasted half an hour on this problem    before I realized this.</td>
</tr>
<tr>
<td width="319" valign="top">Even though AS3 is 10 times faster than AS2 (Ask someone who has    worked with particle systems), it still cannot compare with the power of C#.  Also, can only program in AS3.</td>
<td width="319" valign="top">Very powerful and easy to use. You can use JavaScript, VB.NET and C#.</td>
</tr>
<tr>
<td width="319" valign="top">Linux support <img src='http://blog.buzzyand.me/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </td>
<td width="319" valign="top">No Linux support. That’s just wrong.</td>
</tr>
<tr>
<td width="319" valign="top">Databinding is a snap with the [Bindable] tag.</td>
<td width="319" valign="top">Not as straightforward, but can be done anyway. Also, more powerful(in    my opinion).</td>
</tr>
<tr>
<td width="319" valign="top">Data transfer via the proprietary AMF using WebORB, Fluorine, etc is    faster than traditional web services.</td>
<td width="319" valign="top">No such format for data transfer. Will have to stick to SOAP and REST    web services(for now).</td>
</tr>
<tr>
<td width="319" valign="top">BlazeDS, the real time data push and remoting platform is open    source. Very exciting.</td>
<td width="319" valign="top">!! Did not find much information about this.</td>
</tr>
<tr>
<td width="319" valign="top">Styling is simplified by using CSS to style your components.    Implementation is not complete though. Stuff like background-repeat is a    glaring omission.</td>
<td width="319" valign="top">Have to use XAML resources. Found this unfamiliar.</td>
</tr>
<tr>
<td width="319" valign="top">Debugging is a bit of a hassle.</td>
<td width="319" valign="top">Debugging using Visual Studio is very easy.</td>
</tr>
<tr>
<td width="319" valign="top">Accessing web services requires manual creation of ActionScript proxy    classes. You can automate this by using FlexTense though.</td>
<td width="319" valign="top">Accessing web services is very easy. Just add a reference to the    WebService in Visual Studio and lookup reference.cs for the good stuff <img src='http://blog.buzzyand.me/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </td>
</tr>
<tr>
<td width="319" valign="top">Size of the compiled SWF file is smaller than that of the uncompressed    Silverlight component.</td>
<td width="319" valign="top">Size of the Silverlight component is larger.</td>
</tr>
<tr>
<td width="319" valign="top">!!</td>
<td width="319" valign="top">Get 10 GB of hosting space free with Silverlight streaming. Deliver    rich media. Awesome.</td>
</tr>
<tr>
<td width="319" valign="top">Animation is time based.</td>
<td width="319" valign="top">Animation is frame based. Can’t say which one is better.</td>
</tr>
<tr>
<td width="319" valign="top">Cannot be search engine optimized. Bots can’t read the contents of    the SWF file.</td>
<td width="319" valign="top">I am confused about this after the introduction of the .XAP file.</td>
</tr>
<tr>
<td width="319" valign="top">Deploying the final application is a snap because there is only one SWF    file.</td>
<td width="319" valign="top">Lots of individual files to be deployed.</td>
</tr>
<tr>
<td width="319" valign="top">Got my copy of Flex Builder 3 Pro for free. If you are a student or    faculty member of an educational institution, you can too.</td>
<td width="319" valign="top">Express editions of Visual Studio are available for free.</td>
</tr>
</tbody>
</table>
<p>Those are all the points that come to mind right now. Will update  as I find and learn new stuff.</p>
<p>Buzzy</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.buzzyand.me/2008/04/flex-vs-silverlight-my-views/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
