<?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>Thu, 09 Feb 2012 21:14:58 +0100</pubDate>
    <docs>SnippetRepoBrowser/index</docs>
    <generator>SnippetRepoBrowser Feed Generator</generator>
    <item>
      <title><![CDATA[Removing trailing nulls in ActionScript]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/91</link>
      <description><![CDATA[When reading a byte array in ActionScript (like in C) the null value is read as a string termination. When you try use the <span style="font-size: 8pt">readUTFBytes method over a ByteArray if the data contain a null value (0x00) the ActionScript interpreter stop the reading and retunr you a truncated string, in order to avoid this issue you can simply parse the data before using the method readUTFBytes.</span> <br /><span style="font-size: 8pt">Following a small sample where the variable bytedata represents the raw data recovered from your read operation.</span> <br /><span style="font-size: 8pt"><br /></span><br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">var ba:ByteArray = new ByteArray();<br />			<br />for(var i:int = 0; i &lt; bytedata.length; i++){<br />				<br />	if(bytedata<span style="font-style:italic"> != 0x00){<br />				<br />	ba.writeByte(bytedata<span style="font-style:italic">)<br />					<br />}else{<br />					<br />	ba.writeByte(0x0A)<br />					<br />}<br />				<br />}<br />			<br />ba.position = 0;<br />			<br />var data:String = ba.readUTFBytes( ba.length );</pre></div><br /><br />]]></description>
      <author>GiorgioNatili</author>
      <pubDate>Mon, 17 May 2010 08:50:19 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/91</guid>
   </item><item>
      <title><![CDATA[Retrive image type, width and height of png, jpg, gif using nabiro]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/44</link>
      <description><![CDATA[With these few lines of code you can easly retrive type and size of an image<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">var imageInfo:ImageInfo = new ImageInfo(myByteArray);<br />imageInfo.extractType();<br />imageInfo.extractSize();<br />trace(imageInfo.type.toString());<br />trace(imageInfo.width.toString());<br />trace(imageInfo.height.toString());</pre></div><br /><br />]]></description>
      <author>fedele.marotti</author>
      <pubDate>Wed, 28 Oct 2009 18:44:28 +0100</pubDate>
      <category>Flex 3.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/44</guid>
   </item><item>
      <title><![CDATA[Get the PNG image sizes from IHDR]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/41</link>
      <description><![CDATA[Imagine to load a PNG file through an URLStream intance named stream, on the Event.COMPLETE event this script extract the IHDR information releated to the width and height of the image, more info about IHDR <a href="http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html" target="_blank">here</a>.<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">var _width:Number = 0;<br />var _height:Number = 0;<br /><br />var ba:ByteArray = new ByteArray();<br />stream.readBytes(fileData, 0, stream.bytesAvailable);<br /><br />ba.position = 16<br />_width += this.readUnsignedByte() &lt;&lt; 24;<br />			<br />ba.position = 17<br />_width += this.readUnsignedByte() &lt;&lt; 16;<br />			<br />ba.position = 18<br />_width += this.readUnsignedByte() &lt;&lt; 8;<br />			<br />ba.position = 19<br />_width += this.readUnsignedByte();<br />			<br />ba.position = 20<br />_height += this.readUnsignedByte() &lt;&lt; 24;<br />			<br />ba.position = 21<br />_height += this.readUnsignedByte() &lt;&lt; 16;<br />			<br />ba.position = 22<br />_height += this.readUnsignedByte() &lt;&lt; 8;<br />			<br />ba.position = 23<br />_height += this.readUnsignedByte();<br />			<br />ba.position = 0;<br />			<br />return new Rectangle(0, 0, _width, _height);</pre></div><br /><br />]]></description>
      <author>Giorgio Natili</author>
      <pubDate>Mon, 26 Oct 2009 18:48:39 +0100</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/41</guid>
   </item><item>
      <title><![CDATA[load binary data via xml message]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/36</link>
      <description><![CDATA[say you are dealing with a backend via xml messages, for some instance you need to load binary data. Flash player can load images, sounds, videos and other movies, but these are operations that go separated from the data exchange context. You can join xml messages and binary content using base64 classes.<br />The advantages are:<br />- concurrent messages with content<br />- you can build up your own distributed objects<br />- more opportunities to hardening your movies, e.g content protection, cryptography, progressive and conditioned loading<br />and the cons:<br />- messages are greater, almost 20/30%<br />- if you plan to getting touch with real data, some ByteArray skills needed<br />- some people prefers amf, faster and data driven<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">// these two code files show how to load a sample image using xml message generated from php<br /><br /><br />// as3, TryB64php.as<br /><br />/**<br /> * @author jaco<br /> *<br /> * created on 16/10/2009 16.56.51<br /> */<br />package {<br /><br />	import flash.display.*;<br />	import flash.events.*;<br />	import flash.text.*;<br />	import flash.net.*;<br />	import flash.geom.*;<br />	import flash.utils.*;<br /><br />	// as3, got from <a href="http://dynamicflash.com/goodies/base64/" target="_blank"><a href="http://dynamicflash.com/goodies/base64/" target="_blank">http://dynamicflash.com/goodies/base64/</a></a><br />	// if you&#39;re in flex/air, there are mx.utils.Base64* classes<br />	import com.dynamicflash.util.Base64;<br /><br /><br />	/**<br />	 *<br />	 */<br />	public class TryB64php extends MovieClip {<br /><br />		private static const PHP_URL:String = &quot;get_xml_b64response.php&quot;;<br /><br />		private var ul:URLLoader;<br />		private var ld:Loader;<br /><br />		/**<br />		 * the constructor<br />		 */<br />		function TryB64php(){<br /><br />			var ur:URLRequest = new URLRequest(PHP_URL);<br />			ld = new Loader();<br />			ul = new URLLoader();<br /><br />			addChild(ld);<br /><br />			ul.addEventListener(Event.COMPLETE, onULComplete);<br />			ul.load(ur);<br />		}<br /><br />		private function onULComplete(evt:Event):void {<br /><br />			var xml:XML = XML(ul.data);<br /><br />			var ba:ByteArray = Base64.decodeToByteArray(xml);<br />			ld.loadBytes(ba);<br />		}<br />	}<br />}<br /><br /><br />// php, get_xml_b64response.php<br /><br />&lt;?php<br />/*<br /> * Created on 16/ott/2009<br /> *<br /> * jaco_at_pixeldump<br /> */<br /><br />define(&quot;XML_HEADER&quot;, &quot;&lt;?xml version=\&quot;1.0\&quot;?&gt;&quot;);<br />define(&quot;NL&quot;, &quot;\r\n&quot;);<br /><br />define(&quot;RESPONSE_INFO&quot;, &quot;info&quot;);<br />define(&quot;RESPONSE_VALUE_BASE64&quot;, &quot;base64&quot;);<br /><br />/**<br /> * read resource from path<br /> * @param file name<br /> * @param directory<br /> *<br /> * @return xml instance with base64 encoded data<br /> */<br />function get_resource($resFN, $resDir = &quot;./&quot;) {<br /><br />	$filePath = $resDir .$resFN;<br />	$fRes = file_get_contents($filePath, FILE_BINARY);<br /><br />	return create_simpleXmlMessage(base64_encode($fRes), RESPONSE_VALUE_BASE64);<br />}<br /><br />/**<br /> * create an xml message<br /> * @param message string<br /> * @param response type<br /> *<br /> * @return formatted xml instance with given data<br /> */<br />function create_simpleXmlMessage($str, $type = RESPONSE_INFO) {<br /><br />	$xmlStr = XML_HEADER .NL;<br />	$xmlStr .= create_xmlNode(&quot;response&quot;, $str, array(&quot;type&quot; =&gt; $type, &quot;timeStamp&quot; =&gt; mktime()));<br /><br />	return $xmlStr;<br />}<br /><br />/**<br /> * create a simple xml node with some data population<br /> * @param node name<br /> * @param node content<br /> * @param attributes<br /> * @param CDATA flag<br /> *<br /> * @return formatted xml node with given data<br /> */<br />function create_xmlNode($nodeName, $nodeContent = &quot;&quot;, $attrs = array(), $cDataFlag = true){<br /><br />	$xmlStr = &quot;&lt;&quot; .$nodeName .&quot; &quot;;<br />	$sfx1 = $cDataFlag ? &quot;&lt;![CDATA[&quot; : &quot;&quot;;<br />	$sfx2 = $cDataFlag ? &quot;]]&gt;&quot; : &quot;&quot;;<br /><br />	if(count($attrs))<br />		foreach($attrs as $k =&gt; $v) $xmlStr .= $k .&quot;=\&quot;&quot; .$v .&quot;\&quot; &quot; ;<br /><br />	if(strlen($nodeContent)){<br />		$xmlStr .= &quot;&gt;&quot; .$sfx1 .$nodeContent .$sfx2;<br />		$xmlStr .= &quot;&lt;/&quot; .$nodeName .&quot;&gt;&quot;;<br />	}<br />	else $xmlStr .= &quot;/&gt;&quot;;<br /><br />	return $xmlStr;<br />}<br /><br />// the app<br /><br />header(&quot;Content-type: text/xml&quot;);<br />echo get_resource(&quot;sample_avatar.png&quot;); // sample image<br />?&gt;<br /><br /></pre></div><br /><br />]]></description>
      <author>jaco</author>
      <pubDate>Fri, 16 Oct 2009 16:56:34 +0200</pubDate>
      <category>ActionScript</category>
      <guid>http://snippet.gnstudio.com/viewtopic/36</guid>
   </item>
  </channel>
</rss>
