<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JActionScripters &#187; Tutorial</title>
	<atom:link href="http://blog.jactionscripters.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jactionscripters.com</link>
	<description>More than 20 Japanese flash coders share the blog/ You will be junkie for this crazy Japanese Flash news</description>
	<lastBuildDate>Sat, 08 Oct 2011 16:55:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flash Player 11 adds new methods of the Matrix3D class to copy elements</title>
		<link>http://blog.jactionscripters.com/2011/10/09/flash-player-11-adds-new-methods-of-the-matrix3d-class-to-copy-elements/</link>
		<comments>http://blog.jactionscripters.com/2011/10/09/flash-player-11-adds-new-methods-of-the-matrix3d-class-to-copy-elements/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 16:55:34 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1544</guid>
		<description><![CDATA[Flash Player 11 and AIR 3.0 adds new methods of the Matrix3D class to copy elements between a Matrix3D object and Matrix3D, Vector3D or Vector objects.  A Matrix3D object represents a square matrix of order 4 to transform coordinates in 3D.[*1]
The four methods in the table below copy elements of a row or column [...]]]></description>
			<content:encoded><![CDATA[<p>Flash Player 11 and AIR 3.0 adds new methods of the Matrix3D class to copy elements between a Matrix3D object and Matrix3D, Vector3D or Vector objects.  A Matrix3D object represents a <a href="http://en.wikipedia.org/wiki/Square_matrix#Square_matrices" target="_blank">square matrix</a> of order 4 to transform coordinates in 3D.<sup>[*1]</sup></p>
<div id="attachment_1547" class="wp-caption alignnone" style="width: 310px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2011/10/Matrix3Delements-e.gif" alt="Representation of Matrix3D elements" title="Representation of Matrix3D elements" width="300" height="200" class="alignnone size-full wp-image-1547" /><p class="wp-caption-text">A Matrix3D object represents a square matrix of order 4.</p></div>
<p>The four methods in the table below copy elements of a row or column between the referenced Matrix3D ooject and the Vector3D object of its argument.</p>
<table border="1" cellspacing="0" bordercolor="#9999FF">
<tr>
<td bgcolor="#CCCCFF">
<strong>Target</strong>
</td>
<td bgcolor="#CCCCFF">
      <strong>Method of Matrix3D class</strong>
</td>
<td bgcolor="#CCCCFF">
      <strong>Direction</strong>
</td>
</tr>
<tr>
<td rowspan="2" align="center" bgcolor="#EEEEFF">
Column
</td>
<td bgcolor="#EEEEFF">
<strong>copyColumnFrom()</strong>
</td>
<td>
Vector3D -> Matrix3D
</td>
</tr>
<tr>
<td bgcolor="#EEEEFF">
  <strong>copyColumnTo()</strong>
</td>
<td>
Matrix3D -> Vector3D
</td>
</tr>
<tr>
<td rowspan="2" align="center" bgcolor="#EEEEFF">
Row
</td>
<td bgcolor="#EEEEFF">
<strong>copyRowFrom()</strong>
</td>
<td>
Vector3D -> Matrix3D
</td>
</tr>
<tr>
<td bgcolor="#EEEEFF">
  <strong>copyRowTo()</strong>
</td>
<td>
Matrix3D -> Vector3D
</td>
</tr>
</table>
<p><a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix3D.html#rawData" target="_blank"><em>Matrix3D.rawData</em> property</a> reads or writes 16 elements of a Matrix3D object, which are stored in a Vector object with Number base type.  The two methods in the table below can copy all 16 elements between the referenced Matrix3D object and the Vector object of its argument.  A Vector object of the Matrix3D.rawData property stores elements of a matrix column-by-column.<sup>[*2]</sup></p>
<table border="1" cellspacing="0" bordercolor="#9999FF">
<tr>
<td bgcolor="#CCCCFF">
    <strong>Method of Matrix3D class</strong>
</td>
<td bgcolor="#CCCCFF">
      <strong>Direction</strong>
</td>
</tr>
<tr>
<td bgcolor="#EEEEFF">
  <strong>copyRawDataFrom()</strong>
</td>
<td>
Vector -> Matrix3D
</td>
</tr>
<tr>
<td bgcolor="#EEEEFF">
  <strong>copyRawDataTo()</strong>
</td>
<td>
Matrix3D -> Vector
</td>
</tr>
</table>
<p>The <em>Matrix3D.copyFrom()</em> method copies elements between the referenced Matrix3D object and the other one of it argument.  It does not create new Matrix3D object unlike the Matrix3D.clone() method.  As it can use existing Matrix3D object, it consume less memory and can avoid the garbage collection.</p>
<hr />
<p>[*1] [<a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix3D.html" target="_blank">Matrix3D</a>] of the [Help] shows the figure below with the following description:</p>
<blockquote>
<p>The Matrix3D class uses a 4&#215;4 square matrix: a table of four rows and columns of numbers that hold the data for the transformation. The first three rows of the matrix hold data for each 3D axis (x,y,z). The translation information is in the last column. The orientation and scaling data are in the first three columns. The scaling factors are the diagonal numbers in the first three columns. Here is a representation of Matrix3D elements:</p>
<p><img src="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/images/Matrix3Delements.jpg" alt="Representation of Matrix3D elements in the Help" title="Representation of Matrix3D elements in the Help" width="300" height="246" class="alignnone size-full wp-image-1547" /></p></blockquote>
<p>But the positions of &#8220;x-axis&#8221;, &#8220;y-axis&#8221; and &#8220;z-axis&#8221; are not match to the statement that &#8220;The <strong>first three rows</strong> of the matrix hold data for each 3D axis (x,y,z)&#8221;.  Therefore, the figure inserted in the body text is modified to place them to the correct positions.</p>
<p>[*2] The [Help] describes a Vector object of the Matrix3D.rawData as follows:</p>
<blockquote><p>A Vector of 16 Numbers, where every four elements can be a row or a column of a 4&#215;4 matrix.</p></blockquote>
<p>However every four elements is a COLUMN of a 4&#215;4 matrix as described in the body text.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/10/09/flash-player-11-adds-new-methods-of-the-matrix3d-class-to-copy-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating coordinates to rotate</title>
		<link>http://blog.jactionscripters.com/2011/09/22/calculating-coordinates-to-rotate/</link>
		<comments>http://blog.jactionscripters.com/2011/09/22/calculating-coordinates-to-rotate/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 05:42:19 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1479</guid>
		<description><![CDATA[There are two formulas to calculate coordinates (x, y) with trigonometric functions by specifying angle ø.  The first is &#8220;polar coordinates&#8221; defined with a radius, distance r from the origin (0, 0), and an angle ø between the x axis.
[1] polar: radius r from the origin (0, 0) and angle ø between the x [...]]]></description>
			<content:encoded><![CDATA[<p>There are two formulas to calculate coordinates (x, y) with trigonometric functions by specifying angle ø.  The first is &#8220;polar coordinates&#8221; defined with a radius, distance r from the origin (0, 0), and an angle ø between the x axis.</p>
<p>[1] polar: radius r from the origin (0, 0) and angle ø between the x axis.</p>
<blockquote><p>x: r cosø<br />
y: r sinø</p></blockquote>
</ul>
<p><img src="http://blog.jactionscripters.com/wp-content/uploads/2011/09/ActionScript30for3D_M01_006.gif" alt="ActionScript30for3D_M01_006" title="ActionScript30for3D_M01_006" width="236" height="239" class="alignnone size-full wp-image-1482" /></p>
<p>The following code places a MovieClip instance <em>my_mc</em> at the point of which the radius is <em>radius</em> and the angle is <em>radians</em>.</p>
<p><code-style></p>
<pre name="code" class="as3">my_mc.x = radius * Math.cos(radians);
my_mc.y = radius * Math.sin(radians);</pre>
<p></code></p>
<p>The second is the formula of transforming coordinates (x, y), which rotates the point around the origin (0, 0) by angle ø.</p>
<p>[2] transform: rotating point (x, y) around the origin (0, 0) by angle ø.</p>
<blockquote><p>x: x cosø &#8211; y sinø<br />
y: x sinø + y cosø</p></blockquote>
<p>The following code rotates a MovieClip instance <em>my_mc</em> around the origin of the parent instance by angle <em>theta</em>.</p>
<p><code-style></p>
<pre name="code" class="as3">var nSin:Number = Math.sin(theta);
var nCos:Number = Math.cos(theta);
var nX:Number = my_mc.x;
var nY:Number = my_mc.y;
my_mc.x = nCos * nX - nSin * nY;
my_mc.y = nSin * nX + nCos * nY;</pre>
<p></code></p>
<p>Formula [2] is superior to [1] to rotate many instances around the origin by the same angle.  The Math.sin() and Math.cos() methods should not be called every time to rotate instances because the angle remains the same.</p>
<p><code-style></p>
<pre name="code" class="as3">var nSin:Number = Math.sin(theta);
var nCos:Number = Math.cos(theta);
//
for (var i:uint = 0; i < count; i++) {
	// get reference of my_mc
	var nX:Number = my_mc.x;
	var nY:Number = my_mc.y;
	my_mc.x = nCos * nX - nSin * nY;
	my_mc.y = nSin * nX + nCos * nY;
}</pre>
<p></code></p>
<p>See the wonderfl test code to compare two ways.</p>
<p><script type="text/javascript" src="http://wonderfl.net/blogparts/nw2f/js"></script>
<p class="ttlBpWonderfl" style="width: 465px; margin: 0; text-align: right; font-size: 11px;"><a href="http://wonderfl.net/c/nw2f" title="Calculating coordinates to rotate">Calculating coordinates to rotate - wonderfl build flash online</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/09/22/calculating-coordinates-to-rotate/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comparing Graphics.drawPath() method with traditional Graphics API</title>
		<link>http://blog.jactionscripters.com/2011/09/13/comparing-graphics-drawpath-method-with-traditional-graphics-api/</link>
		<comments>http://blog.jactionscripters.com/2011/09/13/comparing-graphics-drawpath-method-with-traditional-graphics-api/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 15:37:01 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1453</guid>
		<description><![CDATA[According to the explanation of the [Help] Graphics.drawPath() method is faster than the  traditional Graphics API.
Generally, drawings render faster with drawPath() than with a series of individual lineTo() and curveTo() methods.
However, as long as I tested and compared these methods, any significant differences were not found.
[Drawing API] of the [Help] shows an example code [...]]]></description>
			<content:encoded><![CDATA[<p>According to the explanation of the [Help] <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#drawPath()" target="_blank">Graphics.drawPath() method</a> is faster than the  traditional Graphics API.</p>
<blockquote><p>Generally, drawings render faster with drawPath() than with a series of individual lineTo() and curveTo() methods.</p></blockquote>
<p>However, as long as I tested and compared these methods, any significant differences were not found.</p>
<p>[<a href="http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c3a0f5f19124318fc87b-7ffe.html">Drawing API</a>] of the [Help] shows an example code using the Graphics.drawPath() method, which runs faster than the Graphics.moveTo() and Graphics.lintTo() methods. But the coordinates to be passed to the methods are stored in a Vector object. The Vector object is directly specified to the Graphics.drawPath() method, while Graphics.moveTo() and Graphics.lintTo() methods have to take numbers out of the Vector object.</p>
<p>The best case to use Graphics.drawPath() method might be to draw the same shape to multiple instances. Once two Vector objects for the methods arguments are created they can be passed to the methods multiple times.  The test code is uploaded to wonderfl.</p>
<p><script type="text/javascript" src="http://wonderfl.net/blogparts/6yyr/js"></script>
<p class="ttlBpWonderfl" style="width: 465px; margin: 0; text-align: right; font-size: 11px;"><a href="http://wonderfl.net/c/6yyr" title="Comparing Graphics.drawPath() method with traditional Graphics API">Comparing Graphics.drawPath() method with traditional Graphics API &#8211; wonderfl build flash online</a></p>
<p>note: &#8220;<a href="http://www.flashandmath.com/howtos/pathalpha/index.html" target="_blank">AS3 graphics.drawPath versus moveTo, lineTo Methods &#8211; Preserving Transparency</a>&#8221; is introduced to the wonderfl post as a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/09/13/comparing-graphics-drawpath-method-with-traditional-graphics-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysterious class World in Flash CS5</title>
		<link>http://blog.jactionscripters.com/2011/07/30/mysterious-class-world-in-flash-cs5/</link>
		<comments>http://blog.jactionscripters.com/2011/07/30/mysterious-class-world-in-flash-cs5/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 06:51:52 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1430</guid>
		<description><![CDATA[Create a new FLA file in Flash Professional CS5 and write the following frame action:

var test:World = new World();

[Test Movie] generates the compile error #1136:
Incorrect number of arguments. Expected 2.
I have never defined the class World but tried to solve the errors by adding several functions as follows:

var test:World = new World(this, this);
function createWorld() {}
function [...]]]></description>
			<content:encoded><![CDATA[<p>Create a new FLA file in Flash Professional <strong>CS5</strong> and write the following frame action:</p>
<p><code-style></p>
<pre name="code" class="as3">var test:World = new World();</pre>
<p></code></p>
<p>[Test Movie] generates the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/compilerErrors.html#1136" target="_blank">compile error #1136</a>:</p>
<blockquote><p>Incorrect number of arguments. Expected 2.</p></blockquote>
<p>I have never defined the class World but tried to solve the errors by adding several functions as follows:</p>
<p><code-style></p>
<pre name="code" class="as3">var test:World = new World(this, this);
function createWorld() {}
function getStepSize(temp) {}
function setStepSize(temp, temp2) {}
trace(test);  // Output: [object World]</pre>
<p></code></p>
<p>Both Flash CS4 porfessional and Flash Professional CS5.5 don&#8217;t have such class, &#8220;World&#8221;.  I suspect Adobe left the unnecessary class in CS5 by mistake.  You have to be careful if you define the class named &#8220;World&#8221; in CS5.</p>
<p>[postscript: 2011/09/23]<br />
According to the comments below and the blog article &#8220;<a href="http://heftybyte.com/flash/flash-cs5-physics/" target="_blank">Flash CS5 Built-in Physics Discovered</a>&#8220;, the class World is a part of physics engine in the inverse Inverse Kinematics framework.  And once the API was planned to release with the &#8220;Physics&#8221; panel but was abandoned by Adobe.</p>
<p>Based on the blog the following code was written to test the library:</p>
<p><code-style></p>
<pre name="code" class="as3">const COUNT:uint = 50;
var instances:Vector.&lt;Shape&gt; = drawShapes(COUNT);
var physics:PhysicsManager = new PhysicsManager(stage);
var myWorld:World = physics.createWorld();
assignPhysics();
myWorld.enableCollisions(true);
myWorld.setGravity(new Point(0, 200));
stage.addEventListener(MouseEvent.CLICK, startPhysics);
function startPhysics(eventObject:MouseEvent):void {
	addEventListener(Event.ENTER_FRAME, animatePhysics);
}
function assignPhysics():void {
	var myPoint:Point = new Point(1, 1);
	for (var i:uint = 0; i &lt; COUNT; i++) {
		var instance:DisplayObject = instances[i];
		var physicsObject:PhysObj = myWorld.addPhysObj(instance, myPoint, 0, false);
		if (i % 2) {
			physicsObject.setNonMoving(true);
		}
	}
}
function animatePhysics(eventObject:Event):void {
	myWorld.updateAllObjects();
	myWorld.step();
}
function drawShapes(count:uint):Vector.&lt;Shape&gt; {
	var nStageWidth:int = stage.stageWidth;
	var nStageHeight:int = stage.stageHeight;
	var nWidth:Number = 25;
	var nHeight:Number = 5;
	var instances:Vector.&lt;Shape&gt; = new Vector.&lt;Shape&gt;(count);
	for (var i:uint = 0; i &lt; count; i++) {
		var myShape:Shape = new Shape();
		var myGraphics:Graphics = myShape.graphics;
		myGraphics.beginFill(uint(0xFFFFFF * Math.random()));
		myGraphics.drawRect(-nWidth / 2, -nHeight / 2, nWidth, nHeight);
		myGraphics.endFill();
		addChild(myShape);
		instances[i] = myShape;
		myShape.x = nStageWidth * Math.random();
		myShape.y = nStageHeight * Math.random();
		myShape.rotation = 360 * Math.random();
	}
	return instances;
}</pre>
<p></code></p>
<p>Just copy the whole code and paste it into the first frame of  the main timeline in Flash Professional CS5.  Then do [Test Movie] and click on the stage.  A half of instances randomly placed will fall down.</p>
<div id="attachment_1537" class="wp-caption alignnone" style="width: 250px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2011/07/FF1109231_001.gif" alt="Instances are randomly placed on the stage" title="Testing the physics engine" width="240" height="180" class="size-full wp-image-1537" /><p class="wp-caption-text">Instances are randomly placed on the stage</p></div>
<div id="attachment_1537" class="wp-caption alignnone" style="width: 250px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2011/07/FF1109231_003.gif" alt="Click on the stage and a half of Instances fall down" title="Test the physics engine 2" width="240" height="180" class="alignnone size-full wp-image-1538" /><p class="wp-caption-text">Click on the stage and a half of Instances fall down</p></div>
<div id="attachment_1541" class="wp-caption alignnone" style="width: 535px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2011/07/FF1109231_004.gif" alt="Flash Professional CS5 includes the PffLib.swc library file in the application folder" title="PffLib.swc in Flash CS 5" width="525" height="275" class="size-full wp-image-1541" /><p class="wp-caption-text">Flash Professional CS5 includes the PffLib.swc library file in the application holder</p></div>
<p>The API of the physics engine is stored in the application folder of Flash CS5, Adobe Flash CS5/Common/Configuration/ActionScript 3.0/libs.  You may use the file in CS5.5 as well by adding its folder path to the [<a href="http://help.adobe.com/en_US/flash/cs/using/WS3e7c64e37a1d85e1e229110db38dec34-7fa4a.html#WSFE27EB8F-735F-423e-BF7A-56E47357EBD8" target="_blank">Library path</a>] in the [Advanced ActionScript 3.0 Settings].</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/07/30/mysterious-class-world-in-flash-cs5/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>When to use the ?: conditional operator</title>
		<link>http://blog.jactionscripters.com/2011/02/09/when-to-use-the-conditional-operator/</link>
		<comments>http://blog.jactionscripters.com/2011/02/09/when-to-use-the-conditional-operator/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 19:13:37 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1396</guid>
		<description><![CDATA[The conditional operator ?: is used to select an alternative value to be assigned.  It is basically faster than the if statement.

myVariable = (condition) ? valueA : valueB;



if (condition) {
	myVariable = valueA;
} else {
	myVariable = valueB;
}

However if the value selected by the conditional operator is to be added with the addition assignment operator +=, [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/operators.html#conditional" target="_blank">conditional operator <em>?:</em></a> is used to select an alternative value to be assigned.  It is <a href="http://wonderfl.net/c/noWZ" target="_blank">basically faster</a> than the <em>if</em> statement.</p>
<p><code-style></p>
<pre name="code" class="as3">myVariable = (condition) ? valueA : valueB;
</pre>
<p></code></p>
<p><code-style></p>
<pre name="code" class="as3">if (condition) {
	myVariable = valueA;
} else {
	myVariable = valueB;
}</pre>
<p></code></p>
<p>However if the value selected by the conditional operator is to be added with the addition assignment operator <em>+=</em>, its operation will come to be slow.</p>
<p><code-style></p>
<pre name="code" class="as3">myVariable += (condition) ? valueA : valueB;</pre>
<p></code></p>
<p>Using the assignment operator <em>=</em> instead makes it a little faster.</p>
<p><code-style></p>
<pre name="code" class="as3">myVariable = (condition) ? myVariable + valueA : myVariable + valueB;</pre>
<p></code></p>
<p>But in this case, the <a href="http://wonderfl.net/c/yXKm" target="_blank"><em>if</em> statement is better</a> to use.</p>
<p><code-style></p>
<pre name="code" class="as3">if (condition) {
	myVariable += valueA;
} else {
	myVariable += valueB;
}</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/02/09/when-to-use-the-conditional-operator/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Merging two arrays</title>
		<link>http://blog.jactionscripters.com/2011/01/12/merging-two-arrays/</link>
		<comments>http://blog.jactionscripters.com/2011/01/12/merging-two-arrays/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 13:05:36 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1379</guid>
		<description><![CDATA[Grant Skinner (@gskinner) tweeted a handy trick for merging two arrays in JavaScript.  This can be utilized in ActionScript 3.0 as well.

arr1.push.apply(arr1, arr2);

@gskinner:
Advantage of previous trick vs concat: doesn&#8217;t have the cost of constructing a new array.
I tried to compare speed of this technique with the Array.concat() method&#8217;s.  The results of the first [...]]]></description>
			<content:encoded><![CDATA[<p>Grant Skinner (<a href="http://twitter.com/#!/gskinner" target="_blank">@gskinner</a>) tweeted <a href="http://twitter.com/#!/gskinner/status/24695778207338496" target="_blank">a handy trick</a> for merging two arrays in JavaScript.  This can be utilized in ActionScript 3.0 as well.</p>
<p><code-style></p>
<pre name="code" class="as3">arr1.push.apply(arr1, arr2);</pre>
<p></code></p>
<blockquote><p><a href="http://twitter.com/#!/gskinner/status/24705793982988288" target="_blank">@gskinner</a>:<br />
Advantage of previous trick vs concat: doesn&#8217;t have the cost of constructing a new array.</p></blockquote>
<p>I tried to compare speed of this technique with the <em>Array.concat()</em> method&#8217;s.  The results of <a href="http://wonderfl.net/c/wGXS" target="_blank">the first code</a> posted to wonderfl were varied.  In the code the number of elements in both of source and joined arrays are 300.</p>
<p><a href="http://wonderfl.net/c/sdP4" target="_blank">The second code</a> joins 100 elements arrays to 10000 elements of source.  Then the trick with <em>Function.apply()</em> and <em>Array.push()</em> methods is faster than <em>Array.concat()</em>.  But <a href="http://wonderfl.net/c/12Jz" target="_blank">the third code</a>&#8217;s results are opposite.  It merges additional arrays containing 10000 elements with source arrays containing 100 elements.</p>
<p>From these results referencing an Array instance with <em>Function.apply()</em> method seems to be faster but adding elements with <em>Array.push()</em> method might be slower than <em>Array.concat()</em> method.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2011/01/12/merging-two-arrays/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Correction of a sample code in &#8220;Using the Text Layout Framework&#8221; of the CS5 help</title>
		<link>http://blog.jactionscripters.com/2010/06/02/correction-of-a-sample-code-in-using-the-text-layout-framework-of-the-cs5-help/</link>
		<comments>http://blog.jactionscripters.com/2010/06/02/correction-of-a-sample-code-in-using-the-text-layout-framework-of-the-cs5-help/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 07:18:45 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1325</guid>
		<description><![CDATA[&#8220;Using the Text Layout Framework&#8221; in &#8220;ActionScript 3.0 Developer&#8217;s Guide&#8221; on the Flash CS5 help includes some example codes to show how to use the Text Layout Framework. However, the second example in the section &#8220;The Text Layout Framework View&#8221; yields errors. The following two corrections should be made.
First, insert the xmlns attribute into the [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<a href="http://help.adobe.com/en_US/as3/dev/WSb2ba3b1aad8a27b0-1b8898a412218ad3df9-8000.html" target="_blank">Using the Text Layout Framework</a>&#8221; in &#8220;ActionScript 3.0 Developer&#8217;s Guide&#8221; on the Flash CS5 help includes some example codes to show how to use the Text Layout Framework. However, <a href="http://help.adobe.com/en_US/as3/dev/WS14c3067b34b57c6d4a97343b122ab36a52f-7ff4.html#WS14c3067b34b57c6d4a97343b122ab36a52f-7ff2" target="_blank">the second example</a> in the section &#8220;<a href="http://help.adobe.com/en_US/as3/dev/WS14c3067b34b57c6d4a97343b122ab36a52f-7ff4.html" target="_blank">The Text Layout Framework View</a>&#8221; yields errors. The following two corrections should be made.</p>
<p>First, insert the xmlns attribute into the Flow element of the XML data (markup).</p>
<blockquote><p><font color="#999999">// var markup:XML = &lt;TextFlow&gt;&lt;p&gt;&lt;span&gt;Hello, World&lt;/span&gt;&lt;/p&gt;&lt;/TextFlow&gt;;</font><br />
var markup:XML = &lt;TextFlow <font color="#0000FF"><strong>xmlns=&#8217;http://ns.adobe.com/textLayout/2008&#8242;</strong></font>&gt;&lt;p&gt;&lt;span&gt;Hello, World&lt;/span&gt;&lt;/p&gt;&lt;/TextFlow&gt;;
</p></blockquote>
<p>Second, the method updateAllContainers() is not implemented in the IFlowComposer interface.  Use the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/compose/IFlowComposer.html?filter_flash=cs5&#038;filter_flashplayer=10.1&#038;filter_air=2#updateAllControllers()" target="_blank"><em>updateAllControllers()</em> method</a> instead.</p>
<blockquote><p><font color="#999999">// myFlow.flowComposer.updateAllContainers();</font><br />
myFlow.flowComposer.<strong><font color="#0000FF">updateAllControllers</font></strong>();</p></blockquote>
<p>The corrected frame action below works and shows the text in the top left corner of the stage.</p>
<p><code-style></p>
<pre name="code" class="as3">// import necessary classes
import flashx.textLayout.container.*;
import flashx.textLayout.compose.*;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;

// first, create a TextFlow instance named myFlow
// var markup:XML = &lt;TextFlow&gt;&lt;p&gt;&lt;span&gt;Hello, World&lt;/span&gt;&lt;/p&gt;&lt;/TextFlow&gt;;
var markup:XML = &lt;TextFlow xmlns='http://ns.adobe.com/textLayout/2008'&gt;&lt;p&gt;&lt;span&gt;Hello, World&lt;/span&gt;&lt;/p&gt;&lt;/TextFlow&gt;;
var myFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);

// second, create a controller
// the first parameter, this, must point to a DisplayObjectContainer
// the last two parameters set the initial size of the container in pixels
var contr:ContainerController = new ContainerController(this, 600, 600);

// third, associate it with the flowComposer property
myFlow.flowComposer.addController(contr);

// fourth, update the display list ;
// myFlow.flowComposer.updateAllContainers();
myFlow.flowComposer.updateAllControllers();</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/06/02/correction-of-a-sample-code-in-using-the-text-layout-framework-of-the-cs5-help/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a class in flashx.textLayout package prevents the constructor from accessing Stage</title>
		<link>http://blog.jactionscripters.com/2010/05/22/using-a-class-in-flashx-textlayout-package-prevents-the-constructor-from-accessing-stage/</link>
		<comments>http://blog.jactionscripters.com/2010/05/22/using-a-class-in-flashx-textlayout-package-prevents-the-constructor-from-accessing-stage/#comments</comments>
		<pubDate>Sat, 22 May 2010 08:41:33 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1289</guid>
		<description><![CDATA[&#8220;Text Layout Framework example: News layout&#8221; in the [Help] yields the run-time error #1009.  Because using a class in flashx.textLayout package prevents the constructor from accessing the Stage instance.
Note: The code has already been fixed. But it is good to know how to access the Stage object when classes in flashx.textLayout package are used. [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;<a href="http://help.adobe.com/en_US/as3/dev/WS14c3067b34b57c6d4a97343b122ab36a52f-7fed.html" target="_blank">Text Layout Framework example: News layout</a>&#8221; in the [Help] yields the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/runtimeErrors.html#1009" target="_blank">run-time error #1009</a>.  Because using a class in flashx.textLayout package prevents the constructor from accessing the Stage instance.</p>
<p><strong>Note</strong>: The code has already been fixed. But it is good to know how to access the Stage object when classes in flashx.textLayout package are used. (2010/06/20)</p>
<p>As the test script below shows, the Stage object is available after the <a href="http://help.adobe.com/ja_JP/Flash/CS5/AS3LR/flash/display/DisplayObject.html#event:addedToStage" target="_blank">DisplayObject.addedToStage event</a>, which is dispatched twice.</p>
<p><code-style></p>
<pre name="code" class="as3">package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flashx.textLayout.elements.TextFlow;
	public class TextLayoutFormatTest extends Sprite {
		public function TextLayoutFormatTest() {
			var my_fmt:TextFlow;
			trace("constructor", stage, parent);
			addEventListener(Event.ADDED_TO_STAGE, onAdded);
		}
		private function onAdded(eventObject:Event):void {
			trace(stage, parent);
		}
	}
}</pre>
<p></code></p>
<blockquote><p>// [Output]:<br />
constructor null null<br />
[object Stage] [object Loader]<br />
[object Stage] [object Stage]</p></blockquote>
<p>As for the prior example in the [Help], TLFNewsLayout class, the statements in the constructor should be moved into a listener method of the <em>DisplayObject.addedToStage</em> event as follows:</p>
<p><code-style></p>
<pre name="code" class="as3">package {
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Rectangle;

	import flashx.textLayout.compose.StandardFlowComposer;
	import flashx.textLayout.container.ContainerController;
	import flashx.textLayout.container.ScrollPolicy;
	import flashx.textLayout.conversion.TextConverter;
	import flashx.textLayout.elements.TextFlow;
	import flashx.textLayout.formats.TextLayoutFormat;

	public class TLFNewsLayout extends Sprite {
		private var hTextFlow:TextFlow;
		private var headContainer:Sprite;
		private var headlineController:ContainerController;
		private var hContainerFormat:TextLayoutFormat;

		private var bTextFlow:TextFlow;
		private var bodyTextContainer:Sprite;
		private var bodyController:ContainerController;
		private var bodyTextContainerFormat:TextLayoutFormat;

		private const headlineMarkup:String = "<flow:TextFlow xmlns:flow='http://ns.adobe.com/textLayout/2008'><flow:p textAlign='center'><flow:span fontFamily='Helvetica' fontSize='18'>TLF News Layout Example</flow:span><flow:br/><flow:span fontFamily='Helvetica' fontSize='14'>This example formats text like a newspaper page with a headline, a subtitle, and multiple columns</flow:span></flow:p></flow:TextFlow>";

		private const bodyMarkup:String = "<flow:TextFlow xmlns:flow='http://ns.adobe.com/textLayout/2008' fontSize='12' textIndent='10' marginBottom='15' paddingTop='4' paddingLeft='4'><flow:p marginBottom='inherit'><flow:span>There are many </flow:span><flow:span fontStyle='italic'>such</flow:span><flow:span> lime-kilns in that tract of country, for the purpose of burning the white marble which composes a large part of the substance of the hills. Some of them, built years ago, and long deserted, with weeds growing in the vacant round of the interior, which is open to the sky, and grass and wild-flowers rooting themselves into the chinks of the stones, look already like relics of antiquity, and may yet be overspread with the lichens of centuries to come. Others, where the lime-burner still feeds his daily and nightlong fire, afford points of interest to the wanderer among the hills, who seats himself on a log of wood or a fragment of marble, to hold a chat with the solitary man. It is a lonesome, and, when the character is inclined to thought, may be an intensely thoughtful occupation; as it proved in the case of Ethan Brand, who had mused to such strange purpose, in days gone by, while the fire in this very kiln was burning.</flow:span></flow:p><flow:p marginBottom='inherit'><flow:span>The man who now watched the fire was of a different order, and troubled himself with no thoughts save the very few that were requisite to his business. At frequent intervals, he flung back the clashing weight of the iron door, and, turning his face from the insufferable glare, thrust in huge logs of oak, or stirred the immense brands with a long pole. Within the furnace were seen the curling and riotous flames, and the burning marble, almost molten with the intensity of heat; while without, the reflection of the fire quivered on the dark intricacy of the surrounding forest, and showed in the foreground a bright and ruddy little picture of the hut, the spring beside its door, the athletic and coal-begrimed figure of the lime-burner, and the half-frightened child, shrinking into the protection of his father's shadow. And when again the iron door was closed, then reappeared the tender light of the half-full moon, which vainly strove to trace out the indistinct shapes of the neighboring mountains; and, in the upper sky, there was a flitting congregation of clouds, still faintly tinged with the rosy sunset, though thus far down into the valley the sunshine had vanished long and long ago.</flow:span></flow:p></flow:TextFlow>";

		public function TLFNewsLayout() {
			addEventListener(Event.ADDED_TO_STAGE, initialize);
		}
		function initialize(eventObject:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, initialize);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;

			// Headline text flow and flow composer
			hTextFlow = TextConverter.importToFlow(headlineMarkup,TextConverter.TEXT_LAYOUT_FORMAT);
			hTextFlow.flowComposer = new StandardFlowComposer();

			// initialize the headline container and controller objects
			headContainer = new Sprite();
			headlineController = new ContainerController(headContainer);
			headlineController.verticalScrollPolicy = ScrollPolicy.OFF;
			hContainerFormat = new TextLayoutFormat();
			hContainerFormat.paddingTop = 4;
			hContainerFormat.paddingRight = 4;
			hContainerFormat.paddingBottom = 4;
			hContainerFormat.paddingLeft = 4;

			headlineController.format = hContainerFormat;
			hTextFlow.flowComposer.addController(headlineController);
			addChild(headContainer);
			stage.addEventListener(flash.events.Event.RESIZE, resizeHandler);

			// Body text TextFlow and flow composer
			bTextFlow = TextConverter.importToFlow(bodyMarkup,TextConverter.TEXT_LAYOUT_FORMAT);
			bTextFlow.flowComposer = new StandardFlowComposer();

			// The body text container is below, and has three columns
			bodyTextContainer = new Sprite();
			bodyController = new ContainerController(bodyTextContainer);
			bodyTextContainerFormat = new TextLayoutFormat();
			bodyTextContainerFormat.columnCount = 3;
			bodyTextContainerFormat.columnGap = 30;

			bodyController.format = bodyTextContainerFormat;
			bTextFlow.flowComposer.addController(bodyController);
			addChild(bodyTextContainer);
			resizeHandler(null);
		}

		private function resizeHandler(event:Event):void {
			const verticalGap:Number = 25;
			const stagePadding:Number = 16;
			var stageWidth:Number = stage.stageWidth - stagePadding;
			var stageHeight:Number = stage.stageHeight - stagePadding;
			var headlineWidth:Number = stageWidth;
			var headlineContainerHeight:Number = stageHeight;

			// Initial compose to get height of headline after resize
			headlineController.setCompositionSize(headlineWidth, headlineContainerHeight);
			hTextFlow.flowComposer.compose();
			var rect:Rectangle = headlineController.getContentBounds();
			headlineContainerHeight = rect.height;

			// Resize and place headline text container
			// Call setCompositionSize() again with updated headline height
			headlineController.setCompositionSize(headlineWidth, headlineContainerHeight );
			headlineController.container.x = stagePadding / 2;
			headlineController.container.y = stagePadding / 2;
			hTextFlow.flowComposer.updateAllControllers();

			// Resize and place body text container ;
			var bodyContainerHeight:Number = (stageHeight - verticalGap - headlineContainerHeight);
			bodyController.format = bodyTextContainerFormat;
			bodyController.setCompositionSize(stageWidth, bodyContainerHeight );
			bodyController.container.x = (stagePadding/2);
			bodyController.container.y = (stagePadding/2) + headlineContainerHeight + verticalGap;
			bTextFlow.flowComposer.updateAllControllers();
		}
	}
}</pre>
<p></code></p>
<div id="attachment_1319" class="wp-caption alignnone" style="width: 562px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2010/05/TLFNewsLayout.gif" alt="The result of the TLFNewsLayout class" title="TLFNewsLayout" width="552" height="402" class="size-full wp-image-1319" /><p class="wp-caption-text">The result of the TLFNewsLayout class</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/05/22/using-a-class-in-flashx-textlayout-package-prevents-the-constructor-from-accessing-stage/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Decrement versus Increment in Loop 2</title>
		<link>http://blog.jactionscripters.com/2010/05/01/decrement-versus-increment-in-loop-2/</link>
		<comments>http://blog.jactionscripters.com/2010/05/01/decrement-versus-increment-in-loop-2/#comments</comments>
		<pubDate>Sat, 01 May 2010 06:05:18 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1233</guid>
		<description><![CDATA[Adobe&#8217;s &#8220;Optimizing Performance for the Flash Platform&#8221; recommends that &#8220;Use reverse order for while loops&#8221; in its &#8220;Miscellaneous optimizations&#8221; section.  And in my last post, decrement was not explicitly faster than increment with the following code to compare them:


while (--i > -1)




while (++i < MAX_NUMBER)  // MAX_NUMBER is a constant


Difference was very little [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe&#8217;s &#8220;Optimizing Performance for the Flash Platform&#8221; recommends that &#8220;Use reverse order for while loops&#8221; in its &#8220;<a href="http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c3a0f5f19124318fc87b-7ffc.html" target="_blank">Miscellaneous optimizations</a>&#8221; section.  And in <a href="http://blog.jactionscripters.com/2010/04/12/decrement-versus-increment-in-loop/" target="_blank">my last post</a>, decrement was not explicitly faster than increment with <a href="http://wonderfl.net/c/pB5I" target="_blank">the following code</a> to compare them:</p>
<p><code-style></p>
<pre name="code" class="as3">
while (--i > -1)
</pre>
<p></code></p>
<p><code-style></p>
<pre name="code" class="as3">
while (++i < MAX_NUMBER)  // MAX_NUMBER is a constant
</pre>
<p></code></p>
<p>Difference was very little in my Mac OS environment. But in Internet Explorer 7 and Firefox 3/Flash Player 10/Windows Vista, decrement was faster up to twenty percent than increment.  After several trials, speed of operation between decrement and increment seems to be almost the same.  The condition of loop does not care if expression is decrement or increment.</p>
<p>The difference came from value to be compared with a counter variable. <a href="http://wonderfl.net/c/li9w" target="_blank">The new sample script</a> for increment below does not use a constant in the condition. Then its speed seems to be almost identical to the decrement's.</p>
<p><code-style></p>
<pre name="code" class="as3">
while (++i < &lt;the literal number&gt;)
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/05/01/decrement-versus-increment-in-loop-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Decrement versus Increment in Loop</title>
		<link>http://blog.jactionscripters.com/2010/04/12/decrement-versus-increment-in-loop/</link>
		<comments>http://blog.jactionscripters.com/2010/04/12/decrement-versus-increment-in-loop/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 02:28:21 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1198</guid>
		<description><![CDATA[Adobe&#8217;s &#8220;Optimizing Performance for the Flash Platform&#8221; recommends that &#8220;Use reverse order for while loops&#8221; in its &#8220;Miscellaneous optimizations&#8221; section.


while (--i > -1)


But according to my test significant difference could not be found between  decrement and increment.  In other language they said that decrement and increment are identical.
The pre-increment/decrement is a little faster [...]]]></description>
			<content:encoded><![CDATA[<p>Adobe&#8217;s &#8220;Optimizing Performance for the Flash Platform&#8221; recommends that &#8220;Use reverse order for while loops&#8221; in its &#8220;<a href="http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c3a0f5f19124318fc87b-7ffc.html" target="_blank">Miscellaneous optimizations</a>&#8221; section.</p>
<p><code-style></p>
<pre name="code" class="as3">
while (--i > -1)
</pre>
<p></code></p>
<p>But according to <a href="http://wonderfl.net/code/b367bc355256e499f86580359b5120053aa13c49" target="_blank">my test</a> significant difference could not be found between  decrement and increment.  In other language they said that <a href="http://social.msdn.microsoft.com/Forums/en-US/wptk_v4/thread/2e73042e-3ed4-4b16-a8e6-c3d5c350ff89" target="_blank">decrement and increment are identical</a>.</p>
<p>The pre-increment/decrement is a little faster than post, which is included in my test, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/04/12/decrement-versus-increment-in-loop/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Quaternion notation of Vector3D</title>
		<link>http://blog.jactionscripters.com/2010/04/02/quaternion-notation-of-vector3d/</link>
		<comments>http://blog.jactionscripters.com/2010/04/02/quaternion-notation-of-vector3d/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 09:30:52 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1135</guid>
		<description><![CDATA[The [Help] of the Vecror3D.w property mentions about the quaternion notation as follows:
Quaternion notation employs an angle as the fourth element in its calculation of three-dimensional rotation. The w property can be used to define the angle of rotation about the Vector3D object.
But this sounds like explanation of the axis angle (see Orientation3D .AXIS_ANGLE Constant). [...]]]></description>
			<content:encoded><![CDATA[<p>The [Help] of the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Vector3D.html#w" target="_blank">Vecror3D.w property</a> mentions about the quaternion notation as follows:</p>
<blockquote><p>Quaternion notation employs an angle as the fourth element in its calculation of three-dimensional rotation. The w property can be used to define the angle of rotation about the Vector3D object.</p></blockquote>
<p>But this sounds like explanation of the axis angle (see <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Orientation3D.html#AXIS_ANGLE" target="_blank">Orientation3D .AXIS_ANGLE Constant</a>).  The axis angle uses a combination of an axis and an angle to determine the rotation.  For an argument of the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#decompose()" target="_blank">Matrix3D.decompose()</a> or <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#recompose()" target="_blank">Matrix3D.recompose()</a> method Orientation3D.AXIS_ANGLE can be specified as the orientation style used for the matrix transformation.</p>
<p>Try to rotate a Matrix3D object 180 degrees (&pi;) around the axis (1/&radic;2, 1/&radic;2, 0).</p>
<p><img src="http://blog.jactionscripters.com/wp-content/uploads/2010/04/ActionScript30for3D_04_054.gif" alt="The axis of rotation" title="The axis of rotation" width="362" height="362" class="alignnone size-full wp-image-1145" /></p>
<p><code-style></p>
<pre name="code" class="as3">
var myMatrix3D:Matrix3D = new Matrix3D();
var axis:Vector3D = new Vector3D(Math.SQRT1_2, Math.SQRT1_2,0);
myMatrix3D.prependRotation(180, axis);
var axisAngle:Vector3D = myMatrix3D.decompose(Orientation3D.AXIS_ANGLE)[1];
trace(axisAngle, axisAngle.w);
</pre>
<p></code></p>
<p>The frame action above outputs as follows:</p>
<blockquote><p>Vector3D(0.7071067094802856, 0.7071068286895752, -2.339619844353034e-24) 3.1415927410125732
</p></blockquote>
<p>[Note]: 0.707&#8230; = 1/&radic;2 and 3.14&#8230; = &pi; radians = 180 degrees.</p>
<p>The (x, y, z) coordinates represents the axis and Vector3D.w property is an angle of the rotation.  This result seems to fit the explanation of the [Help] quoted above.</p>
<p>But the quaternion notation determine the rotation by the four value.  The following expression of the quaternion Q represents the rotation of &theta; around the vector U.</p>
<blockquote><p>U = (x, y, z) and |U| = 1<br />
Q = (cos(&theta;/2); sin(&theta;/2)U)
</p></blockquote>
<p>Then try to rotate a Matrix3D object 60 degrees around the y axis (0, 1, 0).</p>
<p><code-style></p>
<pre name="code" class="as3">
var myMatrix3D:Matrix3D = new Matrix3D();
myMatrix3D.prependRotation(60, Vector3D.Y_AXIS);
var quaternion:Vector3D = myMatrix3D.decompose(Orientation3D.QUATERNION)[1];
trace(quaternion.w, quaternion);
</pre>
<p></code></p>
<p> The frame action above outputs as follows:</p>
<blockquote><p>0.8660253882408142 Vector3D(0, 0.4999999701976776, 0)</p></blockquote>
<p>These numbers represent the quaternion of 60 degrees&#8217; rotation.</p>
<blockquote><p>0.866&#8230; = cos(60/2) = cos(30)<br />
(0, 0.5, 0) = sin(60/2) (0, 1, 0)</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/04/02/quaternion-notation-of-vector3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Return value of Matrix3D.recompose() method</title>
		<link>http://blog.jactionscripters.com/2010/03/05/return-value-of-matrix3d-recompose-method/</link>
		<comments>http://blog.jactionscripters.com/2010/03/05/return-value-of-matrix3d-recompose-method/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 16:38:34 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1108</guid>
		<description><![CDATA[The [Help] of the Matrix3D.recompose() method tells about its return value as follows:
Returns false if any of the scale elements are zero.
But this is not true.  Try the code below, in the 7th statement of which the third element, the z coordinate, of the scale Vector3D instance is set to zero.


var myMatrix3D:Matrix3D = new [...]]]></description>
			<content:encoded><![CDATA[<p>The [Help] of the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#recompose()"><em>Matrix3D.recompose()</em> method</a> tells about its return value as follows:</p>
<blockquote><p>Returns false if any of the scale elements are zero.</p></blockquote>
<p>But this is not true.  Try the code below, in the 7th statement of which the third element, the z coordinate, of the scale Vector3D instance is set to zero.</p>
<p><code-style></p>
<pre name="code" class="as3">
var myMatrix3D:Matrix3D = new Matrix3D();
trace(myMatrix3D.decompose());
// Output: Vector3D(0, 0, 0),Vector3D(0, 0, 0),Vector3D(1, 1, 1)
var myVector:Vector.&lt;Vector3D&gt; = new Vector.&lt;Vector3D&gt;();
myVector.push(new Vector3D());  // translation
myVector.push(new Vector3D());  // rotation
myVector.push(new Vector3D(1, 1, 0));  // scale
trace(myMatrix3D.recompose(myVector));
// Output: true
trace(myMatrix3D.decompose());
// Output: Vector3D(0, -1.9986319541931152, 0),Vector3D(-1.5707963705062866, NaN, 0),Vector3D(7.667765755019554e-19, -1.998608112335205, 1.9719639421382673e-19)
</pre>
<p></code></p>
<p>The method returns <em>true</em> as long as the argument of Vector instance has three Vector3D elements.  Therefore, the explanation in the [Help] should be rewritten as follows:</p>
<blockquote><p>Returns false if any of the Vector3D elements of the Vector instance as the argument don&#8217;t exist or are null.</p></blockquote>
<p><strong>Note</strong>: The coordinates of Vector3D elements come to be invalid values if any of the scale elements are zero.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/03/05/return-value-of-matrix3d-recompose-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculation in the Utils3D.projectVectors() method</title>
		<link>http://blog.jactionscripters.com/2010/02/01/calculation-in-the-utils3d-projectvectors-method/</link>
		<comments>http://blog.jactionscripters.com/2010/02/01/calculation-in-the-utils3d-projectvectors-method/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 23:11:06 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1073</guid>
		<description><![CDATA[The Utils3D.projectVectors() method projects a Vector of three-dimensional space coordinates to a Vector of two-dimensional space coordinates.  And the method also sets the t value of the uvt data.
The Utils3D.projectVectors() method calculates t value of the uvt data by the following formula:
t value = 1 / (Distance to the origin + z coordinate value)
Also, [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/geom/Utils3D.html#projectVectors()" target="_blank"><em>Utils3D.projectVectors()</em> method</a> projects a Vector of three-dimensional space coordinates to a Vector of two-dimensional space coordinates.  And the method also sets the t value of the uvt data.</p>
<div id="attachment_1078" class="wp-caption alignnone" style="width: 325px"><img src="http://blog.jactionscripters.com/wp-content/uploads/2010/02/Utils3D_projectVectors1.gif" alt="Calculation in the Utils3D.projectVectors() method" title="Utils3D.projectVectors() method" width="315" height="180" class="size-full wp-image-1078" /><p class="wp-caption-text">Values for the calculation in the Utils3D.projectVectors() method</p></div>
<p>The <em>Utils3D.projectVectors() </em>method calculates t value of the uvt data by the following formula:</p>
<blockquote><p>t value = 1 / (Distance to the origin + z coordinate value)</p></blockquote>
<p>Also, the method calculates projected x and y values by the following formula:</p>
<blockquote><p>Projected x or y value = Three-dimensional space x or y coordinate * Focal length * t value</p></blockquote>
<p>The frame action below compares the results of calculation by the formulas above with the methods&#8217;.  And [Output] is as follows:</p>
<blockquote><p>0,0,0.0004  // uvt data<br />
0.0004  // Calculated t value<br />
20,20  // Projected x and y coordinates<br />
20  // Calculated two-dimensional space x or y coordinate  </p></blockquote>
<p><code-style></p>
<pre name="code" class="as3">
var myPerspective:PerspectiveProjection = new PerspectiveProjection();
var myMatrix3D:Matrix3D = new Matrix3D();
var nDistance:Number = 1000;  // Distance to the origin
var nX:Number = 100;  // Three-dimensional space x or y coordinate
var nZ:Number = 1500;  // Three-dimensional z coordinate
var vertices3D:Vector.&lt;Number&gt; = Vector.&lt;Number&gt;([nX, nX, nZ]);
var vertices2D:Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;();
var uvtData:Vector.&lt;Number&gt; = Vector.&lt;Number&gt;([0, 0, 0]);
var nT:Number = 1/(nDistance + nZ);  // t value
myPerspective.focalLength = 500;  // Focal length 
myMatrix3D.appendTranslation(0, 0, nDistance);
myMatrix3D.append(myPerspective.toMatrix3D());
Utils3D.projectVectors(myMatrix3D, vertices3D, vertices2D, uvtData);
trace(uvtData);  // uvt data
trace(nT);  // Calculated t value
trace(vertices2D);  // Projected x and y coordinates
trace(nX * myPerspective.focalLength * nT);  // Calculated two-dimensional space x or y coordinate
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2010/02/01/calculation-in-the-utils3d-projectvectors-method/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rotating an instance with the y axis</title>
		<link>http://blog.jactionscripters.com/2009/12/05/rotating-an-instance-with-the-y-axis/</link>
		<comments>http://blog.jactionscripters.com/2009/12/05/rotating-an-instance-with-the-y-axis/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 13:33:10 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=1017</guid>
		<description><![CDATA[Try to rotate a MovieClip instance named my_mc 80 degrees with the y axis.  The trace() function in the code below displays information in the [Output] panel as follows: 
80.00003182368921 1.3962639570236206


var nRotationY:Number = 80;
my_mc.rotationY = 0;
var myMatrix3D:Matrix3D = my_mc.transform.matrix3D;
myMatrix3D.prependRotation(nRotationY, Vector3D.Y_AXIS);
trace(my_mc.rotationY, myMatrix3D.decompose()[1].y);



Then change the number of degrees in the variable, nRotationY, to 100. The code [...]]]></description>
			<content:encoded><![CDATA[<p>Try to rotate a MovieClip instance named my_mc 80 degrees with the y axis.  The trace() function in the code below displays information in the [Output] panel as follows: </p>
<blockquote><p>80.00003182368921 1.3962639570236206</p></blockquote>
<p><code-style></p>
<pre name="code" class="as3">
var nRotationY:Number = 80;
my_mc.rotationY = 0;
var myMatrix3D:Matrix3D = my_mc.transform.matrix3D;
myMatrix3D.prependRotation(nRotationY, Vector3D.Y_AXIS);
trace(my_mc.rotationY, myMatrix3D.decompose()[1].y);
</pre>
<p></code></p>
<p><img src="http://blog.jactionscripters.com/wp-content/uploads/2009/12/rotationTest_80.gif" alt="Rotating an instance 80 degrees" title="Rotating an instance 80 degrees" width="270" height="235" class="alignnone size-full wp-image-1023" /></p>
<p>Then change the number of degrees in the variable, nRotationY, to 100. The code seems to rotate an instance 100 degrees. However, the number of degrees shown in the [Output] panel is still 80.</p>
<blockquote><p>80.00003182368921 1.3962639570236206</p></blockquote>
<p><code-style></p>
<pre name="code" class="as3">
var nRotationY:Number = 100;  // 80;
my_mc.rotationY = 0;
var myMatrix3D:Matrix3D = my_mc.transform.matrix3D;
myMatrix3D.prependRotation(nRotationY, Vector3D.Y_AXIS);
trace(my_mc.rotationY, myMatrix3D.decompose()[1].y);
</pre>
<p></code></p>
<p><img src="http://blog.jactionscripters.com/wp-content/uploads/2009/12/rotationTest_100.gif" alt="Rotating an instance 100 degrees" title="Rotating an instance 100 degrees" width="270" height="235" class="alignnone size-full wp-image-1035" /></p>
<p>The following code reveals the reason.</p>
<blockquote><p>0 80.00003182368921 0<br />
Vector3D(0, 1.3962639570236206, 0)<br />
180.00000500895632 80.00003182368921 180.00000500895632<br />
Vector3D(3.1415927410125732, 1.3962639570236206, 3.1415927410125732)</p></blockquote>
<p><code-style></p>
<pre name="code" class="as3">
var mySprite:Sprite = new Sprite();
var axis:Vector3D = Vector3D.Y_AXIS;  // Vector3D.X_AXIS  // Try to change this
mySprite.rotationY = 0;
var myMatrix3D:Matrix3D = mySprite.transform.matrix3D;
myMatrix3D.prependRotation(80, axis);
xTrace(mySprite);
myMatrix3D.prependRotation(20, axis);
xTrace(mySprite);
function xTrace(targetSprite:Sprite):void {
	trace(targetSprite.rotationX, targetSprite.rotationY, targetSprite.rotationZ);
	trace(targetSprite.transform.matrix3D.decompose()[1]);
}
</pre>
<p></code></p>
<p>When the <em>Matrix3D.prependRotation()</em> method rotates an instance 100 degrees with y axis, it is only rotated 80 degrees but is flipped with x and z axes.</p>
<p>The appearance of the instance is all right. But the number of degrees is not good. Besides, 100 degrees can be set with x or z axis. It means that the result of y axis is not consistent. Therefore, I suspect that this is a bug.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2009/12/05/rotating-an-instance-with-the-y-axis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Three types of transformation objects in the Transform class</title>
		<link>http://blog.jactionscripters.com/2009/10/14/three-types-of-transformation-objects-in-the-transform-class/</link>
		<comments>http://blog.jactionscripters.com/2009/10/14/three-types-of-transformation-objects-in-the-transform-class/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 09:25:07 +0000</pubDate>
		<dc:creator>Fumio Nonaka</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.jactionscripters.com/?p=985</guid>
		<description><![CDATA[The Transform class has several kinds of transformation objects as its properties.
The Transform class provides access to color adjustment properties and two- or three-dimensional transformation objects that can be applied to a display object.
I noticed three types of properties from the point of view of getting and seting their values.
The first example is the Transform.matrix [...]]]></description>
			<content:encoded><![CDATA[<p>The Transform class has several kinds of transformation objects as its properties.</p>
<blockquote><p>The Transform class provides access to color adjustment properties and two- or three-dimensional transformation objects that can be applied to a display object.</p></blockquote>
<p>I noticed three types of properties from the point of view of getting and seting their values.</p>
<p>The first example is the <em>Transform.matrix</em> property.  It does not provide its Matrix object reference but its copy.  It means that operations to the copy will not affect to the property&#8217;s Matrix object.  To set a Matrix object to the <em>Transform.matrix</em> property, the object should be assigned to the property.</p>
<p><code-style></p>
<pre name="code" class="as3">var mySprite:Sprite = new Sprite();
var myMatrix:Matrix = new Matrix();
mySprite.transform.matrix = myMatrix;
myMatrix.translate(100, 50);
trace(mySprite.transform.matrix);
// Output: (a=1, b=0, c=0, d=1, tx=0, ty=0)
mySprite.transform.matrix = myMatrix;
trace(mySprite.transform.matrix);
// Output: (a=1, b=0, c=0, d=1, tx=100, ty=50)
myMatrix = mySprite.transform.matrix;
myMatrix.scale(2, 1.5);
trace(mySprite.transform.matrix);
// Output: (a=1, b=0, c=0, d=1, tx=100, ty=50)
trace(mySprite.transform.matrix == myMatrix);  // Output: false</pre>
<p></code></p>
<p>The second example is the <em>Transform.matrix3D</em> property.  Unlike to the <em>Transform.matrix</em> property, a Matrix3D object&#8217;s reference is obtained from the property.    Therefore, once its reference is gotten, operations to the reference affects to the <em>Transform.matrix3D</em> property.</p>
<p><code-style></p>
<pre name="code" class="as3">var mySprite:Sprite = new Sprite();
var myMatrix3D:Matrix3D = new Matrix3D();
mySprite.transform.matrix3D = myMatrix3D;
myMatrix3D.prependTranslation(100, 50, 0);
trace(mySprite.transform.matrix3D.position);
// Output: Vector3D(100, 50, 0)
trace(mySprite.transform.matrix3D == myMatrix3D);  // Output: true</pre>
<p></code></p>
<p>The third one is the <em>Transform.perspectiveProjection</em> property. When a new PerspectiveProjection instance is assigned to the property, operations to the instance do not affect to the property as well as the <em>Transform.matrix</em> property. Then, try to get the object from the property and set it to a variable again. You can operate the variable as if it was the object reference of the property. However the variable&#8217;s object is not evaluated to be equal to the property&#8217;s value. It is a mysterious property, isn&#8217;t it.</p>
<p><code-style></p>
<pre name="code" class="as3">var mySprite:Sprite = new Sprite();
var myPerspective:PerspectiveProjection = new PerspectiveProjection();
mySprite.transform.perspectiveProjection = myPerspective;
myPerspective.fieldOfView = 20;
trace(mySprite.transform.perspectiveProjection.fieldOfView);  // Output: 55
myPerspective = mySprite.transform.perspectiveProjection;
myPerspective.fieldOfView = 100;
trace(mySprite.transform.perspectiveProjection.fieldOfView);  // Output: 100
trace(mySprite.transform.perspectiveProjection == myPerspective);
// Output: false</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jactionscripters.com/2009/10/14/three-types-of-transformation-objects-in-the-transform-class/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

