<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<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/"
	>

<channel>
	<title>The kaustic lab __</title>
	<link>http://compiler.kaustic.net/lab</link>
	<description>Code for the Flash Platform</description>
	<pubDate>Tue, 06 Dec 2011 14:19:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>FlexMojos 4.0-RC2 + Flex SDK 4.6.0.23201</title>
		<link>http://compiler.kaustic.net/lab/?p=58</link>
		<comments>http://compiler.kaustic.net/lab/?p=58#comments</comments>
		<pubDate>Tue, 06 Dec 2011 11:40:28 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

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

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

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=58</guid>
		<description><![CDATA[Update 1: fixed the AIR 3 swc&#8217;s and added the descriptors here http://cortizone.googlecode.com/hg/maven/
Disclaimer 1: this is a temporary article i wish to remove in the future when it becomes obsolete*
Disclaimer 2: use at your own risk, YMMV
*hopefully soon
For the moment there is no Flex SDK 4.6 love yet when yer using FlexMojos.
This is a quick [...]]]></description>
			<content:encoded><![CDATA[<p>Update 1: fixed the AIR 3 swc&#8217;s and added the descriptors here <a href="http://cortizone.googlecode.com/hg/maven/">http://cortizone.googlecode.com/hg/maven/</a></p>
<p>Disclaimer 1: this is a temporary article i wish to remove in the future when it becomes obsolete*</p>
<p>Disclaimer 2: use at your own risk, YMMV</p>
<p>*hopefully soon</p>
<p>For the moment there is no Flex SDK 4.6 love yet when yer using FlexMojos.<br />
This is a quick recap of how i seem to have it working now (i think&#8230;) using Conrad&#8217;s flex_sdk_maven_install (<a href="https://github.com/piercer/flex_sdk_maven_install">https://github.com/piercer/flex_sdk_maven_install</a>).</p>
<p>I took the 4.6 SDK that comes with the new Flash Builder and installed it using his guidelines in a clean maven repo. You can find that stuff here: <a href="http://cortizone.googlecode.com/hg/maven-repositories/">http://cortizone.googlecode.com/hg/maven-repositories/</a></p>
<p>If you clone this repo (Mercurial required) and put that stuff in your Maven .m2 folder it seems to actually work&#8230; The suspicious part is that FlexMojos keeps dependencies to 4.5.1 compiler (hardcoded in the plugin? nice&#8230;) Again, merely adding <a href="http://cortizone.googlecode.com/hg/maven-repositories/">http://cortizone.googlecode.com/hg/maven-repositories/</a> in your pom as a repository location doesn&#8217;t work, you should do it manually.</p>
<p>This is the pom i used to test and i get a BUILD SUCCESS. Quadruple rainbow in my face&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
</pre></td><td class="code"><pre>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
		 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		 xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&nbsp;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;net.kaustic.flexmojos.test&lt;/groupId&gt;
	&lt;artifactId&gt;flexmojos-test-swc&lt;/artifactId&gt;
	&lt;packaging&gt;swc&lt;/packaging&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&nbsp;
	&lt;developers&gt;
		&lt;developer&gt;
			&lt;id&gt;vancoja&lt;/id&gt;
			&lt;name&gt;Jan Van Coppenolle&lt;/name&gt;
		&lt;/developer&gt;
	&lt;/developers&gt;
&nbsp;
	&lt;properties&gt;
		&lt;flexmojos.version&gt;4.0-RC2&lt;/flexmojos.version&gt;
		&lt;flex.sdk.version&gt;4.6.0.23201&lt;/flex.sdk.version&gt;
		&lt;apparat.version&gt;1.0-RC9&lt;/apparat.version&gt;
		&lt;flexunit.version&gt;4.1.0-beta3&lt;/flexunit.version&gt;
		&lt;flashplayer.version.swf&gt;13&lt;/flashplayer.version.swf&gt;
		&lt;flashplayer.version.major&gt;11&lt;/flashplayer.version.major&gt;
		&lt;flashplayer.version.minor&gt;1&lt;/flashplayer.version.minor&gt;
		&lt;flashplayer.version&gt;${flashplayer.version.major}.${flashplayer.version.minor}&lt;/flashplayer.version&gt;
		&lt;locale&gt;en_US&lt;/locale&gt;
	&lt;/properties&gt;
&nbsp;
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;
			&lt;artifactId&gt;flex-framework&lt;/artifactId&gt;
			&lt;version&gt;${flex.sdk.version}&lt;/version&gt;
			&lt;type&gt;pom&lt;/type&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;
					&lt;artifactId&gt;playerglobal&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.adobe.flex.framework&lt;/groupId&gt;
			&lt;artifactId&gt;playerglobal&lt;/artifactId&gt;
			&lt;classifier&gt;${flashplayer.version.major}.${flashplayer.version.minor}&lt;/classifier&gt;
			&lt;version&gt;${flex.sdk.version}&lt;/version&gt;
			&lt;type&gt;swc&lt;/type&gt;
			&lt;scope&gt;external&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.adobe.flexunit&lt;/groupId&gt;
			&lt;artifactId&gt;flexunit&lt;/artifactId&gt;
			&lt;version&gt;${flexunit.version}&lt;/version&gt;
			&lt;type&gt;swc&lt;/type&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.googlecode.apparat&lt;/groupId&gt;
			&lt;artifactId&gt;apparat-ersatz&lt;/artifactId&gt;
			&lt;version&gt;${apparat.version}&lt;/version&gt;
			&lt;type&gt;swc&lt;/type&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
&nbsp;
	&lt;build&gt;
		&lt;defaultGoal&gt;install&lt;/defaultGoal&gt;
		&lt;sourceDirectory&gt;src/main/as3&lt;/sourceDirectory&gt;
		&lt;testSourceDirectory&gt;src/test/as3&lt;/testSourceDirectory&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-clean-plugin&lt;/artifactId&gt;
				&lt;configuration&gt;
					&lt;filesets&gt;
						&lt;fileset&gt;
							&lt;directory&gt;src/test/as3&lt;/directory&gt;
							&lt;includes&gt;
								&lt;include&gt;FlexUnitApplication.mxml&lt;/include&gt;
							&lt;/includes&gt;
						&lt;/fileset&gt;
					&lt;/filesets&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.sonatype.flexmojos&lt;/groupId&gt;
				&lt;artifactId&gt;flexmojos-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;${flexmojos.version}&lt;/version&gt;
				&lt;extensions&gt;true&lt;/extensions&gt;
				&lt;dependencies&gt;
					&lt;dependency&gt;
						&lt;groupId&gt;com.adobe.flex&lt;/groupId&gt;
						&lt;artifactId&gt;compiler&lt;/artifactId&gt;
						&lt;version&gt;${flex.sdk.version}&lt;/version&gt;
						&lt;type&gt;pom&lt;/type&gt;
					&lt;/dependency&gt;
				&lt;/dependencies&gt;
				&lt;configuration&gt;
					&lt;coverage&gt;true&lt;/coverage&gt;
					&lt;configurationReport&gt;true&lt;/configurationReport&gt;
					&lt;targetPlayer&gt;${flashplayer.version}&lt;/targetPlayer&gt;
					&lt;swfVersion&gt;${flashplayer.version.swf}&lt;/swfVersion&gt;
					&lt;locales&gt;
						&lt;param&gt;${locale}&lt;/param&gt;
					&lt;/locales&gt;
					&lt;updateSecuritySandbox&gt;true&lt;/updateSecuritySandbox&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;com.googlecode.apparat&lt;/groupId&gt;
				&lt;artifactId&gt;apparat-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;${apparat.version}&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;goals&gt;
							&lt;goal&gt;reducer&lt;/goal&gt;
							&lt;goal&gt;tdsi&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
					&lt;execution&gt;
						&lt;id&gt;tsdi-test&lt;/id&gt;
						&lt;phase&gt;process-test-classes&lt;/phase&gt;
						&lt;goals&gt;
							&lt;goal&gt;tdsi&lt;/goal&gt;
						&lt;/goals&gt;
						&lt;configuration&gt;
							&lt;overrideArtifact&gt;${project.build.testOutputDirectory}/TestRunner.swf&lt;/overrideArtifact&gt;
						&lt;/configuration&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
				&lt;configuration&gt;
					&lt;mergeABC&gt;false&lt;/mergeABC&gt;
					&lt;sortCPool&gt;false&lt;/sortCPool&gt;
					&lt;mergeCF&gt;false&lt;/mergeCF&gt;
					&lt;alchemyExpansion&gt;true&lt;/alchemyExpansion&gt;
					&lt;inlineExpansion&gt;true&lt;/inlineExpansion&gt;
					&lt;macroExpansion&gt;true&lt;/macroExpansion&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;
&nbsp;
	&lt;pluginRepositories&gt;
		&lt;pluginRepository&gt;
			&lt;id&gt;central&lt;/id&gt;
			&lt;name&gt;Maven Plugin Repository&lt;/name&gt;
			&lt;url&gt;http://repo1.maven.org/maven2&lt;/url&gt;
			&lt;snapshots&gt;
				&lt;enabled&gt;false&lt;/enabled&gt;
			&lt;/snapshots&gt;
		&lt;/pluginRepository&gt;
		&lt;pluginRepository&gt;
			&lt;id&gt;flexmojos-repository&lt;/id&gt;
			&lt;url&gt;http://repository.sonatype.org/content/groups/flexgroup/&lt;/url&gt;
		&lt;/pluginRepository&gt;
		&lt;pluginRepository&gt;
			&lt;id&gt;oss-sonatype&lt;/id&gt;
			&lt;url&gt;http://oss.sonatype.org/content/repositories/snapshots&lt;/url&gt;
		&lt;/pluginRepository&gt;
	&lt;/pluginRepositories&gt;
&nbsp;
	&lt;repositories&gt;
		&lt;repository&gt;
			&lt;id&gt;flex-mojos-repository&lt;/id&gt;
			&lt;url&gt;http://repository.sonatype.org/content/groups/flexgroup/&lt;/url&gt;
			&lt;releases&gt;
				&lt;enabled&gt;true&lt;/enabled&gt;
			&lt;/releases&gt;
			&lt;snapshots&gt;
				&lt;enabled&gt;true&lt;/enabled&gt;
			&lt;/snapshots&gt;
		&lt;/repository&gt;
	&lt;/repositories&gt;
&nbsp;
&lt;/project&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=58</wfw:commentRss>
		</item>
		<item>
		<title>ImmutableEnum</title>
		<link>http://compiler.kaustic.net/lab/?p=57</link>
		<comments>http://compiler.kaustic.net/lab/?p=57#comments</comments>
		<pubDate>Tue, 22 Nov 2011 09:23:25 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

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

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=57</guid>
		<description><![CDATA[The Unit Test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package be.idamf.sofa.lang
{
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertFalse;
	import org.flexunit.asserts.assertTrue;
&#160;
	public class ImmutableEnumTest
	{
		public function ImmutableEnumTest()
		{
		}
&#160;
		[Test]
		/**
		 * The Enum name should be a string literal equal to the name
		 * of the static constant member.
		 */
		public function test_name():void
		{
			assertEquals(&#34;A&#34;, ExampleEnum.A.name);
			assertEquals(&#34;B&#34;, ExampleEnum.B.name);
&#160;
			assertTrue(ExampleEnum.A.name == AnotherEnum.A.name);
		}
&#160;
		[Test]
		/**
		 * An Enum is only equal to itself or equal to a String literal
		 * representing its name.
		 [...]]]></description>
			<content:encoded><![CDATA[<h2>The Unit Test</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
</pre></td><td class="code"><pre>package be.idamf.sofa.lang
{
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertFalse;
	import org.flexunit.asserts.assertTrue;
&nbsp;
	public class ImmutableEnumTest
	{
		public function ImmutableEnumTest()
		{
		}
&nbsp;
		[Test]
		/**
		 * The Enum name should be a string literal equal to the name
		 * of the static constant member.
		 */
		public function test_name():void
		{
			assertEquals(&quot;A&quot;, ExampleEnum.A.name);
			assertEquals(&quot;B&quot;, ExampleEnum.B.name);
&nbsp;
			assertTrue(ExampleEnum.A.name == AnotherEnum.A.name);
		}
&nbsp;
		[Test]
		/**
		 * An Enum is only equal to itself or equal to a String literal
		 * representing its name.
		 */
		public function test_equals():void
		{
			assertTrue(ExampleEnum.A.equals(ExampleEnum.A));
&nbsp;
			assertTrue(ExampleEnum.A.equals(&quot;A&quot;));
			assertTrue(ExampleEnum.B.equals(&quot;B&quot;));
&nbsp;
			assertFalse(ExampleEnum.A.equals(ExampleEnum.B));
			assertFalse(ExampleEnum.A.equals(AnotherEnum.A));
		}
&nbsp;
		[Test(expects=&quot;Error&quot;)]
		/**
		 * ImmutableEnum is an Abstract Class and cannot be instantiated.
		 */
		public function test_abstract():void
		{
			new ImmutableEnum();
		}
&nbsp;
		[Test(expects=&quot;Error&quot;)]
		/**
		 * An ImmutableEnum implementation should be locked from within
		 * the Class using a Static Initializer.
		 */
		public function test_instantiate():void
		{
			new ExampleEnum();
		}
&nbsp;
		[Test(expects=&quot;Error&quot;)]
		/**
		 * When no explicit Static Initialization lock was done the use
		 * of the Enum should be discouraged by throwing a runtime Error.
		 */
		public function test_mutable():void
		{
			MutableEnum.A.equals(ExampleEnum.A);
		}
	}
}
&nbsp;
import be.idamf.sofa.lang.ImmutableEnum;
&nbsp;
internal class ExampleEnum extends ImmutableEnum
{
	public static const A:ExampleEnum = new ExampleEnum();
	public static const B:ExampleEnum = new ExampleEnum();
&nbsp;
	{
		lock(ExampleEnum);
	}
&nbsp;
	public function ExampleEnum()
	{
		super();
	}
}
&nbsp;
internal class AnotherEnum extends ImmutableEnum
{
	public static const A:AnotherEnum = new AnotherEnum();
&nbsp;
	{
		lock(AnotherEnum);
	}
&nbsp;
	public function AnotherEnum()
	{
		super();
	}
} 
&nbsp;
internal class MutableEnum extends ImmutableEnum
{
	public static const A:MutableEnum = new MutableEnum();
&nbsp;
	public function MutableEnum()
	{
		super();
	}
}</pre></td></tr></table></div>

<h2>The Class</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code"><pre>package be.idamf.sofa.lang
{
	import avmplus.DescribeType;
	import avmplus.HIDE_OBJECT;
	import avmplus.INCLUDE_TRAITS;
	import avmplus.INCLUDE_VARIABLES;
&nbsp;
	import flash.utils.getQualifiedClassName;
&nbsp;
	public class ImmutableEnum
	{
		use namespace _internal;
&nbsp;
		private static const ENUMS:Object = {};
&nbsp;
		public static function lock(Enum:Class):void
		{
			ENUMS[getQualifiedClassName(Enum)] = Enum;
		}
&nbsp;
		_internal var _isInitialized:Boolean;
		_internal var _className:String;
		_internal var _name:String;
&nbsp;
		public function ImmutableEnum()
		{
			_className = getQualifiedClassName(this);
&nbsp;
			if (ENUMS.hasOwnProperty(_className))
				throw new Error(&quot;Locked Class&quot;);
&nbsp;
			if (_className.split(&quot;::&quot;)[1] == &quot;ImmutableEnum&quot;)
				throw new Error(&quot;Abstract Class&quot;);
		}
&nbsp;
		public final function get name():String
		{
			if (!_isInitialized)
				init();
&nbsp;
			return _name;
		}
&nbsp;
		private function init():void
		{
			var Enum:Class = ENUMS[_className];
&nbsp;
			if (Enum == null)
				throw new Error(&quot;Enum Class should be locked and immutable&quot;);
&nbsp;
			var vars:Object = DescribeType.JSON(Enum, HIDE_OBJECT | INCLUDE_TRAITS | INCLUDE_VARIABLES).traits.variables;
			var enum:ImmutableEnum;
&nbsp;
			for each (var member:Object in vars)
			{
				if (member.type == &quot;readonly&quot;)
					continue;
&nbsp;
				enum = Enum[member.name];
&nbsp;
				if (!enum._isInitialized)
				{
					enum._name = member.name;
					enum._isInitialized = true;
				}
			}
		}
&nbsp;
		public function equals(enum:Object):Boolean
		{
			if (!_isInitialized)
				init();
&nbsp;
			switch (true)
			{
				case enum === this:
					return true;
&nbsp;
				case enum is String:
					return (_name == enum);
&nbsp;
				default:
					return false;
			}
		}
&nbsp;
		public function toString():String
		{
			return _className + &quot;/&quot; + name;
		}
	}
}
&nbsp;
internal namespace _internal;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=57</wfw:commentRss>
		</item>
		<item>
		<title>JSON (de)serialization</title>
		<link>http://compiler.kaustic.net/lab/?p=55</link>
		<comments>http://compiler.kaustic.net/lab/?p=55#comments</comments>
		<pubDate>Thu, 19 May 2011 13:20:01 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=55</guid>
		<description><![CDATA[When it comes to JSON (de)serialization in Flash, some of the options are:

Adobe (AS3): com.adobe.serialization.json 
ason (Alchemy): com.rational.serialization.json
Blooddy (haXe): by.blooddy.crypto.serialization

Flash Player 11 also brings us Native JSON
Deserialization
How do they compare performance-wise for deserialization? A little benchmarking on a list of 50 typed objects (see below how measurements were done) using Flash Player Incubator 11.0.1.3 (Debug) gives [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to JSON (de)serialization in Flash, some of the options are:</p>
<ul>
<li><strong>Adobe </strong>(AS3): <a href="https://github.com/mikechambers/as3corelib/tree/master/src/com/adobe/serialization/json" target="_blank">com.adobe.serialization.json </a></li>
<li><strong>ason </strong>(Alchemy): <a href="http://code.google.com/p/ason/" target="_blank">com.rational.serialization.json</a></li>
<li><strong>Blooddy </strong>(haXe): <a href="http://code.google.com/p/blooddy/source/browse/trunk/blooddy_crypto/src-hx/by/blooddy/crypto/serialization/JSON.hx" target="_blank">by.blooddy.crypto.serialization</a></li>
</ul>
<p>Flash Player 11 also brings us <a href="http://www.bytearray.org/?p=3066" target="_blank">Native JSON</a></p>
<h2>Deserialization</h2>
<p>How do they compare performance-wise for deserialization? A little benchmarking on a list of 50 typed objects (see below how measurements were done) using Flash Player Incubator 11.0.1.3 (Debug) gives following (average) times (adding AMF for comparison):</p>
<ul>
<li><strong>Adobe</strong>: 36.05 ms</li>
<li><strong>ason</strong>: 9.30 ms</li>
<li><strong>Blooddy</strong>: 3.72 ms (*)</li>
<li><strong>Native</strong>: 0.31 ms (**)</li>
<li><strong>AMF0</strong>: 2.52 ms</li>
<li><strong>AMF3</strong>: 1.54 ms</li>
</ul>
<p>Some observations:</p>
<ul>
<li>Blooddy (*) is blooddy fast for a non-native implementation and this is an example of the haXe compiler rocking hard. It is nearly as fast as AMF (yet AMF deserializes to typed Objects in the same effort).</li>
<li>The Native (**) JSON deserialization <em><strong>blows everything out of the water</strong></em>. It deserializes to dynamic Objects, which means you need additional tricks to get a typed graph if needed, but hey&#8230; less than one <em>millisecond</em>?</li>
</ul>
<h2>Serialization</h2>
<p>Serializing objects into a JSON-encoded string might for some be less interesting that deserialization&#8230; nevertheless, let&#8217;s see&#8230; (same case).</p>
<ul>
<li><strong>Adobe</strong>: 77.67 ms</li>
<li><strong>ason</strong>: 72.22 ms</li>
<li><strong>Blooddy</strong>: 42.04 ms (*)</li>
<li><strong>Native</strong>: 4.4 ms (**)</li>
<li><strong>AMF0</strong>: 0.05 ms</li>
<li><strong>AMF3</strong>: 0.01 ms</li>
</ul>
<p>It is not surprising encoding is slower than decoding, as it requires that every object is introspected for read/write accessors and public properties&#8230; (AMF is absolutely awesome though)</p>
<ul>
<li>Still, Blooddy (*) wins again.</li>
<li>The Native (**) JSON serialization is the fastest of this bunch, yet not so fast as AMF0/3.</li>
</ul>
<p>I started to wonder why Adobe/ason/Blooddy were so slow, &#8216;cos our homebrew XML serializer clocked at 5 ms for the same Array of 50 objects&#8230; and the culprit is&#8230; <strong>flash.utils.describeType():XML</strong>!</p>
<h3>flash.utils.describeType vs avmplus.describeTypeJSON</h3>
<p>The avmplus.describeTypeJSON trick (<a href="?p=49">info here</a>) is very important here&#8230; it makes the difference between 77 ms and 10 ms!</p>
<p>I took the com.adobe.serialization.json.JSONEncoder source and placed an implementation based on describeTypeJSON in the objectToString() method (<a href="http://compiler.kaustic.net/lab/wp-content/uploads/2011/05/adobemodjsonencoder.as" title="adobemodjsonencoder.as">source</a>).</p>
<ul>
<li>Adobe: 77.67 ms</li>
<li><strong>Adobe Mod: 10.50 ms !</strong></li>
<li>Native: 4.4 ms</li>
</ul>
<p>An expensive method that remains in the Adobe implementation is the escapeString() method that gets called for every String and loops individually over every character&#8230; When this is omitted, the encoding simplified and rewritten in a single recursive method, encoding time goes <em>down to less than the Native JSON method (but yes, that *is* cheatin&#8217;)</em>.</p>
<p>So it is possible to get pretty fast JSON data encoding using an AS3 implementation. If Blooddy would use the different describeType method, would it reach the same speed as the Native impl?</p>
<h4><em>How the measurements were done</em></h4>
<p>One hundred times, every frame, the dataset of 50 objects was encoded once and the time it took measured using flash.utils.getTimer() and from this the average was calculated.</p>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=55</wfw:commentRss>
		</item>
		<item>
		<title>Number Serialization&#8230;</title>
		<link>http://compiler.kaustic.net/lab/?p=54</link>
		<comments>http://compiler.kaustic.net/lab/?p=54#comments</comments>
		<pubDate>Tue, 01 Feb 2011 15:15:13 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=54</guid>
		<description><![CDATA[
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package
{
	import flash.display.Sprite;
	import flash.utils.ByteArray;
&#160;
	public class Main extends Sprite
	{
		public function Main()
		{
			var bytes:ByteArray = new ByteArray();
			bytes.writeDouble(0.1);
			bytes.writeFloat(0.1);
			bytes.writeObject(new BigDecimal(0.1));
			bytes.position = 0;
&#160;
			trace(bytes.readDouble());
			// 0.1 
&#160;
			trace(bytes.readFloat());
			// 0.10000000149011612
			// Ô_ô
&#160;
			trace(BigDecimal(bytes.readObject()).value);
			// 0.1
			// n_n
		}
	}
}
&#160;
import flash.net.registerClassAlias;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.utils.IExternalizable;
&#160;
internal class BigDecimal implements IExternalizable
{
	{
		registerClassAlias(&#34;BigDecimal&#34;, BigDecimal);
	}
&#160;
	public var value:Number;
&#160;
	public function BigDecimal(value:Number = NaN)
	{
		this.value = value;
	}
&#160;
	public function readExternal(input:IDataInput):void
	{
		value = parseFloat(input.readUTF());
	}
&#160;
	public function writeExternal(output:IDataOutput):void
	{
		output.writeUTF(value.toString());
	}
}

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre>package
{
	import flash.display.Sprite;
	import flash.utils.ByteArray;
&nbsp;
	public class Main extends Sprite
	{
		public function Main()
		{
			var bytes:ByteArray = new ByteArray();
			bytes.writeDouble(0.1);
			bytes.writeFloat(0.1);
			bytes.writeObject(new BigDecimal(0.1));
			bytes.position = 0;
&nbsp;
			trace(bytes.readDouble());
			// 0.1 
&nbsp;
			trace(bytes.readFloat());
			// 0.10000000149011612
			// Ô_ô
&nbsp;
			trace(BigDecimal(bytes.readObject()).value);
			// 0.1
			// n_n
		}
	}
}
&nbsp;
import flash.net.registerClassAlias;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.utils.IExternalizable;
&nbsp;
internal class BigDecimal implements IExternalizable
{
	{
		registerClassAlias(&quot;BigDecimal&quot;, BigDecimal);
	}
&nbsp;
	public var value:Number;
&nbsp;
	public function BigDecimal(value:Number = NaN)
	{
		this.value = value;
	}
&nbsp;
	public function readExternal(input:IDataInput):void
	{
		value = parseFloat(input.readUTF());
	}
&nbsp;
	public function writeExternal(output:IDataOutput):void
	{
		output.writeUTF(value.toString());
	}
}</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=54</wfw:commentRss>
		</item>
		<item>
		<title>Garbage Collection Log Info</title>
		<link>http://compiler.kaustic.net/lab/?p=53</link>
		<comments>http://compiler.kaustic.net/lab/?p=53#comments</comments>
		<pubDate>Tue, 04 Jan 2011 20:29:26 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

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

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=53</guid>
		<description><![CDATA[
Cortizone contains a neato trick to periodically check if the Flash Player&#8217;s Garbage Collector has run.
By including the mixin ProfilerLog class (using the compiler argument -includes be.idamf.profiler.ProfilerLog) the info will for example show up in the Flash Builder Console when using a TraceTarget instance in a Flex application.
This example will produce the output below after [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://compiler.kaustic.net/lab/wp-content/uploads/2011/01/oscar-can.jpg" alt="Oscar the Grouch" /></p>
<p><a href="http://cortizone.googlecode.com" target="_blank">Cortizone</a> contains <a href="http://code.google.com/p/cortizone/source/browse/cortizone-profiler/src/main/as3/be/idamf/profiler/GarbageCollector.as" target="_blank">a neato trick to periodically check if the Flash Player&#8217;s Garbage Collector has run</a>.</p>
<p>By including the mixin <strong>ProfilerLog</strong> class (using the compiler argument <em>-includes be.idamf.profiler.ProfilerLog</em>) the info will for example show up in the Flash Builder Console when using a <strong>TraceTarget</strong> instance in a Flex application.</p>
<p><a href="http://code.google.com/p/cortizone/source/browse/cortizone-profiler/src/test/as3/Example01.mxml" target="_blank">This example</a> will produce the output below after a mark&#8217;n&#8217;sweep:</p>
<pre>
20:23:08.631 Garbage Collection Complete
20:23:08.633 Total Memory: 25Mb</pre>
<p>Based on the same principle i&#8217;m thinking of adding utilities in the cortizone-profiler library for tracking the number of instances of a certain type and have info in the logs similar to the info found in the Flash Builder Profiler, yet highly optimised and specific (read: *not* degrading the performance of the actual application to a useless level if there&#8217;s a fair amount of action going on&#8230;).</p>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=53</wfw:commentRss>
		</item>
		<item>
		<title>Preview: cortizone-amf + as3-commons-bytecode = class generation</title>
		<link>http://compiler.kaustic.net/lab/?p=51</link>
		<comments>http://compiler.kaustic.net/lab/?p=51#comments</comments>
		<pubDate>Sun, 19 Dec 2010 14:25:19 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=51</guid>
		<description><![CDATA[A little sneak peak&#8230; generation of the object definitions from AMF3 serialised objects (package and classname derived from alias type). An alternative way to inspect a Remoting Service and generate a DTO SWC?
The projects:
cortizone-amf
as3-commons-bytecode
(cortizone-amf is currently being rewritten in haXe)

package
{
	import be.idamf.flash.amf.Amf3Input;
	import be.idamf.flash.amf.TraitsInfo;

	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.net.FileReference;
	import flash.utils.ByteArray;

	import org.as3commons.bytecode.emit.IAbcBuilder;
	import org.as3commons.bytecode.emit.IClassBuilder;
	import org.as3commons.bytecode.emit.IPackageBuilder;
	import org.as3commons.bytecode.emit.impl.AbcBuilder;

	public class AMF3toSWF extends Sprite
	{

		[Embed(source="data.amf3", mimeType="application/octet-stream")]
		public [...]]]></description>
			<content:encoded><![CDATA[<p>A little sneak peak&#8230; generation of the object definitions from AMF3 serialised objects (package and classname derived from alias type). An alternative way to inspect a Remoting Service and generate a DTO SWC?</p>
<p>The projects:<br />
<a href="http://code.google.com/p/cortizone/source/browse/#svn%2Ftrunk%2Fcortizone-amf">cortizone-amf</a><br />
<a href="http://www.as3commons.org/as3-commons-bytecode">as3-commons-bytecode</a></p>
<p>(cortizone-amf is currently being rewritten in haXe)</p>
<pre>
package
{
	import be.idamf.flash.amf.Amf3Input;
	import be.idamf.flash.amf.TraitsInfo;

	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.net.FileReference;
	import flash.utils.ByteArray;

	import org.as3commons.bytecode.emit.IAbcBuilder;
	import org.as3commons.bytecode.emit.IClassBuilder;
	import org.as3commons.bytecode.emit.IPackageBuilder;
	import org.as3commons.bytecode.emit.impl.AbcBuilder;

	public class AMF3toSWF extends Sprite
	{

		[Embed(source="data.amf3", mimeType="application/octet-stream")]
		public static const AMF3_DATA:Class;

		public var swf:ByteArray;

		public function AMF3toSWF()
		{
			var amf3Input:Amf3Input;
			var traits:Array;
			var info:TraitsInfo;
			var name:String;
			var abcBuilder:IAbcBuilder;
			var packageBuilder:IPackageBuilder;
			var classBuilder:IClassBuilder;
			var packaze:String;
			var clazz:String;
			var path:Array;

			amf3Input = new Amf3Input(new AMF3_DATA());
			amf3Input.readObject();

			traits = amf3Input.getTraits();

			abcBuilder = new AbcBuilder();

			for each (info in traits)
			{
				path = info.type.split(".");
				clazz = path.pop();
				packaze = path.join(".");
				packageBuilder = abcBuilder.definePackage(packaze);
				classBuilder = packageBuilder.defineClass(clazz);

				for each (name in info.properties)
					classBuilder.defineProperty(name, "Object");
			}

			swf = abcBuilder.buildAndExport();

			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
		}

		protected function keyDownHandler(event:KeyboardEvent):void
		{
			new FileReference().save(swf);
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=51</wfw:commentRss>
		</item>
		<item>
		<title>as3-commons-bytecode: Alchemy Opcodes</title>
		<link>http://compiler.kaustic.net/lab/?p=50</link>
		<comments>http://compiler.kaustic.net/lab/?p=50#comments</comments>
		<pubDate>Fri, 03 Dec 2010 09:05:44 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=50</guid>
		<description><![CDATA[A little test&#8230; *oh the possibilities*

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;

	import org.as3commons.bytecode.abc.enum.Opcode;
	import org.as3commons.bytecode.emit.IAbcBuilder;
	import org.as3commons.bytecode.emit.IClassBuilder;
	import org.as3commons.bytecode.emit.IMethodBuilder;
	import org.as3commons.bytecode.emit.IPackageBuilder;
	import org.as3commons.bytecode.emit.impl.AbcBuilder;

	public class AlchemyOpcodeTest extends Sprite
	{
		public function AlchemyOpcodeTest()
		{
			var abcBuilder:IAbcBuilder;
			var packageBuilder:IPackageBuilder;
			var classBuilder:IClassBuilder;
			var methodBuilder:IMethodBuilder;

			abcBuilder = new AbcBuilder();
			packageBuilder = abcBuilder.definePackage("com.kaustic.bytecode");
			classBuilder = packageBuilder.defineClass("Alchemist");

			methodBuilder = classBuilder.defineMethod("writeByte");
			methodBuilder.defineArgument("uint"); // address
			methodBuilder.defineArgument("int"); // value
			methodBuilder.addOpcode(Opcode.getlocal_0).addOpcode(Opcode.pushscope).addOpcode(Opcode.getlocal_2).addOpcode(Opcode.getlocal_1).addOpcode(Opcode.li8).addOpcode(Opcode.returnvoid);

			abcBuilder.addEventListener(Event.COMPLETE, abcBuilder_completeHandler);
			abcBuilder.buildAndLoad();
		}

		public function abcBuilder_completeHandler(event:Event):void
		{
			var kind:Class;
			var bytes:ByteArray;
			var alchemist:*;

			kind = Class(getDefinitionByName("com.kaustic.bytecode.Alchemist"));

			bytes = new ByteArray();
			bytes.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;

			ApplicationDomain.currentDomain.domainMemory = bytes;

			alchemist [...]]]></description>
			<content:encoded><![CDATA[<p>A little test&#8230; *oh the possibilities*</p>
<pre>
package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;

	import org.as3commons.bytecode.abc.enum.Opcode;
	import org.as3commons.bytecode.emit.IAbcBuilder;
	import org.as3commons.bytecode.emit.IClassBuilder;
	import org.as3commons.bytecode.emit.IMethodBuilder;
	import org.as3commons.bytecode.emit.IPackageBuilder;
	import org.as3commons.bytecode.emit.impl.AbcBuilder;

	public class AlchemyOpcodeTest extends Sprite
	{
		public function AlchemyOpcodeTest()
		{
			var abcBuilder:IAbcBuilder;
			var packageBuilder:IPackageBuilder;
			var classBuilder:IClassBuilder;
			var methodBuilder:IMethodBuilder;

			abcBuilder = new AbcBuilder();
			packageBuilder = abcBuilder.definePackage("com.kaustic.bytecode");
			classBuilder = packageBuilder.defineClass("Alchemist");

			methodBuilder = classBuilder.defineMethod("writeByte");
			methodBuilder.defineArgument("uint"); // address
			methodBuilder.defineArgument("int"); // value
			methodBuilder.addOpcode(Opcode.getlocal_0).addOpcode(Opcode.pushscope).addOpcode(Opcode.getlocal_2).addOpcode(Opcode.getlocal_1).addOpcode(Opcode.li8).addOpcode(Opcode.returnvoid);

			abcBuilder.addEventListener(Event.COMPLETE, abcBuilder_completeHandler);
			abcBuilder.buildAndLoad();
		}

		public function abcBuilder_completeHandler(event:Event):void
		{
			var kind:Class;
			var bytes:ByteArray;
			var alchemist:*;

			kind = Class(getDefinitionByName("com.kaustic.bytecode.Alchemist"));

			bytes = new ByteArray();
			bytes.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;

			ApplicationDomain.currentDomain.domainMemory = bytes;

			alchemist = new kind();
			alchemist.writeByte(13, 0x0A); // write a 10 at position 13

			bytes.position = 13; // at position 13
			trace(bytes.readByte()); // resides a 10, yay!
		}
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=50</wfw:commentRss>
		</item>
		<item>
		<title>Flash 10.1 avmplus.*</title>
		<link>http://compiler.kaustic.net/lab/?p=49</link>
		<comments>http://compiler.kaustic.net/lab/?p=49#comments</comments>
		<pubDate>Mon, 23 Aug 2010 19:17:43 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=49</guid>
		<description><![CDATA[If you introspect the Flash 10.1 playerglobal.swc (in Flash Builder for example) you will notice a package that was not there in Flash Player 10, namely avmplus.
The interesting part is that it contains a method describeTypeJSON(*, uint):Object (which is an internal function)
The first parameter is the object to describe and the second is a flags [...]]]></description>
			<content:encoded><![CDATA[<p>If you introspect the Flash 10.1 playerglobal.swc (in Flash Builder for example) you will notice a package that was not there in Flash Player 10, namely <strong>avmplus</strong>.</p>
<p>The interesting part is that it contains a method <strong>describeTypeJSON(*, uint):Object</strong> (which is an internal function)<br />
The first parameter is the object to describe and the second is a flags parameter (defined as uint constants in the very same package).</p>
<pre>
HIDE_NSURI_METHODS = 1
INCLUDE_BASES = 2
INCLUDE_INTERFACES = 4
INCLUDE_VARIABLES = 8
INCLUDE_ACCESSORS = 16
INCLUDE_METHODS = 32
INCLUDE_METADATA = 64
INCLUDE_CONSTRUCTOR = 128
INCLUDE_TRAITS = 256
USE_ITRAITS = 512
HIDE_OBJECT = 1024
FLASH10_FLAGS = 1535</pre>
<p>By doing a little monkey-patch-hacking (creating something in the same package so that it can access the internals), it is possible to expose this method for all yer class inspection purposes&#8230; *grin*</p>
<p>Example:</p>
<pre>
package avmplus
{
    public function getInterfaces(object:*):Array
    {
        return describeTypeJSON(object, INCLUDE_TRAITS | INCLUDE_INTERFACES).traits.interfaces;
    }
}</pre>
<p>Update August 24th 2010: Till Schneidereit&#8217;s <a href="http://www.tillschneidereit.de/2009/11/22/improved-reflection-support-in-flash-player-10-1/">in-depth article</a> on the subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=49</wfw:commentRss>
		</item>
		<item>
		<title>FLAC playback in AIR 2.0</title>
		<link>http://compiler.kaustic.net/lab/?p=48</link>
		<comments>http://compiler.kaustic.net/lab/?p=48#comments</comments>
		<pubDate>Fri, 04 Jun 2010 22:09:49 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Audio Processing]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=48</guid>
		<description><![CDATA[A little experiment with the NativeProcess API in AIR 2.0&#8230;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;s:WindowedApplication xmlns:fx=&#34;http://ns.adobe.com/mxml/2009&#34; 
					   xmlns:s=&#34;library://ns.adobe.com/flex/spark&#34; 
					   xmlns:mx=&#34;library://ns.adobe.com/flex/mx&#34;
					   applicationComplete=&#34;applicationCompleteHandler(event)&#34;&#62;
	&#60;fx:Script&#62;
		&#60;![CDATA[
			import flash.utils.getTimer;
&#160;
			import mx.events.FlexEvent;
&#160;
			public var process:NativeProcess;
			public var sound:Sound;
			public var channel:SoundChannel;
			public var buffer:ByteArray;
			public var bufferSize:int = 4096;
			public var pos:uint = 0;
			public var t:int;
&#160;
			protected function applicationCompleteHandler(event:FlexEvent):void
			{
				if (!NativeProcess.isSupported)
				{
					out.appendText(&#34;NativeProcess not supported&#34;);
					return;
				}
&#160;
				var file:File = File.applicationDirectory.resolvePath(&#34;bin/flac.exe&#34;);
				var info:NativeProcessStartupInfo = new [...]]]></description>
			<content:encoded><![CDATA[<p>A little experiment with the NativeProcess API in AIR 2.0&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
</pre></td><td class="code"><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:WindowedApplication xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
					   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot; 
					   xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;
					   applicationComplete=&quot;applicationCompleteHandler(event)&quot;&gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
			import flash.utils.getTimer;
&nbsp;
			import mx.events.FlexEvent;
&nbsp;
			public var process:NativeProcess;
			public var sound:Sound;
			public var channel:SoundChannel;
			public var buffer:ByteArray;
			public var bufferSize:int = 4096;
			public var pos:uint = 0;
			public var t:int;
&nbsp;
			protected function applicationCompleteHandler(event:FlexEvent):void
			{
				if (!NativeProcess.isSupported)
				{
					out.appendText(&quot;NativeProcess not supported&quot;);
					return;
				}
&nbsp;
				var file:File = File.applicationDirectory.resolvePath(&quot;bin/flac.exe&quot;);
				var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
&nbsp;
				info.executable = file;
				info.arguments.push(&quot;--decode&quot;);
				info.arguments.push(&quot;--stdout&quot;);
				info.arguments.push(&quot;--totally-silent&quot;);
				info.arguments.push(&quot;--force-raw-format&quot;);
				info.arguments.push(&quot;--endian=little&quot;);
				info.arguments.push(&quot;--sign=signed&quot;);
				info.arguments.push(File.applicationDirectory.resolvePath(&quot;test.flac&quot;).nativePath);
&nbsp;
				process = new NativeProcess();
				process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, process_outputDataHandler);
				process.addEventListener(Event.STANDARD_OUTPUT_CLOSE, process_outputCloseHandler);
				process.start(info);
&nbsp;
				buffer = new ByteArray();
				buffer.endian = Endian.LITTLE_ENDIAN;
&nbsp;
				sound = new Sound();
				sound.addEventListener(SampleDataEvent.SAMPLE_DATA, sound_sampleDataHandler);
				channel = sound.play();
&nbsp;
				out.appendText(&quot;Playing\n&quot;);
&nbsp;
				t = getTimer();
			}
&nbsp;
			protected function process_outputDataHandler(event:ProgressEvent):void
			{
				process.standardOutput.readBytes(buffer, buffer.length, process.standardOutput.bytesAvailable);
			}
&nbsp;
			protected function process_outputCloseHandler(event:Event):void
			{
				out.appendText(&quot;FLAC decoded in &quot; + (getTimer() - t) + &quot; ms\n&quot;);
			}
&nbsp;
			protected function sound_sampleDataHandler(event:SampleDataEvent):void
			{
				if (buffer.length &lt; (bufferSize * 4))
				{
					for (var i:int = 0; i &lt; (bufferSize * 2); ++i)
						event.data.writeFloat(0.0);
				}
				else if (buffer.position == buffer.length)
				{
					channel.stop();
					out.appendText(&quot;Stopped\n&quot;);
				}
				else
				{
					buffer.position = pos;
&nbsp;
					for (var j:int = 0; j &lt; (bufferSize * 2); ++j)
					{
						if (buffer.position == buffer.length)
							event.data.writeFloat(0.0);
						else
							event.data.writeFloat(buffer.readShort() / 32767.0);
					}
&nbsp;
					pos += (bufferSize * 4);
				}
			}
&nbsp;
		]]&gt;
	&lt;/fx:Script&gt;
&nbsp;
	&lt;s:TextArea id=&quot;out&quot;
				width=&quot;100%&quot;
				height=&quot;100%&quot;/&gt;
&nbsp;
&lt;/s:WindowedApplication&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=48</wfw:commentRss>
		</item>
		<item>
		<title>Flex Localised Resource Bundle Compiler</title>
		<link>http://compiler.kaustic.net/lab/?p=46</link>
		<comments>http://compiler.kaustic.net/lab/?p=46#comments</comments>
		<pubDate>Tue, 11 Aug 2009 21:45:08 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://compiler.kaustic.net/lab/?p=46</guid>
		<description><![CDATA[The Flex compiler moaning Unable to resolve resource bundle &#8220;xxx&#8221; for locale &#8220;yy_ZZ&#8221; sound familiar?
If you&#8217;re lucky you get away with running copylocale, but i always stumble upon nastier stuff (most projects for Belgian clients are bi-lingual&#8230; erm&#8230; bi-local French/Dutch).
To solve this for once and for all i wanted to create an elegant ANT scripty [...]]]></description>
			<content:encoded><![CDATA[<p>The Flex compiler moaning <em>Unable to resolve resource bundle &#8220;xxx&#8221; for locale &#8220;yy_ZZ&#8221;</em> sound familiar?</p>
<p>If you&#8217;re lucky you get away with running copylocale, but i always stumble upon <a href="http://bugs.adobe.com/jira/browse/SDK-16142">nastier stuff</a> (most projects for Belgian clients are bi-lingual&#8230; erm&#8230; bi-local French/Dutch).</p>
<p>To solve this for once and for all i wanted to create an elegant ANT scripty that takes care of all my localisation woes&#8230; Something easy, as it should be (c).<br />
Thus i embarked on a (somewhat boring i must admit) adventure and started from the article <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&amp;productId=2&amp;postId=12765">&#8220;Easily compile resource bundles using Ant&#8221;</a> which i improved a little here and there (uses compc.jar and not flexTasks, dynamically composes the -include-resource-bundles argument etc&#8230;) and did get some gratification i&#8217;d like to share.</p>
<p><a href="http://compiler.kaustic.net/lab/wp-content/uploads/2009/08/localisedresourcebundlecompiler.zip">Thou can download the project here.</a></p>
<p><strong>Configuration</strong>:<br />
- edit build.xml and change the FLEX_HOME property if needed<br />
- that&#8217;s it&#8230; the rest is automagically done for you&#8230; no locales or bundles to specify&#8230;</p>
<p><strong>Workflow</strong>:</p>
<p>Explode existing resource bundles<br />
- place .swc files under /src/main/resources/locale/{locale}/..<br />
- run ANT build script, target &#8220;explode-overwrite&#8221;</p>
<p>Compile resource bundles to swc or swf<br />
- place .properties files under /src/main/locale/{locale}/{bundle}/..<br />
- run ANT build script, target &#8220;compile-swc&#8221; (default) or target &#8220;compile-swf&#8221; (for runtime resource loading)</p>
<p><strong>Example</strong>:<br />
- copy the SDK compiled resource bundles under /src/main/resources/locale/en_US<br />
- run the &#8220;explore-overwrite&#8221; target<br />
- adapt the files under /src/main/locale/en_US to your liking + rename the en_US folder to your locale<br />
- run the &#8220;compile-swc&#8221; target</p>
<p>Et <em>voilà</em>! Happy multilingual times <em>verdekke nondedju</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://compiler.kaustic.net/lab/?feed=rss2&amp;p=46</wfw:commentRss>
		</item>
	</channel>
</rss>

