<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>SnippetRepoBrowser</title>
    <link>http://snippet.gnstudio.com/snippetrepobrowser/index</link>    
    <description>RSS Feed of SnippetRepoBrowser (Global RSS)</description>    
    <language>en-us</language>
    <pubDate>Fri, 18 May 2012 14:27:18 +0200</pubDate>
    <docs>SnippetRepoBrowser/index</docs>
    <generator>SnippetRepoBrowser Feed Generator</generator>
    <item>
      <title><![CDATA[Filter messages using the logcat command]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/112</link>
      <description><![CDATA[When working on mobile with AIR you cab use the <a href="http://developer.android.com/guide/developing/tools/logcat.html" target="_blank">logcat tool</a> available in the Andorid SDK to grab information from the device and dumping them via USB on a log screen.<br />If you are interested to get only the trace statements and the ActionScript error messages you can restict the logcat output via command line with the snippet you find below. <br />The reason why you can do this filtering is because during the packaging process each AIR application has the word <span style="font-style:italic">air</span> added to the application ID, therefore using the filter I.air guarantees to dump all messages for the currently running AIR application.<br />The letter <span style="font-style:italic">I</span> stays for the <span style="font-style:italic">Information</span> priority level.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">androidSDK/platform-tools/adb logcat|grep &quot;I.air&quot;</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Sun, 13 Nov 2011 17:24:57 +0100</pubDate>
      <category>Air</category>
      <guid>http://snippet.gnstudio.com/viewtopic/112</guid>
   </item><item>
      <title><![CDATA[TextFlow autoscroll with multiple lines]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/111</link>
      <description><![CDATA[If you&#39;re using TextFlow for a chat room or in similar cases, when users keep adding text to the flow and you need to kepp the latest messages visible, you have to pay attention about when to set the verticalScrollPosition.<br />In fact, if you wait for the CompositionCompleteEvent.COMPOSITION_COMPLETE event to trigger to set it, you&#39;ll have issues with multiple lines. To be precise, only the first line of the message will be shown even if the text will scroll up to make space for all the lines.<br />The correct way to make it scroll, is to call composeToPosition() on the flowComposer right after adding the new text and, this will force a recalculation of the bound sizes and a recomposition of the text, then immediatly set the verticalScrollPosition.<br />After an update of the controllers the text will show correctly at the right position.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">import flashx.textLayout.elements.TextFlow;<br />import flashx.textLayout.conversion.TextConverter;<br />import flashx.textLayout.container.ContainerController;<br />import flash.utils.Timer;<br />import flash.events.TimerEvent;<br />import flashx.textLayout.elements.ParagraphElement;<br />import flashx.textLayout.container.ScrollPolicy;<br />import flash.display.Sprite;<br />import flash.geom.Rectangle;<br /><br />var container:Sprite = new Sprite();<br />addChild(container);<br /><br />var size:Rectangle = new Rectangle(0,0,200,300);<br /><br />var chat:TextFlow = TextConverter.importToFlow(&quot;&quot;, TextConverter.PLAIN_TEXT_FORMAT);<br />var roller:ContainerController = new ContainerController(container, size.width, size.height);<br />roller.verticalScrollPolicy = ScrollPolicy.ON;<br />chat.flowComposer.addController(roller);<br />chat.flowComposer.updateAllControllers(); <br /><br />var timer:Timer = new Timer(1000);<br />timer.addEventListener(TimerEvent.TIMER, onTimerTick);<br />timer.start();<br /><br />function onTimerTick(event:TimerEvent):void {<br />	<br />	var text:String;<br />	switch(timer.currentCount%3)<br />	{<br />		case 0:<br />			text = &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ultricies lobortis nulla, et posuere nibh lacinia ut. Sed dolor sapien, porta nec sodales vitae, commodo vel quam. Nam sit amet nibh et nisl pulvinar scelerisque a vitae ligula. Maecenas vehicula dictum sollicitudin.&quot;;<br />			break;<br />		case 1:<br />			text = &quot;Phasellus eget pretium sem. Curabitur ut nunc at nunc posuere congue. Nullam id velit nisl, ut condimentum urna. Nam erat arcu, hendrerit pulvinar posuere non, lobortis a risus. Vivamus dolor odio, accumsan ut ultrices sed, tristique et tellus. Sed cursus lacinia dui ac condimentum. Aenean et accumsan orci.&quot;;<br />			break;<br />		case 2:<br />			text = &quot;Vestibulum mollis porttitor posuere. In varius, ipsum nec placerat viverra, ipsum massa scelerisque diam, at pharetra sem metus eu neque. Pellentesque bibendum neque sapien, sit amet tincidunt magna. Suspendisse potenti. Etiam fermentum iaculis augue vel ullamcorper. Morbi ante arcu, suscipit placerat ornare viverra, elementum a tortor.&quot;;<br />			break;<br />	} <br />	<br />	appendText(text);<br />}<br /><br />function appendText(text:String):void {<br />	<br />	var flow:TextFlow = TextConverter.importToFlow(text, TextConverter.PLAIN_TEXT_FORMAT);<br />	var paragraph:ParagraphElement = flow.getChildAt(0) as ParagraphElement;<br />	chat.addChild(paragraph);<br />	roller.flowComposer.composeToPosition(); // call a recomposition so later we&#39;ll have the real size from getContentBounds<br />	roller.verticalScrollPosition = roller.getContentBounds().height - roller.compositionHeight;<br />	roller.flowComposer.updateAllControllers();<br />}<br /></pre></div><br /><br />]]></description>
      <author>cyberpunk</author>
      <pubDate>Fri, 02 Sep 2011 13:55:46 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/111</guid>
   </item><item>
      <title><![CDATA[Detect Internet Explorer and its version]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/110</link>
      <description><![CDATA[Unfortunately sometime is pretty useful to understand if the JavaScript is executed into Internet Explorer and the version of the browser, you can recover all this information with the usage of regular expressions.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ <br /> <br />     var version = new Number(RegExp.$1);<br />     // Do whatever you want with the version information<br /><br />}</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Wed, 24 Aug 2011 05:08:31 +0200</pubDate>
      <category>JavaScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/110</guid>
   </item><item>
      <title><![CDATA[JQuery tools overlay handling]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/109</link>
      <description><![CDATA[There are several JavaScript libraries that can help you to create an overlay effect, a good one should be <a href="http://flowplayer.org/tools/overlay/index.html" target="_blank">JQuery tools</a>.<br />A common issue with this library is that the auto load feature allow you to load only once the overlay, second time you try to load it nothing happens and no errors appear. <br />To solve this issue you can disable the auto load feature in the configuration and manually handle the closure of the overaly binding and unbinding the click event to the document object using jQuery.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">var currentOverlay;<br /><br />function openOverlay(){<br />	<br />	var config = {};<br />	<br />	config[&#39;mask&#39;] = {<br />	<br />			// you might also consider a &quot;transparent&quot; color for the mask<br />			color: &#39;#000000&#39;,<br />				<br />			// load mask a little faster<br />			loadSpeed: 300,<br />				<br />			// very transparent<br />			opacity: .6<br />						<br />			};<br />	config[&#39;closeOnClick&#39;] = false;<br />	config[&#39;load&#39;] = false;<br />	config[&#39;top&#39;] = &#39;40%&#39;;<br />	config[&#39;onLoad&#39;] = activateCloseHandler;<br />	config[&#39;onClose&#39;] = removeCloseHandler;<br />	<br />	$(&quot;#theDivYouWantToOpenInOverlay&quot;).overlay(config);<br />	currentOverlay = $(&quot;#theDivYouWantToOpenInOverlay&quot;).data(&quot;overlay&quot;).load();<br />	<br />}<br /><br />function activateCloseHandler(event){<br />	<br />	$(document).click(function(e) {<br />  		<br />		e.stopPropagation();<br />		currentOverlay.close();<br />		<br />	});<br />	<br />}<br /><br />function removeCloseHandler(event){<br />	<br />	$(document).unbind(&#39;click&#39;);<br />	<br />}</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Tue, 16 Aug 2011 07:04:42 +0200</pubDate>
      <category>JavaScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/109</guid>
   </item><item>
      <title><![CDATA[Language Management and multilang web app]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/108</link>
      <description><![CDATA[A common issue in a web application is handling the automatic language detection and the selection of a specific language made by an user.<br />A possible approach is to keep the language handling client side and handle it through JavaScript. In order to do this you can manipulate the URL and append and recover values using the <a href="http://code.google.com/p/jsuri/" target="_blank">jsuri</a> library hosted on google code and encapsulate the language detection in a script included in each page.<br />The steps the script has to perform are:<br /><br /><ul style="list-style-type:decimal"><li>Declare a varbiable to store the current language</li><br /><li>Recover the browser language</li><br /><li>Check if the URL already contains a language query string param</li><br /><li>Change the href value of your page or populate the variable that contains the current language</li><br /></ul><br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">var currentLanguage;<br />	<br />if (navigator.appName == &#39;Netscape&#39;){<br />		<br />	var language = navigator.language;<br />		<br />}else{<br />		<br />	var language = navigator.browserLanguage;<br />		<br />}<br />	<br />if (language.indexOf(&#39;en&#39;) &gt; -1) currentLanguage = &quot;en&quot;;<br />else if (language.indexOf(&#39;it&#39;) &gt; -1) currentLanguage = &quot;it&quot;;<br />else currentLanguage = &quot;en&quot;;<br />	<br />var uri = new jsUri(location.href);<br />	<br />if(!uri.getQueryParamValue(&#39;lang&#39;)){<br />		<br />	uri.setQuery(&#39;?lang=&#39; + currentLanguage);<br />	location.href = uri;<br />		<br />}else{<br />		<br />	currentLanguage = getQueryParamValue(&#39;lang&#39;);<br />		<br />}<br />	</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Tue, 16 Aug 2011 06:54:22 +0200</pubDate>
      <category>JavaScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/108</guid>
   </item><item>
      <title><![CDATA[Dynamically add JavaScript]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/107</link>
      <description><![CDATA[In order to add dynamically a script to your page you can use the DOM and access the header, in this way you can be sure that the page will contain this file before other script will be executed.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">var currentFile = &#39;test&#39;;<br /><br />var headID = document.getElementsByTagName(&quot;head&quot;)[0];  <br />var script = document.createElement( &#39;script&#39; );<br />script.type = &#39;text/javascript&#39;;<br />script.src = &#39;js/&#39; + currentFile + &#39;.js&#39;;<br />headID.appendChild( script );</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Sat, 06 Aug 2011 18:15:55 +0200</pubDate>
      <category>DOM</category>
      <guid>http://snippet.gnstudio.com/viewtopic/107</guid>
   </item><item>
      <title><![CDATA[CSS and orientation mode on iOS devices]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/106</link>
      <description><![CDATA[You can use media query in your CSS in order to load the appropriate file accordingly to the device orientation.<br />In order to do this you can create a main.css file for your mobile web page and the use inside it media query combined with the import directive.<br />This sinppet is particulary tailored of iOS devices<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">@import url(&quot;portrait.css&quot;) all and (orientation:portrait);<br />@import url(&quot;landscape.css&quot;) all and (orientation:landscape);</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Tue, 05 Jul 2011 08:55:08 +0200</pubDate>
      <category>Uncategorized</category>
      <guid>http://snippet.gnstudio.com/viewtopic/106</guid>
   </item><item>
      <title><![CDATA[&quot;Pure&quot; ActionScript Main Application File in Flex 4]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/105</link>
      <description><![CDATA[In order to have a clean main application file in Flex 4 we can define a custom application skin and remove contentGroup from it. This way there is no way to add any mxml elements inside of the main application file. Even if you do, they wont show up. Main application file in this way has only the script block and maybe metadata and other similar blocks if you declare them. At the end you will have almost perfectly clean main application file. Here is the example.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">// Application File.<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;s:Application xmlns:fx=&quot;<a href="http://ns.adobe.com/mxml/2009&quot;" target="_blank"><a href="http://ns.adobe.com/mxml/2009&quot;" target="_blank">http://ns.adobe.com/mxml/2009&quot;</a></a><br />			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;<br />			   xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;<br />			   skinClass=&quot;com.gnstudio.skins.MyApplicationSkin&quot;<br />			   preinitialize=&quot;onPreinitialize(event)&quot;<br />			   minWidth=&quot;700&quot; minHeight=&quot;440&quot;&gt;<br /><br />	&lt;fx:Metadata&gt;<br />		[ResourceBundle(&quot;IB_Main&quot;)]<br />	&lt;/fx:Metadata&gt;<br /><br />	&lt;fx:Style source=&quot;../css/main.css&quot;/&gt;<br />	&lt;fx:Style source=&quot;../css/fonts.css&quot;/&gt;<br /><br />	&lt;fx:Script&gt;<br />		&lt;![CDATA[<br />			private function onPreinitialize(event:FlexEvent):void {<br /><br />				// Initialize your application here.<br /><br />			}<br /><br />			private function myMethod():void {<br />				<br />				// My method stup. All components are in MyApplicationSkin.<br /><br />			}<br />		]]&gt;<br />	&lt;/fx:Script&gt;<br /><br />&lt;/s:Application&gt;<br /><br /><br />// Application Skin.<br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;s:Skin xmlns:fx=&quot;<a href="http://ns.adobe.com/mxml/2009&quot;" target="_blank"><a href="http://ns.adobe.com/mxml/2009&quot;" target="_blank">http://ns.adobe.com/mxml/2009&quot;</a></a><br />		xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;<br />		xmlns:fb=&quot;<a href="http://ns.adobe.com/flashbuilder/2009&quot;" target="_blank"><a href="http://ns.adobe.com/flashbuilder/2009&quot;" target="_blank">http://ns.adobe.com/flashbuilder/2009&quot;</a></a><br />		alpha.disabled=&quot;0.5&quot;&gt;<br /><br />	&lt;fx:Metadata&gt;[HostComponent(&quot;MyApplication&quot;)]&lt;/fx:Metadata&gt;<br /><br />	&lt;s:states&gt;<br />		&lt;s:State name=&quot;normal&quot;/&gt;<br />		&lt;s:State name=&quot;disabled&quot;/&gt;<br />	&lt;/s:states&gt;<br /><br />	&lt;!-- application background --&gt;<br />	&lt;s:Rect left=&quot;0&quot; right=&quot;0&quot; top=&quot;0&quot; bottom=&quot;0&quot;&gt;<br />		&lt;s:fill&gt;<br />			&lt;s:SolidColor color=&quot;#FFFFFF&quot;/&gt;<br />		&lt;/s:fill&gt;<br />	&lt;/s:Rect&gt;<br /><br />	&lt;s:Group left=&quot;0&quot; right=&quot;0&quot; top=&quot;0&quot; bottom=&quot;0&quot;&gt;<br /><br />		&lt;my:Component1 id=&quot;component1&quot;/&gt;<br />		&lt;my:Component2 id=&quot;component2&quot;/&gt;<br /><br />	&lt;/s:Group&gt;<br /><br />&lt;/s:Skin&gt;</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 24 Jun 2011 15:50:20 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/105</guid>
   </item><item>
      <title><![CDATA[Spark Custom States]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/104</link>
      <description><![CDATA[When defining custom states for your spark component, make sure you override getCurrentSkinState() method. You will determine skin state according to your custom and some already existing flags like enabled. Here is an example.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">//----------------------------------<br />// States<br />//----------------------------------<br /><br />/**<br /> *  Opened Normal State<br /> *  <br /> *  @langversion 3.0<br /> *  @playerversion Flash 10<br /> *  @playerversion AIR 1.5<br /> *  @productversion Flex 4<br /> */<br />[SkinState(&quot;openedNormal&quot;)]<br /><br />/**<br /> *  Opened Disabled State<br /> *  <br /> *  @langversion 3.0<br /> *  @playerversion Flash 10<br /> *  @playerversion AIR 1.5<br /> *  @productversion Flex 4<br /> */<br />[SkinState(&quot;openedDisabled&quot;)]<br /><br />/**<br /> *  Closed Normal State<br /> *  <br /> *  @langversion 3.0<br /> *  @playerversion Flash 10<br /> *  @playerversion AIR 1.5<br /> *  @productversion Flex 4<br /> */<br />[SkinState(&quot;closedNormal&quot;)]<br /><br />/**<br /> *  Closed Disabled State<br /> *  <br /> *  @langversion 3.0<br /> *  @playerversion Flash 10<br /> *  @playerversion AIR 1.5<br /> *  @productversion Flex 4<br /> */<br />[SkinState(&quot;closedDisabled&quot;)]<br /><br /><br />override protected function getCurrentSkinState():String {<br />	<br />	var state:String;<br />	if (opened) {<br />		state = enabled ? &quot;openedNormal&quot; : &quot;openedDisabled&quot;;<br />	} else {<br />		state = enabled ? &quot;closedNormal&quot; : &quot;closedDisabled&quot;;				<br />	}<br />	return state;<br />	<br />}</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 24 Jun 2011 15:36:30 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/104</guid>
   </item><item>
      <title><![CDATA[Complex Renderer Mouse Handling]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/103</link>
      <description><![CDATA[If you have a renderer that has many different components and you need to mouse out and mouse over events when user moves mouse over the renderer, you have two options. Use only one element of your complex renderer to detect mouse over and mouse out. If this is not acceptable the other solution is to set mouseChildren to false on the renderer and use hit test in order to detect mouse interaction on different renderer elements. Check out the example of complex renderer event handling done with hit test approach.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">private function onListRendererAdd(event:RendererExistenceEvent):void {<br />	<br />	var renderer:DisplayObjectContainer = event.renderer as DisplayObjectContainer;<br />	if (renderer) {<br />		<br />		renderer.mouseChildren = false;<br />		<br />		renderer.addEventListener(MouseEvent.MOUSE_OVER, onListRendererOver);<br />		renderer.addEventListener(MouseEvent.MOUSE_OUT, onListRendererOut);<br />		renderer.addEventListener(MouseEvent.CLICK, onListRendererSelection);<br />		renderer.addEventListener(MouseEvent.CLICK, onListRendererInfo);<br />		<br />	}<br />	<br />}<br /><br />private function onListRendererRemove(event:RendererExistenceEvent):void {<br />	<br />	var renderer:IEventDispatcher = event.renderer as IEventDispatcher;<br />	if (renderer) {<br />		renderer.removeEventListener(MouseEvent.MOUSE_OVER, onListRendererOver);<br />		renderer.removeEventListener(MouseEvent.MOUSE_OUT, onListRendererOut);<br />		renderer.removeEventListener(MouseEvent.CLICK, onListRendererSelection);<br />		renderer.removeEventListener(MouseEvent.CLICK, onListRendererInfo);<br />	}<br />	<br />}		<br /><br />private function onListRendererOver(event:MouseEvent):void {<br />	<br />	// This event will be dispatched only once when user rolls over the renderer.	<br />	<br />}<br /><br />private function onListRendererOut(event:MouseEvent):void {<br />	<br />	// This event will be dispatched only once when user moves from the renderer.<br />	<br />}<br /><br />private function onListRendererSelection(event:MouseEvent):void {<br />	<br />	var renderer:DisplayObject = event.target;<br />	if (renderer &amp;&amp; renderer.selectionControl.hitTestPoint(event.stageX, event.stageY)) {<br />		<br />		// Check if the mouse was on the selection control when the click event was dispatched.<br />		// This way we know that the mouse click was on the selection control.<br />			<br />	}<br />	<br />}<br /><br /><br />private function onListRendererInfo(event:MouseEvent):void {<br />	<br />	var renderer:DisplayObject = event.target;<br />	if (renderer &amp;&amp; renderer.infoControl.hitTestPoint(event.stageX, event.stageY)) {<br />		<br />		// Check if the mouse was on the info control when the click event was dispatched.<br />		// This way we know that the mouse click was on the info control.<br />			<br />	}<br />	<br />}</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 24 Jun 2011 15:26:45 +0200</pubDate>
      <category>Flex 3.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/103</guid>
   </item><item>
      <title><![CDATA[Spark Item by Item Scrolling List like in Flex 3 mx List ]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/102</link>
      <description><![CDATA[Spark list vertical scroll setup that works like Flex 3 mx list item by item scrolling. The point is to setup s:VScrollBar with smoothScrolling false and to set step size that equals list item height. You will also want to set the list height in a way that list items don&#39;t get cut off at the bottom (list height = n x item height).<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;s:DataGroup id=&quot;contentGroup&quot; width=&quot;341&quot; height=&quot;100&quot;&gt;<br />	&lt;s:layout&gt;<br />		&lt;s:TileLayout horizontalGap=&quot;9&quot; verticalGap=&quot;0&quot; columnWidth=&quot;69&quot; requestedColumnCount=&quot;4&quot;/&gt;<br />	&lt;/s:layout&gt;<br />&lt;/s:DataGroup&gt;<br /><br />&lt;s:VScrollBar viewport=&quot;{contentGroup}&quot; top=&quot;0&quot; left=&quot;330&quot; height=&quot;100&quot; smoothScrolling=&quot;false&quot; stepSize=&quot;100&quot;/&gt;</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 24 Jun 2011 15:08:40 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/102</guid>
   </item><item>
      <title><![CDATA[Spark Scrolling List]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/101</link>
      <description><![CDATA[Easy and quick setup of spark list with vertical scroll.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;s:DataGroup id=&quot;contentGroup&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;<br />	&lt;s:layout&gt;<br />		&lt;s:VerticalLayout/&gt;<br />	&lt;/s:layout&gt;<br />&lt;/s:DataGroup&gt;<br /><br />&lt;s:VScrollBar viewport=&quot;{contentGroup}&quot;/&gt;</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 24 Jun 2011 15:00:52 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/101</guid>
   </item><item>
      <title><![CDATA[ALT GR + foreign keyboards workaround]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/100</link>
      <description><![CDATA[With Firefox and Chrome the handling of the ALT GR keyboards combination fails silently.<br />We found a workaround based on the usage of an instance of the class LocalConnection in an SWF file based on ActionScript 1.0 (available <a href="http://forums.adobe.com/message/2129911" target="_blank">here</a>) but we strongly avoid to use AS1 also for workaraounds like this.<br />The solution we outlined is available <a href="http://wip.gnstudio.com/specialchars/SpecialCharsTest.html" target="_blank">here</a>, is based on JavaScript and ActionScript 3.0 and can be summarized as following<br /><ul><li>Instead of using a input text filed use a dynamic text field</li><li>Through a Cursor class (the one available in the following snippet) the standard cursor behavior is simulated</li><li>The focus is immediately removed from the text field and moved to the body of the HTML page</li><li>The HTML page handle the keyboard pressure and communicate with the SWF file through JavaScript</li></ul><br /><br />The source code is not fully implemented so consider it as a proof of concept (POC), in the demo you can take a look to the behavior of a dynamic text field and of a input text field. In order to download the code you have to create an account.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">package  {<br />	import flash.display.Sprite;<br />	import flash.text.TextField;<br />	import flash.events.Event;<br />	import flash.events.TextEvent;<br />	import flash.events.FocusEvent;<br />	import flash.utils.Timer;<br />	import flash.events.TimerEvent;<br />	import flash.display.Graphics;<br />	<br />	public class Cursor extends Sprite {<br />		<br />		private var target:TextField;		<br />		private var timer:Timer;<br />		<br />		private const CURSOR_DELAY:int = 400;<br />		private const PADDING_BOTTOM:int = 4;<br />		private const PADDING_TOP:int = 4;<br />		private const PADDING_LEFT:int = 2;		<br />		<br />		private var _cursorDelay:int;<br />		private var drawable:Boolean;<br />				<br />		private var _paddingTop:int;<br />		private var _paddingLeft:int;<br />		private var _paddingBottom:int;<br />		<br />		public static const ACTIVATE_INTERACTION:String = &quot;onActivateInteraction&quot;;<br />		public static const DEACTIVATE_INTERACTION:String = &quot;onDeActivateInteraction&quot;;<br />		<br />		public function Cursor(tg:TextField) {<br />			<br />			target = tg;<br />						<br />			addEventListener(Event.ADDED_TO_STAGE, init);<br />			addEventListener(Event.REMOVED_FROM_STAGE, dispose);<br />						<br />		}<br />		<br />		private function createCursor():void{<br />			<br />			if(!timer){<br />			<br />				timer = new Timer(cursorDelay);<br />			<br />				timer.addEventListener(TimerEvent.TIMER, onBlink);<br />				timer.start();<br />				<br />			}<br />			<br />		}<br />		<br />		public function destroyCursor():void{<br />			<br />			if(timer){<br />				<br />				timer.stop();<br />				timer.removeEventListener(TimerEvent.TIMER, onBlink);<br />				<br />				timer = null;<br />				<br />				graphics.clear();<br />				<br />			}<br />			<br />		}<br />		<br />		protected function onBlink(e:TimerEvent):void{<br />			<br />			drawable = !drawable;<br />			var g:Graphics = graphics;<br />			<br />			if(drawable){<br />								<br />				g.lineStyle(1, 0x000000, 1);<br />				g.moveTo(cursorX, target.y + paddingTop);<br />				g.lineTo(cursorX, target.y + target.height - paddingBottom);<br />				<br />			}else{<br />				<br />				g.clear();<br />				<br />			}<br />			<br />		}<br />		<br />		protected function handleInput(e:TextEvent):void{<br />			<br />						<br />			<br />		}<br />		<br />		protected function onFocusIn(e:FocusEvent):void{<br />			<br />			dispatchEvent(new Event(ACTIVATE_INTERACTION));<br />						<br />			createCursor();<br />			<br />			stage.focus = parent;			<br />									<br />		}<br />		<br />		protected function onFocusOut(e:FocusEvent):void{<br />			<br />			dispatchEvent(new Event(DEACTIVATE_INTERACTION));<br />			<br />			<br />			<br />		}<br />		<br />		private function init(e:Event):void{<br />			<br />			target.addEventListener(TextEvent.TEXT_INPUT, handleInput);<br />			<br />			target.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);<br />			target.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);<br />			<br />		}<br />		<br />		private function dispose(e:Event):void{<br />			<br />			target.removeEventListener(TextEvent.TEXT_INPUT, handleInput);<br />			<br />			target.removeEventListener(FocusEvent.FOCUS_IN, onFocusIn);<br />			target.removeEventListener(FocusEvent.FOCUS_OUT, onFocusOut);<br />			<br />		}<br />		<br />		public function set cursorDelay(value:int):void{<br />			<br />			_cursorDelay = value;<br />			<br />		}<br />		<br />		public function get cursorDelay():int{<br />			<br />			return _cursorDelay ? _cursorDelay : CURSOR_DELAY;<br />			<br />		}<br />		<br />		public function set paddingTop(value:int):void{<br />			<br />			_paddingTop = value;<br />			<br />		}<br />		<br />		public function get paddingTop():int{<br />			<br />			return _paddingTop ? _paddingTop : PADDING_TOP;<br />			<br />		}<br />		<br />		public function set paddingBottom(value:int):void{<br />			<br />			_paddingBottom = value;<br />			<br />		}<br />		<br />		public function get paddingBottom():int{<br />			<br />			return _paddingBottom ? _paddingBottom : PADDING_BOTTOM;<br />			<br />		}<br />		<br />		public function set paddingLeft(value:int):void{<br />			<br />			_paddingLeft = value;<br />			<br />		}<br />		<br />		public function get paddingLeft():int{<br />			<br />			return _paddingLeft ? _paddingLeft : PADDING_LEFT;<br />			<br />		}<br />		<br />		public function get currentTarget():TextField{<br />			<br />			return target;<br />			<br />		}<br />		<br />		private function get cursorX():int{<br />			<br />			return target.x + paddingLeft + target.textWidth;<br />			<br />		}<br />		<br />	}<br />	<br />}<br /></pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Sun, 05 Jun 2011 15:07:45 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/100</guid>
   </item><item>
      <title><![CDATA[Spark DataGroup items management]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/99</link>
      <description><![CDATA[If you want to listen for events from events created by a DataGroup, you can use the group&#39;s events renderAdd and renderRemove to be notified when items are being created or recycled.<br />From those event handlers you can setup your items or store them somewhere, like a Dictionary, to be easily accessed later.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;fx:Script&gt;<br />		&lt;![CDATA[<br />		<br />			import mx.core.IVisualElement;<br />			<br />			import spark.events.RendererExistenceEvent;<br />			<br />			private var map:Dictionary = new Dictionary(true);<br />			<br />			private function onRendererAdd(event:RendererExistenceEvent):void {<br />				<br />				var index:int = event.index;<br />				var renderer:IVisualElement = event.renderer;<br />				<br />				if (!renderer) return;<br />				<br />				map[index] = renderer;<br />				MyRenderer(renderer).addEventListener(MyCustomEvent.ACTION, onItemRendererAction);<br />			}<br /><br />			private function onRendererRemove(event:RendererExistenceEvent):void {<br />				<br />				var index:int = event.index;<br />				var renderer:IVisualElement = event.renderer;<br />				<br />				if (!renderer) return;<br />				<br />				delete map[index];<br />				MyRenderer(renderer).removeEventListener(MyCustomEvent.ACTION, onItemRendererAction);<br />			}<br />	]]&gt;<br />&lt;/fx:Script&gt;<br />&lt;s:DataGroup id=&quot;buttons&quot; top=&quot;300&quot; height=&quot;100%&quot;<br />			 rendererAdd=&quot;onRendererAdd(event)&quot;<br />			 rendererRemove=&quot;onRendererRemove(event)&quot;<br />			 itemRenderer=&quot;MyRenderer&quot;&gt;<br />	&lt;s:layout&gt;<br />		&lt;s:VerticalLayout gap=&quot;12&quot; horizontalAlign=&quot;left&quot; paddingLeft=&quot;20&quot;/&gt;<br />	&lt;/s:layout&gt;<br />&lt;/s:DataGroup&gt;</pre></div><br /><br />]]></description>
      <author>cyberpunk</author>
      <pubDate>Wed, 18 May 2011 09:35:54 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/99</guid>
   </item><item>
      <title><![CDATA[Automatically set focus to flash movie]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/98</link>
      <description><![CDATA[Usually flash movies needs to be clicked to make them gain focus before they can be interacted via keyboard. If you want to gain automagically when your movie starts, you can do it via javascript. It&#39;s just a matter of calling the focus() method on the right html element at the right time.<br />You can find here an example made using SWFObject. The setFocusOnFlash() is used as a callback by the embedSWF() method. An event object is sent along the function callback, holding the operation status, the html element id and a direct reference to the html element.<br />Notes:<br /> <br /><ul style="list-style-type:decimal"><li>make sure to use wmode opaque or transparent, otherwise this trick won&#39;t work on chrome and safari</li><br /><li>make sure to set the tabIndex property on the html element you&#39;re going to focus, otherwise it won&#39;t be in the &quot;tabbing list&quot; and some browsers (chrome and safari) will ignore the focus() call</li><br /><li>on firefox (both 3.6 and 4.0) the callback is fired a bit too early, hence the need for a small timer before the actual call</li><br /></ul><br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt;<br />	function setFocusOnFlash(e) { <br />		setTimeout(function() {<br />			if (e.success) {<br />				e.ref.tabIndex = 0;<br />				e.ref.focus(); <br />			}<br />		},125);<br />	}<br />	var swfVersionStr = &quot;10.0.0&quot;;<br />	var xiSwfUrlStr = &quot;playerProductInstall.swf&quot;;<br />	var flashvars = {};<br />	var params = {};<br />	params.quality = &quot;high&quot;;<br />	params.bgcolor = &quot;#000000&quot;;<br />	params.allowscriptaccess = &quot;sameDomain&quot;;<br />	params.allowfullscreen = &quot;true&quot;;<br />	params.wmode = &quot;opaque&quot;;<br />	var attributes = {};<br />	attributes.id = &quot;MyMovie&quot;;<br />	attributes.name = &quot;MyMovie&quot;;<br />	attributes.align = &quot;middle&quot;;<br />	swfobject.embedSWF(<br />		&quot;MyMovie.swf&quot;, &quot;flashContent&quot;, <br />		&quot;300&quot;, &quot;200&quot;, <br />		swfVersionStr, xiSwfUrlStr, <br />		flashvars, params, attributes, setFocusOnFlash);<br />	swfobject.createCSS(&quot;#flashContent&quot;, &quot;display:block;text-align:left;&quot;);<br />&lt;/script&gt;</pre></div><br /><br />]]></description>
      <author>cyberpunk</author>
      <pubDate>Tue, 10 May 2011 09:27:27 +0200</pubDate>
      <category>Uncategorized</category>
      <guid>http://snippet.gnstudio.com/viewtopic/98</guid>
   </item><item>
      <title><![CDATA[Performance boost for Google Maps API Street View iframe overlay for IE]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/97</link>
      <description><![CDATA[If you have your Google Maps JavaScript API overlayed over a Flash content in iframe you may experience really slow performance in IE. Solution is to set the wmode to &quot;opaque&quot; for IE. Note that for other browsers this might cause some issues. Our experience shown that it&#39;s best to set wmode to &quot;opaque&quot; exclusively for IE and for other browsers set it to &quot;window&quot;, which is default wmode.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">/* Set wmode to &quot;opaque&quot; in your HTML wrapper for Object and Embed tags. */</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Tue, 08 Mar 2011 09:26:07 +0100</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/97</guid>
   </item><item>
      <title><![CDATA[Apply gradient to dynamic textfields]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/96</link>
      <description><![CDATA[Using blend modes you can show your dynamic textfields with a nice gradient instead of the usual boring color.<br />With this method you can make a text transparent without embedding the font.<br />ps: you can also try with input text field by setting the appropriate value to the type property and changing selectable to true<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">import flash.text.TextField;<br />import flash.text.TextFieldAutoSize;<br />import flash.text.TextFieldType;<br />import flash.display.Shape;<br />import flash.display.GradientType;<br />import flash.display.SpreadMethod;<br />import flash.display.InterpolationMethod;<br />import flash.display.BlendMode;<br />import flash.text.TextFormat;<br />import flash.text.TextFormatAlign;<br />import flash.geom.Matrix;<br /><br />/*<br /> * Dynamically created textfields seems to mantain a constant 2px<br /> * border around the text, no matter the font size. If we don&#39;t<br /> * handle it in the gradient size and position, we&#39;ll see a gradient<br /> * border around out text<br /> */<br />const TEXTFIELD_BORDER:int = 2;<br /><br />/*<br /> * Let&#39;s build the container of out text<br /> * and set it in blend mode LAYER.<br /> */<br />var container:Sprite = new Sprite();<br />container.blendMode = BlendMode.LAYER;<br />addChild(container);<br /><br />/*<br /> * Now we add out textfield to the container<br /> * and we set its blend mode to ALPHA<br /> */<br />var field:TextField = new TextField();<br />field.blendMode = BlendMode.ALPHA;<br />field.defaultTextFormat = new TextFormat(&quot;_sans&quot;, 14, 0xFF0000, true, false, false, null, null, TextFormatAlign.LEFT, 0, 0, 0, 0);<br />field.text = &quot;Lorem ipsum dolor sit amet&quot;;<br />field.autoSize = TextFieldAutoSize.LEFT;<br />field.wordWrap = false;<br />field.multiline = false;<br />field.selectable = false;<br />container.addChild(field);<br /><br />/*<br /> * Finally we can create a shape with a gradient box inside<br /> * we&#39;ll use the sizes from the field to define its dimensions<br /> * and make sure to put it BEHIND the text field, inside the container<br /> */<br />var colors:Array = [0xFF00000, 0xFF00FF, 0xFFFFFF, 0xFFFF00];<br />var alphas:Array = [1, 1, 0, 1];<br />var ratios:Array = [0x00, 0x43, 0x7F, 0xFF];<br />var matrix:Matrix = new Matrix();<br />matrix.createGradientBox(field.width-TEXTFIELD_BORDER*2, field.height-TEXTFIELD_BORDER*2, 0, TEXTFIELD_BORDER, TEXTFIELD_BORDER);<br /><br />var gradient:Shape = new Shape();<br />gradient.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);<br />gradient.graphics.drawRect(TEXTFIELD_BORDER, TEXTFIELD_BORDER, field.width-TEXTFIELD_BORDER*2, field.height-TEXTFIELD_BORDER*2);<br />gradient.graphics.endFill();<br />container.addChildAt(gradient, 0);<br /></pre></div><br /><br />]]></description>
      <author>cyberpunk</author>
      <pubDate>Wed, 05 Jan 2011 09:03:17 +0100</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/96</guid>
   </item><item>
      <title><![CDATA[Bitmap Capture of Resized 9-Slice Scale Sprite]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/95</link>
      <description><![CDATA[If you draw a resized 9-slice scale Sprite to a BitmapData, the result will be non-resized original bitmap data of your Sprite. <br />To take a bitmap capture from a resized 9-slice scale Sprite, add it to a Sprite container and draw the Sprite container to a BitmapData. <br />Note that non of the Sprites need to be added to the display list to accomplish this.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">[Embed(source=&quot;/../assets/nine_slice_frame.png&quot;, scaleGridTop=&quot;100&quot;, scaleGridBottom=&quot;1100&quot;, scaleGridLeft=&quot;100&quot;, scaleGridRight=&quot;1500&quot;)]<br />private const NINE_SLICE_FRAME:Class;<br /><br />var nineSliceFrame:Sprite = new NINE_SLICE_FRAME() as Sprite;<br />nineSliceFrame.width = 400;<br />nineSliceFrame.height = 400;<br /><br />// Use dummy Sprite instance to take a bitmap capture of resized Sprite with 9 slice scale applied.<br />var dummySprite:Sprite = new Sprite();<br />dummySprite.width = 400;<br />dummySprite.height = 400;<br />dummySprite.addChild(nineSliceFrame);<br /><br />var nineSliceFrameBitmapData:BitmapData = new BitmapData(400, 400, true, 0x00000000);<br />nineSliceFrameBitmapData.draw(dummySprite);<br /><br />var nineSliceFrameBitmap:Bitmap = new Bitmap(nineSliceFrameBitmapData);<br />addChild(nineSliceFrameBitmap);</pre></div><br /><br />]]></description>
      <author>ivan.varga</author>
      <pubDate>Fri, 22 Oct 2010 10:14:11 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/95</guid>
   </item><item>
      <title><![CDATA[Duplicate SWF or raster content of an Image component]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/94</link>
      <description><![CDATA[Using the BitmapData class is quite easy and fast copy or manipulate an external image loaded into a Flex application, it&#39;s quite interesting the difference between the data type of the content property of an Image component because it changes if a bitmap or a SWF has been loaded: <br /><ul><li>the first one is a Bitmap </li><li>the second on is a MovieClipLoaderAsset </li></ul><br /><br />In order to let you copy the content also with a SWF file loaded into the Image component you can use a Loader and the loadBytes() method.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;mx:Application xmlns:mx=&quot;<a href="http://www.adobe.com/2006/mxml&quot;" target="_blank"><a href="http://www.adobe.com/2006/mxml&quot;" target="_blank">http://www.adobe.com/2006/mxml&quot;</a></a><br />        layout=&quot;vertical&quot;<br />        verticalAlign=&quot;middle&quot;<br />        backgroundColor=&quot;white&quot;&gt;<br /> <br />    &lt;mx:Script&gt;<br />        &lt;![CDATA[<br />        	import mx.core.MovieClipLoaderAsset;<br />        	import mx.core.BitmapAsset;<br />            import mx.collections.ArrayCollection;<br />            <br />            [Embed(source=&quot;placeholder.swf&quot;)]<br />			private const ARTWORK_PLACE_HOLDER_SWF:Class;<br />			<br />			[Embed(source=&quot;placeholder.png&quot;)]<br />			private const ARTWORK_PLACE_HOLDER_PNG:Class;<br /> <br />            [Bindable]<br />            private var collection:ArrayCollection = new ArrayCollection();<br /> 			<br /> 			private function handleImage(e:Event):void{<br /> 				<br /> 				if(e.currentTarget.selectedValue == &quot;PNG&quot;){<br /> 					<br /> 					img.source = ARTWORK_PLACE_HOLDER_PNG;<br /> 					<br /> 				}else{<br /> 					<br /> 					img.source = ARTWORK_PLACE_HOLDER_SWF;<br /> 					<br /> 				}<br /> 				<br /> 			}<br /> 			<br />            private function dumpImage(source:Image):void {<br />            	<br />            	var asset:* = source.content;<br />            	var data:BitmapData;<br />            	var bitmap:Bitmap;<br />            	<br />            	try{<br />            		<br />            		data = Bitmap(source.content).bitmapData;<br />                	bitmap = new Bitmap(data);<br />                	<br />                	collection.addItem({image:bitmap, label:&quot;item #&quot; + (collection.length + 1)});<br />            		<br />            	}catch(error:Error){<br />            		<br />            		var loader:Loader = new Loader();<br />            		<br />            		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBitmapData); <br />            		           		<br />            		var swf:MovieClipLoaderAsset = asset as MovieClipLoaderAsset;            		<br />            		loader.loadBytes(swf.movieClipData);<br />            		<br />            	}<br />            	<br />            }<br />            <br />            private function onBitmapData(e:Event):void{<br />            			<br />            	e.target.removeEventListener(e.type, arguments.callee);<br />            			<br />            	var content: MovieClip = MovieClip((e.currentTarget as LoaderInfo).content)<br />            	var data:BitmapData = new BitmapData(content.width, content.height);<br />            	data.draw(content, null, null, null, null, true)<br />            	var bitmap:Bitmap = new Bitmap(data)<br />            			<br />            	collection.addItem({image:bitmap, label:&quot;item #&quot; + (collection.length + 1)});<br />            			<br />            }<br />            <br />        ]]&gt;<br />    &lt;/mx:Script&gt;<br /> <br />    &lt;mx:HBox&gt;<br />        &lt;mx:Panel title=&quot;Source image&quot;&gt;<br />            &lt;mx:HBox verticalAlign=&quot;middle&quot; horizontalAlign=&quot;center&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;<br />                &lt;mx:Image id=&quot;img&quot; source=&quot;{ARTWORK_PLACE_HOLDER_SWF}&quot; /&gt;<br />            &lt;/mx:HBox&gt;<br />            <br />            &lt;mx:RadioButtonGroup id=&quot;imageSelector&quot; change=&quot;handleImage(event)&quot; /&gt;<br />            &lt;mx:RadioButton label=&quot;SWF&quot; selected=&quot;true&quot; group=&quot;{imageSelector}&quot; /&gt;<br />            &lt;mx:RadioButton label=&quot;PNG&quot; group=&quot;{imageSelector}&quot; /&gt;<br /> <br />            &lt;mx:ControlBar&gt;<br />                &lt;mx:Button label=&quot;Copy image&quot; click=&quot;dumpImage(img)&quot; /&gt;<br />            &lt;/mx:ControlBar&gt;<br />        &lt;/mx:Panel&gt;<br /> <br />        &lt;mx:TileList id=&quot;tileList&quot; dataProvider=&quot;{collection}&quot; width=&quot;450&quot; height=&quot;500&quot; columnCount=&quot;4&quot; verticalScrollPolicy=&quot;on&quot;&gt;<br />            &lt;mx:itemRenderer&gt;<br />                &lt;mx:Component&gt;<br />                    &lt;mx:VBox&gt;<br />                        &lt;mx:Image source=&quot;{data.image}&quot; /&gt;<br />                        &lt;mx:Label text=&quot;{data.label}&quot; /&gt;<br />                    &lt;/mx:VBox&gt;<br />                &lt;/mx:Component&gt;<br />            &lt;/mx:itemRenderer&gt;<br />        &lt;/mx:TileList&gt;<br />    &lt;/mx:HBox&gt;<br /> <br />&lt;/mx:Application&gt;</pre></div><br /><br />]]></description>
      <author>giorgionatili</author>
      <pubDate>Mon, 04 Oct 2010 06:02:28 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/94</guid>
   </item><item>
      <title><![CDATA[Call AMF RPC methods from Flash]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/93</link>
      <description><![CDATA[If you would like consume some services through RemoteObject from Flash in the same fashion you do in Flex, you will need to follow these step: <br /><ul style="list-style-type:decimal"><li>Add the <span style="font-weight:bold">rpc.swc</span> and <span style="font-weight:bold">framework.swc</span> from your <span style="text-decoration:underline">{FLEX_HOME}/frameworks/libs</span> to you ptoject or .fla classpath </li><br /><li>Optional: If you are compiling an Actionscript Project in Flash Builder you&#39;ll also need the resource bundles for those swcs. So add also the rpc_<span style="font-weight:bold">rb.swc</span> and <span style="font-weight:bold">framework_rb.swc</span> from <span style="text-decoration:underline">{FLEX_HOME}/frameworks/locale</span> to your classpath. </li><br /><li>Look at the code below, the <span style="font-style:italic">initializeRPC </span>and <span style="font-style:italic">registerClasses </span>methods are what you need to make things work. </li><br /></ul><br />You are now ready to call remote methods via amf like this simple example. <br /><span style="font-weight:bold">Notes</span>: <br />You will bring nearly 100kb of footprint to your swf due to dependencies from the flex framework. You reduce that footprint by registering a custom collection class instead of the ArrayCollection. The only requirement is that your collection class implements the <span style="font-style:italic">IExternalizable</span> interface.<br />]]><![CDATA[<div class="divcode"><pre class="prettyprint">import mx.collections.ArrayCollection;<br />import mx.core.mx_internal;<br />import mx.logging.Log;<br />import mx.logging.targets.TraceTarget;<br />import mx.messaging.ChannelSet;<br />import mx.messaging.channels.AMFChannel;<br />import mx.messaging.config.ConfigMap;<br />import mx.messaging.config.LoaderConfig;<br />import mx.messaging.messages.AcknowledgeMessage;<br />import mx.messaging.messages.AcknowledgeMessageExt;<br />import mx.messaging.messages.CommandMessage;<br />import mx.messaging.messages.CommandMessageExt;<br />import mx.messaging.messages.ErrorMessage;<br />import mx.messaging.messages.RemotingMessage;<br />import mx.rpc.AbstractOperation;<br />import mx.rpc.events.FaultEvent;<br />import mx.rpc.events.ResultEvent;<br />import mx.rpc.remoting.RemoteObject;<br />import mx.utils.ObjectProxy;<br /><br />use namespace mx_internal;<br /><br />const ID:String = &quot;my-amf&quot;;<br />const ENDPOINT:String = &quot;<a href="http://your.domain/amf/gateway&quot;;" target="_blank"><a href="http://your.domain/amf/gateway&quot;;" target="_blank">http://your.domain/amf/gateway&quot;;</a></a><br />const DEFAULT_SOURCE:String = &quot;your.service&quot;;<br />const DEFAULT_SOURCE:String = &quot;your.service&quot;;<br /><br />var remoteObject:RemoteObject;<br /><br />/**<br /> * This initializes the rpc library.<br /> * After this you should see the requests going through.<br /> * Note: LoaderConfig won&#39;t show up in the code hints, so you have to write down the import manually.<br /> */<br />function initializeRPC():void {<br />	<br />	LoaderConfig.mx_internal::_url = loaderInfo.url; <br />	LoaderConfig.mx_internal::_parameters = loaderInfo.parameters;<br />}<br /><br />/**<br /> * We register a bunch of class aliases that are needed by the rpc methods.<br /> * The list *may be* incomplete, if you get some TypeCoertion error try registering that class.<br /> */<br />function registerClasses():void {<br />	<br />	registerClassAlias(&quot;flex.messaging.messages.ErrorMessage&quot;, ErrorMessage);<br />	registerClassAlias(&quot;flex.messaging.messages.CommandMessage&quot;, CommandMessage);<br />	registerClassAlias(&quot;flex.messaging.messages.RemotingMessage&quot;, RemotingMessage);<br />	registerClassAlias(&quot;flex.messaging.messages.AcknowledgeMessage&quot;, AcknowledgeMessage);<br />	registerClassAlias(&quot;DSC&quot;, CommandMessageExt);<br />	registerClassAlias(&quot;DSK&quot;, AcknowledgeMessageExt);<br />	registerClassAlias(&quot;flex.messaging.config.ConfigMap&quot;, ConfigMap);<br />	registerClassAlias(&quot;flex.messaging.io.ObjectProxy&quot;, ObjectProxy);<br />	registerClassAlias(&quot;flex.messaging.io.ArrayCollection&quot;, ArrayCollection);<br />}<br /><br />/**<br /> * Prepare the RemoteObject, creating the appropriate AMF channel<br /> * and setting up the default event handlers.<br /> */<br />function prepareDefaultRemoteObject():void {<br />	<br />	var channel:AMFChannel = new AMFChannel(ID, ENDPOINT);<br />	<br />	var channelSet:ChannelSet = new ChannelSet();<br />	channelSet.addChannel(channel);<br /><br />	remoteObject = new RemoteObject();<br />	remoteObject.source = DEFAULT_SOURCE;<br />	remoteObject.destination = DEFAULT_DESTINATION;<br />	remoteObject.channelSet = channelSet;<br />	remoteObject.addEventListener(FaultEvent.FAULT, onDefaultServiceFault);<br />	remoteObject.addEventListener(ResultEvent.RESULT, onDefaultServiceResult);<br />}<br /><br />/**<br /> * Create and execute the remote method.<br /> */<br />function makeAnonymousRemoteCall():void {<br />	<br />	var operation:AbstractOperation = ro.getOperation(&quot;getProduct&quot;);<br />	operation.send();<br />}<br /><br /><br />/**<br /> * Handles faulty replies from the remote methods.<br /> */<br />function onDefaultServiceFault(event:FaultEvent):void {<br />	<br />	trace(event.fault.faultDetail);<br />}<br /><br />/**<br /> * Handles successful replies from the remote methods.<br /> */<br />function onDefaultServiceResult(event:ResultEvent):void {<br />	<br />	trace(event.result.toString());<br />}<br /><br />// All RPC classes use the Flex logging API so enabling it in the Flash project could be helpful.<br />Log.addTarget(new TraceTarget());<br /><br />initializeRPC();<br />registerClasses();<br /><br />prepareDefaultRemoteObject();<br />makeAnonymousRemoteCall();</pre></div><br /><br />]]></description>
      <author>cyberpunk</author>
      <pubDate>Thu, 02 Sep 2010 11:15:23 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/93</guid>
   </item>
  </channel>
</rss>
