<?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/"
	>

<channel>
	<title>(.) (.)</title>
	<atom:link href="http://blog.vane.pl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vane.pl</link>
	<description>some random shit from random guy who do the shit</description>
	<pubDate>Mon, 23 Jan 2012 04:23:53 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>dataProvider Flex 4.6 spark DataGrid and Flex 3.6 mx DataGrid comparasion</title>
		<link>http://blog.vane.pl/2012/01/23/flex-46-spark-datagrid-and-flex-36-mx-datagrid-comparasion-dataprovider/</link>
		<comments>http://blog.vane.pl/2012/01/23/flex-46-spark-datagrid-and-flex-36-mx-datagrid-comparasion-dataprovider/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 04:04:32 +0000</pubDate>
		<dc:creator>vane</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[flex 3 and 4 comparasion]]></category>

		<category><![CDATA[flex sdk]]></category>

		<category><![CDATA[flex4]]></category>

		<category><![CDATA[mx]]></category>

		<category><![CDATA[mxml]]></category>

		<category><![CDATA[spark]]></category>

		<guid isPermaLink="false">http://blog.vane.pl/?p=252</guid>
		<description><![CDATA[Well I think DataGrid is the most used control and most power full one in flex, so how it&#8217;s different in spark and mx
DataProvider
The most common thing you do with datagrid is assign dataprovider to it and display data.
There is a significant difference on this method. So let&#8217;s start with flex 3.x cause it&#8217;s interesting [...]]]></description>
			<content:encoded><![CDATA[<p>Well I think DataGrid is the most used control and most power full one in flex, so how it&#8217;s different in spark and mx</p>
<p><strong>DataProvider</strong></p>
<p>The most common thing you do with datagrid is assign dataprovider to it and display data.<br />
There is a significant difference on this method. So let&#8217;s start with flex 3.x cause it&#8217;s interesting one.</p>
<p>First difference is that the DataGrid is the class on top of the mx ListBase and there are mostly all the data operations so the function in ListBase in shortcut (not important lines were removed) looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> dataProvider<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value is <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		collection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span>value as <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value is ICollectionView<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		collection = ICollectionView<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value is IList<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		collection = <span style="color: #000000; font-weight: bold;">new</span> ListCollectionView<span style="color: #66cc66;">&#40;</span>IList<span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value is XMLList<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		collection = <span style="color: #000000; font-weight: bold;">new</span> XMLListCollection<span style="color: #66cc66;">&#40;</span>value as XMLList<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value is <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> xl:XMLList = <span style="color: #000000; font-weight: bold;">new</span> XMLList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		xl += value;
		collection = <span style="color: #000000; font-weight: bold;">new</span> XMLListCollection<span style="color: #66cc66;">&#40;</span>xl<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// convert it to an array containing this one item</span>
		<span style="color: #000000; font-weight: bold;">var</span> tmp:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>value <span style="color: #66cc66;">!</span>= <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
			tmp.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>value<span style="color: #66cc66;">&#41;</span>;
		collection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span>tmp<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// get an iterator for the displaying rows.  The CollectionView's</span>
	<span style="color: #808080; font-style: italic;">// main iterator is left unchanged so folks can use old DataSelector</span>
	<span style="color: #808080; font-style: italic;">// methods if they want to</span>
	iterator = collection.<span style="color: #006600;">createCursor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	collectionIterator = collection.<span style="color: #006600;">createCursor</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//IViewCursor(collection);</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>It&#8217;s now clear that to create own implementation of the dataProvider you need to implement ICollectionView cause it&#8217;s only one without the root class on top of it and make sure you also have strong IViewCursor implementation cause it&#8217;s the most important one. The IViewCursor is iterator for the list that let&#8217;s you display the data.</p>
<p>On the other hand in spark 4.6 you have one big class that inherits from SkinnableContainerBase and is using composition to make Grid with columns and rows so the dataProvider is assigned to Grid - well it&#8217;s using 3 method&#8217;s to do it - that&#8217;s the spirit of the flex 4 design.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//FIRST</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> dataProvider<span style="color: #66cc66;">&#40;</span>value:IList<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
&nbsp;
<span style="color: #808080; font-style: italic;">//SECOND</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> setGridProperty<span style="color: #66cc66;">&#40;</span>propertyName:<span style="color: #0066CC;">String</span>, value:<span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// THIRD - the most valuable and readable for simple grid.dataProvider = value;</span>
<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> setPartProperty<span style="color: #66cc66;">&#40;</span>part:<span style="color: #0066CC;">Object</span>, properties:<span style="color: #0066CC;">Object</span>, propertyName:<span style="color: #0066CC;">String</span>, value:<span style="color: #66cc66;">*</span>, defaults:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span></pre></div></div>

<p>YEAH it sucks ;) well nevermind, the person who wrote it lost the contact with reality, hope they meet the dedline.</p>
<p>The grid dataProvider function looks simple _dataProvider = value, so if you want to implement the custom dataProvider you need implement the IList and the most important function is</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getItemAt<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">index</span>:<span style="color: #0066CC;">int</span>, prefetch:<span style="color: #0066CC;">int</span>=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Object</span></pre></div></div>

<p>cause it&#8217;s using it all the time to get to the data.</p>
<p><strong>Summary</strong><br />
Overall spark DataGrid dataprovider assign is much more straightforward and I need not much time to implement my own, if only all flex4 code will be refactored for performance - what I hope will become true in ASF during the Apache Flex incubation we could have pretty decent platform independent (with AIR captive runtime) framework for developing business applications.</p>
<p>Another thing is with processor time and memory when compiling the flex sdk 3.6 I got 22MB flash debugger application and with flex sdk 4.6 I got 40MB flash debugger application - hope that&#8217;s only the debugging size but the 3.6 datagrid runs a little faster.<br />
I need to try with custom itemrenderers with override data and manualy change with propertyChange event yet.</p>
<p>And that&#8217;s all about my analysis.</p>
<p>Icing on the cake is my custom 8KB only datagrid early prototype, without flex but with custom item renderers (ex time is rendered with custom date) and custom dataprovider. Compiled for SDK 4.6. you can drag  to see 100 generated insturments with code generated data feed.<br />
<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_testmarketwatch2_170932524"
			class="flashmovie"
			width="500"
			height="300">
	<param name="movie" value="http://blog.vane.pl/wp-content/uploads/2012/01/testmarketwatch2.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://blog.vane.pl/wp-content/uploads/2012/01/testmarketwatch2.swf"
			name="fm_testmarketwatch2_170932524"
			width="500"
			height="300">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
<br />
Now without the itemrenderer caching, sorting, css styles.<br />
Similar one compiled in air captive runtime for IOS runs smoothly and takes only 11MB with custom compiled prototype of RPC and real data push inside ;)</p>
<p>Beware of further flex components comparasion and happy codding as always ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vane.pl/2012/01/23/flex-46-spark-datagrid-and-flex-36-mx-datagrid-comparasion-dataprovider/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flex Spark TextInput scroll and position coursor</title>
		<link>http://blog.vane.pl/2012/01/11/flex-spark-textinput-scroll-and-position-coursor/</link>
		<comments>http://blog.vane.pl/2012/01/11/flex-spark-textinput-scroll-and-position-coursor/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 19:31:07 +0000</pubDate>
		<dc:creator>vane</dc:creator>
		
		<category><![CDATA[flex]]></category>

		<category><![CDATA[flex4]]></category>

		<category><![CDATA[spark]]></category>

		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.vane.pl/?p=246</guid>
		<description><![CDATA[Well ex. you want to browse for directory and then display results in ]]></description>
			<content:encoded><![CDATA[<p>Well ex. you want to browse for directory and then display results in <code><s:TextInput</code> to let end user modify it. These operations you can find easy in one place <code>textDisplay</code> property.</p>
<p>And the code:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:WindowedApplication</span> xmlns:fx=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #000000;">					   xmlns:s=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #000000;">					   xmlns:mx=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/mx&quot;</span></span>
<span style="color: #000000;">					   applicationComplete=<span style="color: #ff0000;">&quot;windowedapplication1_applicationCompleteHandler(event)&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;!<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import mx.events.FlexEvent;</span>
&nbsp;
<span style="color: #000000;">			protected function windowedapplication1_applicationCompleteHandler<span style="color: #66cc66;">&#40;</span>event:FlexEvent<span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				var s:String = <span style="color: #ff0000;">&quot;myVeryVeryVeryLongString&quot;</span>;</span>
<span style="color: #000000;">				$myInput.text = s;</span>
<span style="color: #000000;">				$myInput.setFocus<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				$myInput.textDisplay.selectRange<span style="color: #66cc66;">&#40;</span>$myInput.text.length,$myInput.text.length<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				$myInput.textDisplay.scrollToRange<span style="color: #66cc66;">&#40;</span>$myInput.text.length, $myInput.text.length<span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/fx:Script</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;s:TextInput</span> id=<span style="color: #ff0000;">&quot;$myInput&quot;</span> width=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/s:WindowedApplication</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>hope that helps you can find also textDisplay in spark TextArea.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vane.pl/2012/01/11/flex-spark-textinput-scroll-and-position-coursor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Go IOC and DI rewrite your flex code now - sleep well, be happy, drink beer</title>
		<link>http://blog.vane.pl/2011/10/05/go-ioc-and-di-rewrite-your-flex-code-now-sleep-well-be-happy-drink-beer/</link>
		<comments>http://blog.vane.pl/2011/10/05/go-ioc-and-di-rewrite-your-flex-code-now-sleep-well-be-happy-drink-beer/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 21:08:02 +0000</pubDate>
		<dc:creator>vane</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Robotlegs]]></category>

		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[refactoring]]></category>

		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.vane.pl/?p=234</guid>
		<description><![CDATA[Well,
The most important thing when rewriting the old code is to decide which framework chose Yes framework or maybe only some utility classes ex smartypants ioc is better . I will say go with IOC 100% to separate your view from the logic part. You can loose some time when you&#8217;ve got some not organized [...]]]></description>
			<content:encoded><![CDATA[<p>Well,</p>
<p>The most important thing when rewriting the old code is to decide which framework chose Yes framework or maybe only some utility classes ex smartypants ioc is better . I will say go with IOC 100% to separate your view from the logic part. You can loose some time when you&#8217;ve got some not organized code, or you are using the oldie framework but it will benefit in the future.</p>
<p>First Separate your business logic.</p>
<p>Badly written project have some business logic mixed up with the view logic. Services with specific calculations. When you will try to rewrite your application try to group your business methods in one part and the view logic in the other part. It&#8217;s easy in the Robotlegs Mediator so you can see what methods have it&#8217;s view.someFancyComponent reference and what have not. Put the minimum in the view components logic and separate other things to some Helper classes that you can refactor later. If  your project is quite big and getting larger you will see you have some helpers that methods are the same but maybe some little part is different. Try to use it as params. Once you clear your view logic out from business logic  you can separate the business itself to services logic and equations logic. Do equations in separate classes call it some strategy. ex. MyBudgetImportantStrategy if you are using DI you can insert it and decouple with interface and you can use unit tests in the future. The equations logic merely changes when it&#8217;s done right.  And you are ready for webworkers dude. You can then put your all equations to the worker. The update will be 1-2days not 1-2weeks, months when you wrote your code wrong and keep doing it.</p>
<p>Second be elastic with gui.</p>
<p>Well the gui part is the most important thing in the flex. It have changes. Well it is changing all the time. Maybe you remember some css issues when migrating from flex 2 to flex 3 and you will remember rewrite to the flex 4 and then you will remember if your boss told you compile it to mobile. The simple part is IOC. When you have IOC framework with your business logic highly separated from the gui. The gui logic is the bottleneck. If you screw this up and you need to refresh the look of your big enterprise application you are in hell now. You need to keep your mediators smart and simple, decouple the state and change layout logic from the interaction logic. The layout logic it the shit when you need to reorganize your components view the all the old layout is often the shit see the flex 3 and flex 4 states, flex 3 and flex 4 css. But the button clicks as it clicks it is the main functionality for it, combobox often is only combobox and list is a list. But it may be in the different state of your layout now. When you put your view components first think what is your functionality for this control. And try to put the functionality components separate from your layout component&#8217;s don&#8217;t mix them up or they will mix you up when refreshing the look.</p>
<p>Third</p>
<p>Think, read and ask, there are many people out there that have the same problems and there are many authorities in the world of flash/flex that write some good shit about every problem you have. But don&#8217;t chose the first solution of your problem the person who wrote it 3 years ago is not the same programmer now, maybe someone did it better so you can use it . Try to read more, yes it&#8217;s time consuming but when you rewriting you don&#8217;t want to rewrite it again and again. Maybe sometimes it&#8217;s better to mix some solutions up to build something better.  Use event&#8217;s as much as you can you can. Man if you have some performance problems why then not use signals or do some own simple notifications where you send often. The event&#8217;s are for you to keep your life easier not to kill you. Do the commands. The command is the shit cause it only have one functionality. You can separate it and use it in your logic.</p>
<p>Prototype only when your time is very limited but try to separate the 4 logical parts</p>
<p>- layout, - interaction,- services, - equations</p>
<p>cause  flashplayer is crossplatform only from the basis and you interact with phones, tablets other then on desktop or even game console. Your layout and functionality may be different for other screens and equations could be moved to the server when low performance. And on there is still more freedom on the desktop.</p>
<p>Happy codding ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vane.pl/2011/10/05/go-ioc-and-di-rewrite-your-flex-code-now-sleep-well-be-happy-drink-beer/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Extra large modular robotlegs application code organize ?</title>
		<link>http://blog.vane.pl/2011/09/04/extra-large-modular-robotlegs-application-code-organize/</link>
		<comments>http://blog.vane.pl/2011/09/04/extra-large-modular-robotlegs-application-code-organize/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 10:12:44 +0000</pubDate>
		<dc:creator>vane</dc:creator>
		
		<category><![CDATA[Robotlegs]]></category>

		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flash builder]]></category>

		<category><![CDATA[flex]]></category>

		<category><![CDATA[modular]]></category>

		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.vane.pl/?p=231</guid>
		<description><![CDATA[Well when doing some extra large project I was always concerned how to force myself to code right. Not share some dependences across modules not reference to the application, how to manage large codebase and what framework I need to use. Well I chose Robotlegs cause it&#8217;s simple and will be the best way to [...]]]></description>
			<content:encoded><![CDATA[<p>Well when doing some extra large project I was always concerned how to force myself to code right. Not share some dependences across modules not reference to the application, how to manage large codebase and what framework I need to use. Well I chose Robotlegs cause it&#8217;s simple and will be the best way to success and Joel Hooks wrote nice modular extension to it so we can make everything modular.  It&#8217;s amazing that that technology works smoothly without any problems. But let&#8217;s get back to the point.</p>
<p>Well if you have something like 1-10 modules you can keep everything in the same project I think. But what if your plan is to have 20-30 modules ? And by the way you have external people working on your project you not really want to share all your code. How to keep things consistent.  I&#8217;ll share my concept with you cause it&#8217;s simple. LIBRARIES, yes each module should have separate project library so you won&#8217;t use one module  codebase in another module codebase what&#8217;s modular application essential.  Next you need at least one common module for your framework classes that are shared across all modules. Let&#8217;s say it will be the Components, validators, renderers and some other visual related stuff I will name it CORE. I also managed to separate communication module that sends and receives the data from the services. And for this point I wanted to have all my communication classes in another module - let&#8217;s say the API. So you can use the API and give the api and the CORE to the external developer and he will do some shit for you. And you give him only SWC with some documentation not the all codebase.</p>
<p>Some conclusions:</p>
<p>- Unless you are moving something to the  CORE library or API library your project build time will be something like 1-2 seconds. That&#8217;s something. You are not frustrating while flashbuilder is building your project or freezes sometimes without memory.</p>
<p>- You don&#8217;t have to worry that you used some classes across modules and you don&#8217;t know what dependences are - you have it all in CORE. Your modules should be equal in size, and the size won&#8217;t be 10-40kB it will be all the classes you have in the library so 100-200kB so you will save some time while loading big application and showing it to client.</p>
<p>- If you managed to separate your SERVICE to the external module and that&#8217;s with all flash domain policy really hard shit, if you use some remote classes that you send or receive it&#8217;s really messy but then you can use it in some third party related project&#8217;s.</p>
<p>-You can then give the API and CORE  and see what other people will build with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vane.pl/2011/09/04/extra-large-modular-robotlegs-application-code-organize/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Simple http push server for flash using python twisted</title>
		<link>http://blog.vane.pl/2011/07/02/simple-http-push-server-for-flash-using-python-twisted/</link>
		<comments>http://blog.vane.pl/2011/07/02/simple-http-push-server-for-flash-using-python-twisted/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 17:47:49 +0000</pubDate>
		<dc:creator>vane</dc:creator>
		
		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[as3]]></category>

		<category><![CDATA[python]]></category>

		<category><![CDATA[streaming]]></category>

		<guid isPermaLink="false">http://blog.vane.pl/?p=222</guid>
		<description><![CDATA[I was preety busy at work. Sorry for not posting. I will try to post once a month from now.
The networing profiler project was stopped due to my work but I will try to finish it&#8217;s simple and post the sources. To the point.
In my workplace we are pushing some data to the clients, and [...]]]></description>
			<content:encoded><![CDATA[<p>I was preety busy at work. Sorry for not posting. I will try to post once a month from now.<br />
The networing profiler project was stopped due to my work but I will try to finish it&#8217;s simple and post the sources. To the point.</p>
<p>In my workplace we are pushing some data to the clients, and more websites are pushing realtime data so it made me think. How hard it&#8217;s to write simple http push server for actionscript using python ?</p>
<p>Well it seems not so hard cause we got great library for it twisted. So let&#8217;s get started on server side:</p>
<p>We will be using <a href="http://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html">twisted web server and Site object</a>,<em>JSON</em> to send data, <em>simplejson</em> library to convert our objects to <em>JSON</em></p>
<p>So we start by creating simple class Test with GET and POST handlers and in get we add server.NOT_DONE_YET to never stop sending GET request once connected. In <strong><em>__init__</em></strong> method we declare array for users and array for messages to pass. Next we add <strong>LoopingCall</strong> task to throtle messages for our clients every 250ms, and define method<strong><em> __print_time</em></strong> that we will be using to create messages. Well <strong><em>__print_time</em></strong> is simple method that we pass time and messages when there are any in our messages array.<br />
We simply loop in our users array and add aditional message to send.</p>
<p>Things to improve:<br />
1. detect when user disconnect<br />
2. add user id when connected<br />
3. replace json with amf protocol</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor, task
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span>.<span style="color: black;">server</span> <span style="color: #ff7700;font-weight:bold;">import</span> Site
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span> <span style="color: #ff7700;font-weight:bold;">import</span> server
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span>.<span style="color: #dc143c;">resource</span> <span style="color: #ff7700;font-weight:bold;">import</span> Resource
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> simplejson <span style="color: #ff7700;font-weight:bold;">as</span> json
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Test<span style="color: black;">&#40;</span>Resource<span style="color: black;">&#41;</span>:
    isLeaf = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">json_encoder</span> = json.<span style="color: black;">JSONEncoder</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">users</span>=<span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">messages</span> = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
        loopingCall = task.<span style="color: black;">LoopingCall</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.__print_time<span style="color: black;">&#41;</span>
        loopingCall.<span style="color: black;">start</span><span style="color: black;">&#40;</span>.25, <span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
        Resource.<span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> render_GET<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        request.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">json_encoder</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;time&quot;</span>:<span style="color: #dc143c;">time</span>.<span style="color: black;">ctime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;type&quot;</span>:<span style="color: #483d8b;">&quot;CONNECT&quot;</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;client connected&quot;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">users</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;number clients:&quot;</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">users</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> server.<span style="color: black;">NOT_DONE_YET</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> render_POST<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> request.<span style="color: black;">args</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;msg&quot;</span><span style="color: black;">&#93;</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">messages</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>request.<span style="color: black;">args</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> request.<span style="color: black;">args</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> __print_time<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        sendMSG = <span style="color: #008000;">None</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">messages</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">0</span>:
            sendMSG=<span style="color: #008000;">self</span>.<span style="color: black;">messages</span>.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
        <span style="color: #808080; font-style: italic;"># keep alive connection</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> p <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">self</span>.<span style="color: black;">users</span>:
            p.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">json_encoder</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;time&quot;</span>:<span style="color: #dc143c;">time</span>.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;msg&quot;</span>:<span style="color: black;">&#91;</span>sendMSG<span style="color: black;">&#93;</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;server start&quot;</span>
<span style="color: #dc143c;">resource</span> = Test<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
factory = Site<span style="color: black;">&#40;</span><span style="color: #dc143c;">resource</span><span style="color: black;">&#41;</span>
reactor.<span style="color: black;">listenTCP</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8081</span>, factory<span style="color: black;">&#41;</span>
reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;server stop&quot;</span></pre></div></div>

<p>Next what about client, some time ago I started simple library for my inhouse projects.<br />
I created simple HTTPConnection class where I use URLStream for handling connection and some self created Observer for listening events instead of eventDispatcher.<br />
Well I will not describe my classes here but only show the main class for the server class in python.<br />
The main method is  init where we create gui, HTTPConnection named consumer and some logger. We add event for progress where we simply try to parse json using as3corelib and if we have some messages we try to display it in our gui. when we press ENTER in our upper TextField we are simply sending post to the same url.</p>
<p>Things to improve:<br />
1. detect when disconnected and try to reconnect<br />
2. parse messages only when we need</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> clazz.<span style="color: #006600;">GUI</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">serialization</span>.<span style="color: #006600;">json</span>.<span style="color: #006600;">JSON</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">DataEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">ProgressEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequestMethod</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> pl.<span style="color: #006600;">vane</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">errors</span>.<span style="color: #006600;">Throws</span>;
	<span style="color: #0066CC;">import</span> pl.<span style="color: #006600;">vane</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">logging</span>.<span style="color: #006600;">ILog</span>;
	<span style="color: #0066CC;">import</span> pl.<span style="color: #006600;">vane</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">logging</span>.<span style="color: #0066CC;">Log</span>;
	<span style="color: #0066CC;">import</span> pl.<span style="color: #006600;">vane</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">net</span>.<span style="color: #006600;">HTTPConnection</span>;
	<span style="color: #0066CC;">import</span> pl.<span style="color: #006600;">vane</span>.<span style="color: #006600;">framework</span>.<span style="color: #006600;">net</span>.<span style="color: #006600;">IConnection</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>
				addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, init<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span>
				init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _gui:GUI;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _consumer:IConnection;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _log:ILog;
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>event:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_gui = <span style="color: #000000; font-weight: bold;">new</span> GUI;
			_gui.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>DataEvent.<span style="color: #0066CC;">DATA</span>, dataSendHandler<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>_gui<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_consumer = <span style="color: #000000; font-weight: bold;">new</span> HTTPConnection;
			_consumer.<span style="color: #006600;">observer</span>.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, connectionCompleteHandler<span style="color: #66cc66;">&#41;</span>;
			_consumer.<span style="color: #006600;">observer</span>.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, connectionProgressHandler<span style="color: #66cc66;">&#41;</span>;
			_consumer.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://127.0.0.1:8081&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_log = <span style="color: #0066CC;">Log</span>.<span style="color: #006600;">getLogger</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			_gui.<span style="color: #006600;">appendText</span> = <span style="color: #ff0000;">&quot;start<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
			_log.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;start&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> dataSendHandler<span style="color: #66cc66;">&#40;</span>event:DataEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// TODO Auto-generated method stub</span>
			<span style="color: #000000; font-weight: bold;">var</span> c:IConnection = <span style="color: #000000; font-weight: bold;">new</span> HTTPConnection<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
			c.<span style="color: #006600;">observer</span>.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, <span style="color: #000000; font-weight: bold;">function</span> complete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:ByteArray<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
			<span style="color: #66cc66;">&#123;</span>
				_log.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>.<span style="color: #006600;">bytesAvailable</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #000000; font-weight: bold;">var</span> r:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://127.0.0.1:8081&quot;</span><span style="color: #66cc66;">&#41;</span>;
			r.<span style="color: #0066CC;">data</span> = encodeURI<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;msg=&quot;</span> + event.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
			r.<span style="color: #006600;">method</span> = URLRequestMethod.<span style="color: #006600;">POST</span>;
			c.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>r<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> connectionProgressHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:ByteArray<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// TODO Auto Generated method stub</span>
			<span style="color: #000000; font-weight: bold;">var</span> next:<span style="color: #0066CC;">String</span> = <span style="color: #0066CC;">data</span>.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>.<span style="color: #006600;">bytesAvailable</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> o:<span style="color: #0066CC;">Object</span>;
			<span style="color: #0066CC;">try</span>
			<span style="color: #66cc66;">&#123;</span>
				o = JSON.<span style="color: #006600;">decode</span><span style="color: #66cc66;">&#40;</span>next<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				Throws.<span style="color: #0066CC;">error</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>o<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_log.<span style="color: #006600;">track</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #0066CC;">time</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&amp;</span>amp;<span style="color: #66cc66;">&amp;</span>amp; o.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#41;</span>
					<span style="color: #66cc66;">&#123;</span>
						_gui.<span style="color: #006600;">appendText</span> = o.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">msg</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
					<span style="color: #66cc66;">&#125;</span>
					_log.<span style="color: #006600;">info</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">msg</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
				<span style="color: #808080; font-style: italic;">//chat.text = next+ &quot;\n&quot; + chat.text;</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;DUPA:&quot;</span>+<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> connectionCompleteHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>:ByteArray<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// TODO Auto Generated method stub</span>
			_log.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data&quot;</span> + <span style="color: #0066CC;">data</span>.<span style="color: #006600;">readUTFBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span>.<span style="color: #006600;">bytesAvailable</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And the gui class for display the messages:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package clazz
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">DataEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyboardEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #006600;">TextFieldType</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">ui</span>.<span style="color: #006600;">Keyboard</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Event<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>=<span style="color: #ff0000;">&quot;data&quot;</span>, <span style="color: #0066CC;">type</span>=<span style="color: #ff0000;">&quot;flash.events.DataEvent&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GUI <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _txt:<span style="color: #0066CC;">TextField</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _msg:<span style="color: #0066CC;">TextField</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> GUI<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>
				addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, init<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span>
				init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span>event:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>_txt<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_txt = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span>;
				_txt.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #0066CC;">DYNAMIC</span>;
				addChild<span style="color: #66cc66;">&#40;</span>_txt<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>_msg<span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_msg = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span>;
				_msg.<span style="color: #0066CC;">type</span> = TextFieldType.<span style="color: #006600;">INPUT</span>;
				_msg.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>KeyboardEvent.<span style="color: #006600;">KEY_DOWN</span>, keyDownHandler<span style="color: #66cc66;">&#41;</span>;
				_msg.<span style="color: #0066CC;">border</span> = <span style="color: #000000; font-weight: bold;">true</span>;
				addChild<span style="color: #66cc66;">&#40;</span>_msg<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			resizeHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">RESIZE</span>, resizeHandler<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> keyDownHandler<span style="color: #66cc66;">&#40;</span>event:KeyboardEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">keyCode</span> == Keyboard.<span style="color: #0066CC;">ENTER</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				dispatchEvent<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> DataEvent<span style="color: #66cc66;">&#40;</span>DataEvent.<span style="color: #0066CC;">DATA</span>, <span style="color: #000000; font-weight: bold;">false</span>, <span style="color: #000000; font-weight: bold;">false</span>, _msg.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
				_msg.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> appendText<span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_txt.<span style="color: #0066CC;">text</span> = value+_txt.<span style="color: #0066CC;">text</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> resizeHandler<span style="color: #66cc66;">&#40;</span>event:Event = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_txt.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">0</span>;
			_txt.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">50</span>;
			_txt.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;
			_txt.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> - <span style="color: #cc66cc;">50</span>;
&nbsp;
			_msg.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">0</span>;
			_msg.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">0</span>;
			_msg.<span style="color: #0066CC;">width</span> = <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>;
			_msg.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">50</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>And that&#8217;s it. The exported swf size is wow 12KB, not much :)<br />
Any questions please post in comments.<br />
Sources are below, i will try to post my HTTPConnection class sources with others on github as soon as I will have some more time.<br />
Just run twisted_stream.py in server folder and Main.swf in client/bin-release</p>
<p><a href="http://blog.vane.pl/wp-content/uploads/2011/07/twistedstream.zip">twistedstream</a></p>
<p>Have fun :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vane.pl/2011/07/02/simple-http-push-server-for-flash-using-python-twisted/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

