<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="css/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Chen Sheng - 敲打代码</title><link>http://chensheng.net/</link><description>chensheng.net  - </description><generator>RainbowSoft Studio Z-Blog 1.8 Arwen Build 81206</generator><language>zh-CN</language><copyright>Copyright 2000-2008 @ chensheng.net.(qq:99479) All Rights Reserved.浙ICP备09092413号 </copyright><pubDate>Tue, 07 Sep 2010 21:04:47 +0800</pubDate><item><title>R6034 又来了.</title><author>crazycs@163.com (cs)</author><link>http://chensheng.net/post/21.html</link><pubDate>Mon, 04 May 2009 20:23:55 +0800</pubDate><guid>http://chensheng.net/post/21.html</guid><description><![CDATA[<p><a class="l" target="_blank" onmousedown="return clk(0,'','','res','12','')" href="http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/9fbc9292-11b8-4ee4-94a4-5223546df280"><font color="#cc0033" size="3">R6034</font></a>,又来了.</p><p>用vs2008编译的一个项目,之前运行得很好,今天编译了一下,结果又出现了 R6034.记得之前曾发生过无数回这样诡异的事情.后来都轻松解决,这回却忘记怎么弄了.</p><p>一番折腾之后,得出如下解决之法,特记录如下</p><p>1)可以先将&quot;清单工具&quot;中的嵌入清单设成否,编译,然后再改成&quot;是&quot;,重新编译,运行试试,</p><p>2)或者干脆彻底地,把生成的清单文件删除,再重新编译,100%ok.</p><p>&nbsp;R6034 错误的解决之道--仅限于原来可以正常运行的情况下。</p><p>&nbsp;</p>]]></description><category>敲打代码</category><comments>http://chensheng.net/post/21.html#comment</comments><wfw:comment>http://chensheng.net/</wfw:comment><wfw:commentRss>http://chensheng.net/feed.asp?cmt=21</wfw:commentRss><trackback:ping>http://chensheng.net/cmd.asp?act=tb&amp;id=21&amp;key=3cebab53</trackback:ping></item><item><title>ByteArray 使用摘录 utf-16与ByteArray的恩怨 flex中文乱码之谜</title><author>crazycs@163.com (cs)</author><link>http://chensheng.net/post/19.html</link><pubDate>Thu, 26 Mar 2009 16:40:13 +0800</pubDate><guid>http://chensheng.net/post/19.html</guid><description><![CDATA[<p><span style="font-size: medium">ByteArray是一种有用的对象<br />他有3个值得注意的属性<br />position 及 length,endian</span></p><p><span style="font-size: medium">ByteArray 有二种操作<br />一种是Read系列，主要是将从position开始的，返回某种类型长度或指定长度的缓冲,返回结果会做根据字节顺序一些处理，同时postion会自动移到读取缓冲的终点。</span></p><p><span style="font-size: medium">二是Write系列，也是从position开始，写入某种类型长度或指定长度的数据（必要时会根据字节顺序作处理），同时position会自增。</span></p><p><span style="font-size: medium">要注意的有几点<br /><span style="font-size: large"><span><strong>1)字节顺序</strong></span></span><br />&nbsp;var b:ByteArray= new ByteArray;<br />&nbsp;b.endian=flash.utils.Endian.BIG_ENDIAN;<br />&nbsp;b.writeShort(0x1234);<br />&nbsp;b.position=0;<br />&nbsp;trace(b.readByte());//=0x12，如果b.endian=flash.utils.LITTLE_ENDIAN,则是0x34<br /><span style="font-size: large"><strong><span>2）readBytes</span></strong></span><br />ByteArray.readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void<br />Reads the number of data bytes, specified by the length parameter, from the byte stream.</span></p><p><span style="font-size: medium"><br />如<br />var b:ByteArray= new ByteArray;<br />var a:ByteArray= new ByteArray;<br />..<br />b.ReadBytes(a,o,l);</span></p><p><span style="font-size: medium">这时从b的角度来考虑，b是从b.position开始读取b的内容的。<br />从a的角度来看，a被写的数据是存放在[o,o+l)这段空间的，这时不关心a的position在何处。<br />如果a的长度原来不够，则会自动增长到o+l长度。</span></p><p><span style="font-size: large"><span><strong><span>3）writeBytes</span></strong></span></span><span style="font-size: medium"><br />public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void<br />var b:ByteArray= new ByteArray;<br />var a:ByteArray= new ByteArray;<br />...<br />b.writeBytes(a,o,l);<br />表示从b.postion 开始写入从a的o处开始l 长度的缓冲到b</span></p><p><span style="font-size: medium"><br /><span style="font-size: large"><span><strong>4) 关于字符集的问题</strong></span></span><br />ByteArray在处理utf-8及普通字符集都没有太大问题（通过read/writeUTF/MultiByte）<br />但在处理utf-16时有点小麻烦。<br />也就说，如果ByteArray存放的是utf-16则有些问题。</span></p><p><span style="font-size: medium">flex 自己的文档 &ldquo;Supported Character Sets&rdquo;&nbsp; 有这么一行：Unicode (Big-Endian) unicodeFFFE ，也就是说 0xFFFE flex当成大端的BOM，然而恰恰相反，这似乎应该是小端BOM吧。<br />所以当byteArray存放的是ucs-2时，即无论是大端还是小端，或者你怎么设置都不能正确得到字符串。晕啊。<br />这太郁闷了，当有BOM存在时，经过代码验证，flex是忽略ByteArray的endian设置的---只要有BOM存在(这是有道理的，因为bom决定了字节顺序）。</span></p><p><span style="font-size: medium">我写了一个小小的flex页面（页面及代码见文章最后），专门来测试，试了大把的charset 。最后的结果是让我对使用readMultiByte读取ucs-2(utf16-be or utf16-le)的缓冲不抱任何希望。</span></p><p><span style="font-size: medium">因此凡是utf-16编码的ByteArray得通过另外的方法来取得--而且有比较简单的方法（运气啊！是运气，还是因为上帝在这里关上门，就会在另一面打开一扇窗？）</span></p><p><span style="font-size: medium">ByteArray中缓冲区的数据要符合二个条件就可以读出</span></p><ol>    <li><span style="color: #0000ff"><strong><span style="font-size: medium">必须得有BOM</span></strong></span></li>    <li><span style="color: #0000ff"><strong><span style="font-size: medium">BOM之后的数据流字节顺序与BOM是一致的</span></strong></span></li></ol><p>&nbsp;</p><p><span style="font-size: medium">这样就可以通过ByteArray.toString()得到 String了！</span></p><p><span style="font-size: medium">小小代码例子：</span></p><blockquote><p><span style="font-size: medium">var s:String = &quot;123中国&quot;;<br />var b:ByteArray= new ByteArray;<br />b.writeByte(0xFF);<br />b.writeByte(0xFE);<br />b.endian=Endian.LITTLE_ENDIAN; //与上面的BOM对应起来<br />for ( var i:int = 0 ; i &lt;s.length ; ++i )<br />{<br />&nbsp;buff.writeShort( s.charCodeAt( i ));<br />}</span></p><p><span style="font-size: medium">var </span><a href="news:String"><span style="font-size: medium">news:String</span></a><span style="font-size: medium"> = b.toString();<br />trace(news);</span></p></blockquote><p><span style="font-size: medium">// or</span></p><blockquote><p><span style="font-size: medium">var s:String = &quot;123中国&quot;;<br />var b:ByteArray= new ByteArray;<br />b.writeByte(0xFE);<br />b.writeByte(0xFF);<br />b.endian=Endian.BIG_ENDIAN; //与上面的BOM对应起来<br />for ( var i:int = 0 ; i &lt;s.length ; ++i )<br />{<br />&nbsp;buff.writeShort( s.charCodeAt( i ));<br />}</span></p><p><span style="font-size: medium">var </span><a href="news:String"><span style="font-size: medium">news:String</span></a><span style="font-size: medium"> = b.toString();<br />trace(news);</span></p><p><span style="font-size: medium">&nbsp;</span></p></blockquote><p><span style="font-size: medium">我测试的flash程序所在</span></p><p><a href="http://chensheng.net/p/test-bytearray/"><span style="font-size: medium">http://chensheng.net/p/test-bytearray/</span></a></p><p><span style="font-size: medium">源代码点右键可以看到,utf-16字符串与byteArray之间的相互转换</span></p><p><span style="font-size: medium">&nbsp;</span></p><p><span style="font-size: medium">&nbsp;btw:这好象是一个bug</span></p><p><span style="font-size: medium">请参见：<a href="http://bugs.adobe.com/jira/browse/FP-716">http://bugs.adobe.com/jira/browse/FP-716</a></span></p><p><span style="font-size: medium">呵呵，这么说来，许多中文论坛上关于 Flex 中文乱码 的麻烦是有原因的，我这才是解决之首。</span></p><p>&nbsp;</p>]]></description><category>敲打代码</category><comments>http://chensheng.net/post/19.html#comment</comments><wfw:comment>http://chensheng.net/</wfw:comment><wfw:commentRss>http://chensheng.net/feed.asp?cmt=19</wfw:commentRss><trackback:ping>http://chensheng.net/cmd.asp?act=tb&amp;id=19&amp;key=efb67064</trackback:ping></item></channel></rss>
