<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The Type-Safety of Vectors</title>
	<atom:link href="http://jacksondunstan.com/articles/105/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/105</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:30:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/105/comment-page-1#comment-1004</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Fri, 22 Oct 2010 06:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=105#comment-1004</guid>
		<description>I fixed the formatting on your post. I should really see if there&#039;s a way I can improve the standard WordPress comment filter to allow better code posting...

Anyhow, &lt;code&gt;splice&lt;/code&gt; is working just like &lt;code&gt;push&lt;/code&gt; would work. It doesn&#039;t throw an &lt;code&gt;Error&lt;/code&gt;, but instead does as you say and converts the argument(s) to the &lt;code&gt;Vector&lt;/code&gt;&#039;s type. Consider this:

&lt;pre lang=&quot;actionscript3&quot;&gt;
var vec1:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();
vec1.push(Vector.&lt;Sprite&gt;([new Sprite, new Sprite, new Sprite]));
trace(vec1.length, vec1);
&lt;/pre&gt;

That also outputs &lt;code&gt;1 0&lt;/code&gt; because the pushed type (&lt;code&gt;Vector.&lt;Sprite&gt;&lt;/code&gt;) converts to the integer &lt;code&gt;0&lt;/code&gt;. This is totally contrary to Adobe&#039;s &lt;a href=&quot;http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html#push()&quot; rel=&quot;nofollow&quot;&gt;documentation&lt;/a&gt;, which states that an exception will be thrown.

You are also correct in that &lt;code&gt;splice&lt;/code&gt;&#039;s third argument does not do as the &lt;a href=&quot;http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html#splice()&quot; rel=&quot;nofollow&quot;&gt;documentation&lt;/a&gt; says as it doesn&#039;t add the elements of the passed &lt;code&gt;Vector&lt;/code&gt;, but rather converts like you showed. It&#039;s not even a case of a type mismatch, as in your example, as this results in the same output as your example:

&lt;pre lang=&quot;actionscript3&quot;&gt;
var vec1:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();
vec1.splice(0, 0, Vector.&lt;int&gt;([100, 200, 300]));
trace(vec1.length, vec1);
&lt;/pre&gt;

In summary, &lt;code&gt;Vector&lt;/code&gt; is still, as I stated in the article&#039;s conclusion, type-safe. It just doesn&#039;t behave as the documentation says it does and is therefore pretty strange to work with. Thanks for the insightful comments!</description>
		<content:encoded><![CDATA[<p>I fixed the formatting on your post. I should really see if there&#8217;s a way I can improve the standard WordPress comment filter to allow better code posting&#8230;</p>
<p>Anyhow, <code>splice</code> is working just like <code>push</code> would work. It doesn&#8217;t throw an <code>Error</code>, but instead does as you say and converts the argument(s) to the <code>Vector</code>&#8216;s type. Consider this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> vec1<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>Sprite<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">,</span> vec1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>That also outputs <code>1 0</code> because the pushed type (<code>Vector.<sprite></sprite></code>) converts to the integer <code>0</code>. This is totally contrary to Adobe&#8217;s <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html#push()" rel="nofollow">documentation</a>, which states that an exception will be thrown.</p>
<p>You are also correct in that <code>splice</code>&#8216;s third argument does not do as the <a href="http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html#splice()" rel="nofollow">documentation</a> says as it doesn&#8217;t add the elements of the passed <code>Vector</code>, but rather converts like you showed. It&#8217;s not even a case of a type mismatch, as in your example, as this results in the same output as your example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> vec1<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">,</span> vec1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>In summary, <code>Vector</code> is still, as I stated in the article&#8217;s conclusion, type-safe. It just doesn&#8217;t behave as the documentation says it does and is therefore pretty strange to work with. Thanks for the insightful comments!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skyboy</title>
		<link>http://jacksondunstan.com/articles/105/comment-page-1#comment-1003</link>
		<dc:creator>skyboy</dc:creator>
		<pubDate>Fri, 22 Oct 2010 05:34:25 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=105#comment-1003</guid>
		<description>Bah. HTML safety got me, the first vector is int, the second is Sprite; an easier way to prevent HTML-injection is to replace less-than with &lt;code&gt;&amp; lt ;&lt;/code&gt; and greater-than with &lt;code&gt;&amp; gt ;&lt;/code&gt; without spaces when it isn&#039;t an allowed tag; after &amp; is replaced with &lt;code&gt;&amp; amp ;&lt;/code&gt; of course.</description>
		<content:encoded><![CDATA[<p>Bah. HTML safety got me, the first vector is int, the second is Sprite; an easier way to prevent HTML-injection is to replace less-than with <code>&amp; lt ;</code> and greater-than with <code>&amp; gt ;</code> without spaces when it isn&#8217;t an allowed tag; after &amp; is replaced with <code>&amp; amp ;</code> of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skyboy</title>
		<link>http://jacksondunstan.com/articles/105/comment-page-1#comment-1002</link>
		<dc:creator>skyboy</dc:creator>
		<pubDate>Fri, 22 Oct 2010 05:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=105#comment-1002</guid>
		<description>&lt;pre lang=&quot;actionscript3&quot;&gt;
var vec1:Vector.&lt;int&gt; = new Vector.&lt;int&gt;();
var vec2:Vector.&lt;Sprite&gt; = Vector.&lt;Sprite&gt;([new Sprite, new Sprite, new Sprite]);
vec1.splice(0, 0, vec2);
trace(vec1.length, vec1);
&lt;/pre&gt;

What should this do?  Throw an error? Attempt to add the Sprites to the vector? Attempt to add the other vector to the vector?

It kind-of does the last one. It will trace &lt;code&gt;1 0&lt;/code&gt;.

According to the documentation you pass in var args or a vector of  objects to be spliced into it.
This is wrong. It takes var args, and nothing more, but it also does something weird. It converts everything to the type specified, even if it&#039;s unrelated.</description>
		<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> vec1<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>int<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> vec2<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>Sprite<span style="color: #000066; font-weight: bold;">&gt;</span> = Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>Sprite<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> vec2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>vec1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">,</span> vec1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>What should this do?  Throw an error? Attempt to add the Sprites to the vector? Attempt to add the other vector to the vector?</p>
<p>It kind-of does the last one. It will trace <code>1 0</code>.</p>
<p>According to the documentation you pass in var args or a vector of  objects to be spliced into it.<br />
This is wrong. It takes var args, and nothing more, but it also does something weird. It converts everything to the type specified, even if it&#8217;s unrelated.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

