<?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>Flex the world &#187; Flex 迷你教程</title>
	<atom:link href="http://www.flextheworld.com/category/flextutorial/feed" rel="self" type="application/rss+xml" />
	<link>http://www.flextheworld.com</link>
	<description>Flex, AIR, FMS, P2P and Things......</description>
	<lastBuildDate>Fri, 10 Sep 2010 08:08:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>基于Stratus 2的P2P多人文件共享</title>
		<link>http://www.flextheworld.com/2010/08/stratus2-p2p-fileshare.html</link>
		<comments>http://www.flextheworld.com/2010/08/stratus2-p2p-fileshare.html#comments</comments>
		<pubDate>Thu, 05 Aug 2010 12:43:40 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[P2P]]></category>
		<category><![CDATA[未分类]]></category>
		<category><![CDATA[flash multicast]]></category>
		<category><![CDATA[flash player 10.1]]></category>
		<category><![CDATA[Stratus]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=791</guid>
		<description><![CDATA[在我的上一篇Status 2的文章中给大家简单介绍了Stratus 2 一对多视频直播，今天给大家演示一下如何在NetGroup中共享文件。在原来的Strtuas 1 中，我们也可以发送文件，不过发送的方式很单一，只能通过NetStream.send的方式将文件发送给选定的对象。这样的文件发送问题很多。

发送过程中无法知道文件发送的情况。
很麻烦才可以将文件拆分发送。
发送的过程中很容易造成数据包丢失。
一次只能发送给一个用户，如果要发送到第二个用户，需要额外的连接。

以上这些问题因为Stratus 1 只支持点对点的传输，所以这些问题很难解决。而现在的Stratus 2，因为支持了Application level Multicast (应用层多播，关于应用层多播是什么因为不会影响我们的教程，这里就不多解释了，有兴趣的朋友可以问下google)，所以我们的文件发送变得更加的强大，或者说更加的P2P，具体来说有这些优点。

支持文件拆分发送。你可以将你的文件拆分至N份。
多用户间共享文件块 。A用户发送文件,B用户接收,C用户再接收时C用户从A与B中接收
相对稳定的传输 (因为Stratus 2 现在也是Beta阶段，我也没有试过真实环境下大量用户共享文件的情况所以稳定情况有待考证)
文件传输反馈。更方便的监控传送的过程

了解了以上这些，我们来看下面这个例子，代码我是在前一个例子的基础上添加，所以对已有的代码就不重复解释，只解释文件发送相关的代码。

文件发送过程

A从本地读取文件，切分成128K一个的大小，假设我们发送一个1MB的文件，那么就是9个文件块
A使用NetGroup.addHaveObject(0,9)发送文件, 9代表文件的快数。
B使用NetGroup.addWantObjects(index, index)来接收文件, 第一个index是当前的文件块，第二个index是需要到第几个文件块，我们的接收从0,0开始，我们在0文件块中保存文件的基本信息，名字，大小，等等。接收到0个文件快后，你可以直接接收剩下的全部文件块，比如NetGroup.addWantObjects(1, 9)，这样就直接接收剩全部文件块，如果NetGroup.addWantObjects(1, 1)表示你本次只需要再往下的一个文件块。
B在调用NetGroup.addWantObjects(index, index)后A会有事件响应，NetGroup.Replication.Request，在这个事件响应中A需要开始向要求文件的B发送文件 NetGroup.writeRequestedObject(event.info.requestID,p2pSharedObject.chunks[event.info.index])。 p2pSharedObject是我们发送的文件,requestID是B的地址，file.chunks[event.info.index]是需要写入的文件内容。
A发送文件时B响应事件NetGroup.Replication.Fetch.Result, B在事件中保存文件快，并继续重复#3步骤获取下一个文件快。如果文件块获取结束，保存本地。 （注意，B在获取文件块后可以使用#2的步骤将自己也变为文件发发布者）

Demo 操作
点击运行发布者
点击运行Viewer

先运行发布者，记住Gourp的名字，点击connect创建组
点击“共享文件”，随意选择一个文件。
运行Viewer，group中输入与发布者一样的Group.点击connect连接组
点击下载文件，下载发布者发送的文件。
你可以多开几个Viewer来一起接收文件。

需要注意的地方

?View Code ACTIONSCRIPT3     //允许Objecy Replication
     groupSpecifier.objectReplicationEnabled = true; //onConnect() function中设置


?View Code ACTIONSCRIPT3//设置replicationStrategy
netGroup.replicationStrategy = NetGroupReplicationStrategy.LOWEST_FIRST;//onNetGroupConnect() function中设置


?View Code ACTIONSCRIPT3//netStatusHandler中注意以下事件处理，接收和发送文件块
&#160;
case &#34;NetGroup.Replication.Fetch.Result&#34;: // e.info.index, e.info.object
&#160;
					//作为发布者已经接收的部分
					netGroup.addHaveObjects&#40;e.info.index,e.info.index&#41;;
					if&#40;e.info.code [...]]]></description>
			<content:encoded><![CDATA[<p>在我的上一篇Status 2的文章中给大家简单介绍了<a href="http://www.flextheworld.com/2010/02/flex-stratus-2-p2p.html" target="_blank">Stratus 2 一对多视频直播</a>，今天给大家演示一下如何在NetGroup中共享文件。在原来的Strtuas 1 中，我们也可以发送文件，不过发送的方式很单一，只能通过NetStream.send的方式将文件发送给选定的对象。这样的文件发送问题很多。</p>
<ol>
<li><span style="color: #ff0000;">发送过程中无法知道文件发送的情况。</span></li>
<li><span style="color: #ff0000;">很麻烦才可以将文件拆分发送。</span></li>
<li><span style="color: #ff0000;">发送的过程中很容易造成数据包丢失。</span></li>
<li><span style="color: #ff0000;">一次只能发送给一个用户，如果要发送到第二个用户，需要额外的连接。</span></li>
</ol>
<p>以上这些问题因为Stratus 1 只支持点对点的传输，所以这些问题很难解决。而现在的Stratus 2，因为支持了Application level Multicast (应用层多播，关于应用层多播是什么因为不会影响我们的教程，这里就不多解释了，有兴趣的朋友可以问下google)，所以我们的文件发送变得更加的强大，或者说更加的P2P，具体来说有这些优点。</p>
<ol>
<li><span style="color: #0000ff;">支持文件拆分发送。你可以将你的文件拆分至N份。</span></li>
<li><span style="color: #0000ff;">多用户间共享文件块 。A用户发送文件,B用户接收,C用户再接收时C用户从A与B中接收</span></li>
<li><span style="color: #0000ff;">相对稳定的传输 (因为Stratus 2 现在也是Beta阶段，我也没有试过真实环境下大量用户共享文件的情况所以稳定情况有待考证)</span></li>
<li><span style="color: #0000ff;">文件传输反馈。更方便的监控传送的过程</span></li>
</ol>
<p>了解了以上这些，我们来看下面这个例子，代码我是在前一个例子的基础上添加，所以对已有的代码就不重复解释，只解释文件发送相关的代码。</p>
<p><span id="more-791"></span></p>
<h2><strong>文件发送过程</strong></h2>
<ol>
<li>A从本地读取文件，切分成128K一个的大小，假设我们发送一个1MB的文件，那么就是9个文件块</li>
<li>A使用NetGroup.addHaveObject(0,9)发送文件, 9代表文件的快数。</li>
<li>B使用NetGroup.addWantObjects(index, index)来接收文件, 第一个index是当前的文件块，第二个index是需要到第几个文件块，我们的接收从0,0开始，我们在0文件块中保存文件的基本信息，名字，大小，等等。接收到0个文件快后，你可以直接接收剩下的全部文件块，比如NetGroup.addWantObjects(1, 9)，这样就直接接收剩全部文件块，如果NetGroup.addWantObjects(1, 1)表示你本次只需要再往下的一个文件块。</li>
<li>B在调用NetGroup.addWantObjects(index, index)后A会有事件响应，NetGroup.Replication.Request，在这个事件响应中A需要开始向要求文件的B发送文件 NetGroup.writeRequestedObject(event.info.requestID,p2pSharedObject.chunks[event.info.index])。 p2pSharedObject是我们发送的文件,requestID是B的地址，file.chunks[event.info.index]是需要写入的文件内容。</li>
<li>A发送文件时B响应事件NetGroup.Replication.Fetch.Result, B在事件中保存文件快，并继续重复#3步骤获取下一个文件快。如果文件块获取结束，保存本地。 （注意，B在获取文件块后可以使用#2的步骤将自己也变为文件发发布者）</li>
</ol>
<h2><strong>Demo 操作</strong></h2>
<p><a href="http://www.flextheworld.com/demo/stratus2-fileshare/Publisher.html" target="_blank"><span style="color: #ff0000;"><span style="color: #000000;"><strong><span style="color: #ff0000;">点击运行发布者</span></strong></span></span></a></p>
<p><a href="http://www.flextheworld.com/demo/stratus2-fileshare/Viewer.html" target="_blank"><span style="color: #ff0000;"><span style="color: #000000;"><strong><span style="color: #ff0000;">点击运行Viewer</span></strong></span></span></a></p>
<ol>
<li>先运行发布者，记住Gourp的名字，点击connect创建组</li>
<li>点击“共享文件”，随意选择一个文件。</li>
<li>运行Viewer，group中输入与发布者一样的Group.点击connect连接组</li>
<li>点击下载文件，下载发布者发送的文件。</li>
<li>你可以多开几个Viewer来一起接收文件。</li>
</ol>
<h2>需要注意的地方</h2>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p791code4'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7914"><td class="code" id="p791code4"><pre class="actionscript3" style="font-family:monospace;">     <span style="color: #009900; font-style: italic;">//允许Objecy Replication</span>
     groupSpecifier<span style="color: #000066; font-weight: bold;">.</span>objectReplicationEnabled = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//onConnect() function中设置</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p791code5'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7915"><td class="code" id="p791code5"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//设置replicationStrategy</span>
netGroup<span style="color: #000066; font-weight: bold;">.</span>replicationStrategy = NetGroupReplicationStrategy<span style="color: #000066; font-weight: bold;">.</span>LOWEST_FIRST<span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//onNetGroupConnect() function中设置</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p791code6'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7916"><td class="code" id="p791code6"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//netStatusHandler中注意以下事件处理，接收和发送文件块</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;NetGroup.Replication.Fetch.Result&quot;</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #009900; font-style: italic;">// e.info.index, e.info.object</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">//作为发布者已经接收的部分</span>
					netGroup<span style="color: #000066; font-weight: bold;">.</span>addHaveObjects<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">,</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">code</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #990000;">&quot;NetGroup.Replication.Fetch.Result&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
						<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #000000;">&#125;</span>
&nbsp;
					<span style="color: #009900; font-style: italic;">//接收文件</span>
					p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>chunks<span style="color: #000000;">&#91;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000000;">&#93;</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>object<span style="color: #000066; font-weight: bold;">;</span>
					updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;正在接收第&quot;</span><span style="color: #000066; font-weight: bold;">+</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;块文件&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
						p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>packetLenght = <a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>object<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>object<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">;</span>
						updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;要接收的文件有: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>packetLenght<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;块文件&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						receiveObject<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
					<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span>
						<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">&lt;</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>packetLenght<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
							receiveObject<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
						<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span>
							updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;文件接收完毕&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;接收了: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>packetLenght<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;块文件&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
							p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">&lt;</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>packetLenght<span style="color: #000066; font-weight: bold;">;</span>i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
								p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeBytes</span><span style="color: #000000;">&#40;</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>chunks<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
							<span style="color: #000000;">&#125;</span>
&nbsp;
							updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;字节长度: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
							Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;保存文件&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;文件下载完毕，是否保存?&quot;</span><span style="color: #000066; font-weight: bold;">,</span>Alert<span style="color: #000066; font-weight: bold;">.</span>YES<span style="color: #000066; font-weight: bold;">|</span>Alert<span style="color: #000066; font-weight: bold;">.</span>NO<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">,</span>saveFileHandelr<span style="color: #000000;">&#41;</span>
&nbsp;
						<span style="color: #000000;">&#125;</span>
					<span style="color: #000000;">&#125;</span>
&nbsp;
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;NetGroup.Replication.Request&quot;</span><span style="color: #000066; font-weight: bold;">:</span> <span style="color: #009900; font-style: italic;">// e.info.index, e.info.requestID</span>
					<span style="color: #009900; font-style: italic;">//同时作为发布者</span>
					netGroup<span style="color: #000066; font-weight: bold;">.</span>writeRequestedObject<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>requestID<span style="color: #000066; font-weight: bold;">,</span>p2pSharedObject<span style="color: #000066; font-weight: bold;">.</span>chunks<span style="color: #000000;">&#91;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
					updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;接收方ID: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span>requestID<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;, 需要的文件块: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">index</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<h2>源文件下载</h2>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=26" title=" downloaded 56 times" >Stratus2FileSharing (56)</a>
<h2>相关资源</h2>
<ol>
<li><a title="Permalink to Flex 迷你教程 — 基于Stratus的P2P网络电话 (1)" rel="bookmark" href="http://www.flextheworld.com/2009/01/flex-stratus-p2p-phone.html">Flex 迷你教程 — 基于Stratus的P2P网络电话 (1)</a></li>
<li><a title="Permalink to Flex 迷你教程 — 基于Stratus的P2P网络电话 (2)" rel="bookmark" href="http://www.flextheworld.com/2009/01/flex-stratus-phone-2.html">Flex 迷你教程 — 基于Stratus的P2P网络电话 (2)</a></li>
<li><a href="http://www.flextheworld.com/2009/01/flex-stratus-phone-3.html" target="_blank">Flex 迷你教程 — 基于Stratus的P2P网络电话 (3)</a></li>
<li><a title="Permanent Link to Flex 迷你教程 — 基于Stratus 2的P2P在线视频共享1 (NetGroup, Multicast实例)" rel="bookmark" href="http://www.flextheworld.com/2010/02/flex-stratus-2-p2p.html">Flex 迷你教程 — 基于Stratus 2的P2P一对多视频直播 (NetGroup, Multicast实例)</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2010/08/stratus2-p2p-fileshare.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Flex 迷你教程 — 基于Stratus 2的P2P一对多视频直播 (NetGroup, Multicast实例)</title>
		<link>http://www.flextheworld.com/2010/02/flex-stratus-2-p2p.html</link>
		<comments>http://www.flextheworld.com/2010/02/flex-stratus-2-p2p.html#comments</comments>
		<pubDate>Wed, 24 Feb 2010 08:46:29 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[P2P]]></category>
		<category><![CDATA[未分类]]></category>
		<category><![CDATA[flash player 10.1]]></category>
		<category><![CDATA[Stratus]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=691</guid>
		<description><![CDATA[终于有时间试下Strtaus 2的p2p多播功能了。之前看的视频介绍中，Adobe描述一个非常理想的多人P2P数据共享方式。但是今天试了一下后发现视频的速度非常慢（视频的发布和接收端都在一台机器上），感觉上视频被发送到了什么地方后才传了回来。这这&#8230;&#8230;好吧，就当是BETA的问题了，WAIT AND SEE. (2/25日更新，2/23日发布的Flash player 10.1 beta 3 看来解决了这个问题，Demo的速度现在非常正常)
准备工作:
先了解一下什么是stratus以及什么是RTMFP，你可以到http://labs.adobe.com/technologies/stratus/看下官方的解释或者直接看我原来的 Flex 迷你教程 — 基于Stratus的P2P网络电话 (1)(2)(3) 先学习一下Flash p2p的基础. 简单的说原来的Stratus 实现了flash player之间点对点的传输数据，而今天要讲的stratus 2 不仅支持单个的点对点数据传说，还引入了多播的概念。
在原来的stratus中如果我们要做一个多人同时在线的应用，比如多人视频。那么我们需要把在线的所有人都链接起来，类似蜘蛛网的结构，网中的每个人需要与其他所有人链接，这样数据才能在所有人中共享。这种模式在多人连线中是不可取的。假设我们用户A发布一个视频想让其他10个用户观看，那么10个用户都需要链接到他。就中国的普通用户的网络带宽来说，这就是极限了。而Stratus 2 中 “组” 的概念解决了这个问题。用户A发布视频让同一个组中的其他10个人观看。他们并都从A处获取视频。而有可能通过组中的其他用户获取A的视频。这也就是P2P的模式了，每个人都可以作为数据的发出者，数据以最优的方式被观看者收到，参与的人越多，数据的副本就越多。视频的速度也就越快。


确定你安装了 Flex SDK3.2 以上的SDK (现在最新的是3.5). 这里下载
确定安装了flash payer 10.1 debug version (开发环境最好用debug version)  这里下载
申请一个 Stratus develper key 这里申请
下载flash player 10.1 的 Player Global SWC  这里下载，放到你的SDK3.2目录下面吧
导入下面的Demo源文件，编辑项目属性 — Flex compiler — Require Flash player version 到 10:1:0
编辑项目属性 [...]]]></description>
			<content:encoded><![CDATA[<p>终于有时间试下Strtaus 2的p2p多播功能了。之前看的视频介绍中，Adobe描述一个非常理想的多人P2P数据共享方式。但是今天试了一下后发现视频的速度非常慢（视频的发布和接收端都在一台机器上），感觉上视频被发送到了什么地方后才传了回来。这这&#8230;&#8230;好吧，就当是BETA的问题了，WAIT AND SEE. <strong><span style="color: #ff0000;">(2/25日更新，2/23日发布的Flash player 10.1 beta 3 看来解决了这个问题，Demo的速度现在非常正常)</span></strong></p>
<h2>准备工作:</h2>
<p><span style="font-weight: normal; font-size: 13px;">先了解一下什么是stratus以及什么是RTMFP，你可以到<a href="http://labs.adobe.com/technologies/stratus/">http://labs.adobe.com/technologies/stratus/</a>看下官方的解释或者直接看我原来的 <a href="http://www.flextheworld.com/2009/01/flex-stratus-p2p-phone.html">Flex 迷你教程 — 基于Stratus的P2P网络电话 (1)(2)(3</a>) 先学习一下Flash p2p的基础. 简单的说原来的Stratus 实现了flash player之间点对点的传输数据，而今天要讲的stratus 2 不仅支持单个的点对点数据传说，还引入了多播的概念。</span></p>
<p><span style="font-weight: normal; font-size: 13px;">在原来的stratus中如果我们要做一个多人同时在线的应用，比如多人视频。那么我们需要把在线的所有人都链接起来，类似蜘蛛网的结构，网中的每个人需要与其他所有人链接，这样数据才能在所有人中共享。这种模式在多人连线中是不可取的。假设我们用户A发布一个视频想让其他10个用户观看，那么10个用户都需要链接到他。就中国的普通用户的网络带宽来说，这就是极限了。而Stratus 2 中 “组” 的概念解决了这个问题。用户A发布视频让同一个组中的其他10个人观看。他们并都从A处获取视频。而有可能通过组中的其他用户获取A的视频。这也就是P2P的模式了，每个人都可以作为数据的发出者，数据以最优的方式被观看者收到，参与的人越多，数据的副本就越多。视频的速度也就越快。<span id="more-691"></span><br />
</span></p>
<ol>
<li>确定你安装了 Flex SDK3.2 以上的SDK (现在最新的是3.5). <a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;" href="http://www.adobe.com/products/flex/flexdownloads/" target="_blank">这里下载</a></li>
<li>确定安装了flash payer 10.1 debug version (开发环境最好用debug version)  <a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;" href="http://labs.adobe.com/downloads/flashplayer10.html" target="_blank">这里下载</a></li>
<li>申请一个 Stratus develper key <a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: #000000; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;" href="https://www.adobe.com/cfusion/entitlement/index.cfm?e=stratus" target="_blank">这里申请</a></li>
<li>下载flash player 10.1 的 Player Global SWC  <a href="http://download.macromedia.com/pub/labs/flashplayer10/flashplayer10_globalswc.zip">这里下载</a>，放到你的SDK3.2目录下面吧</li>
<li>导入下面的Demo源文件，编辑项目属性 — Flex compiler — Require Flash player version 到 10:1:0</li>
<li>编辑项目属性 &#8212; Flex Builder Path &#8212; Library Path &#8212; Add SWC. 添加你刚才下载的playerglobal.swc &#8212;- 添加后双击playerglobal.swc &#8212; 双击Link Type &#8212; 切换Link Type到External</li>
</ol>
<p>好了，准备工作到此结束。</p>
<h2><strong>Demo操作</strong></h2>
<p>Demo 是一个视频共享的程序，用户A发布一个视频，其他进入相同组的用户可以观看视频，观看视频的同时大家可以文字聊天</p>
<ol>
<li>先运行Publisher.mxml. 点击链接 （记住Group 名字，一会要用）</li>
<li>运行Viewer.mxml, 输入刚才的Group 名字，点链接。</li>
<li>你可以运行多个Viewer,输入相同的Group名，链接进去同一个组</li>
<li>链接成功后Viewer可以看见Publisher发布的视频。下面的聊天框可以和所有人聊天。</li>
</ol>
<h2><strong>代码说明</strong></h2>
<p>具体的代码说明大家下载源文件看注释就好了（看Publisher的注释）。这里只说一下Publisher和Viewer的区别，Publisher是作为视频的发布者以及Group的参与者（注意他并不是Gruop的&#8221;老大&#8221;，Group对这里的任何人来说都是平等的，Publisher只是在里面发布了视频而已）。Viewer是视频的接收者以及Group的参与者。下面的代码指出了Viewer和Publisher的不同</p>
<p><strong>Publisher发布视频</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code9'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6919"><td class="code" id="p691code9"><pre class="actionscript3" style="font-family:monospace;">           <span style="color: #3f5fbf;">/**
            *
            * NetStraeam链接到用户组后触发
            * */</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onNetStreamConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
            	<span style="color: #009900; font-style: italic;">//加载话筒</span>
                netStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> mic<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=microphone%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:microphone.html"><span style="color: #004993;">Microphone</span></a> = <a href="http://www.google.com/search?q=microphone%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:microphone.html"><span style="color: #004993;">Microphone</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getMicrophone</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>mic<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    mic<span style="color: #000066; font-weight: bold;">.</span>codec = SoundCodec<span style="color: #000066; font-weight: bold;">.</span>SPEEX<span style="color: #000066; font-weight: bold;">;</span>
                    mic<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setSilenceLevel</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                    netStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachAudio</span><span style="color: #000000;">&#40;</span>mic<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                    updateStatus<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;话筒设置完毕<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #009900; font-style: italic;">//加载视频，并发布视频和话筒</span>
                publishVideo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Viewer接收视频</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p691code10'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p69110"><td class="code" id="p691code10"><pre class="actionscript3" style="font-family:monospace;">            <span style="color: #3f5fbf;">/**
            *
            * NetStraeam链接到用户组后触发
            * */</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onNetStreamConnect<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                netStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">!</span>= video<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    videoDisplay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    video = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                video = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">smoothing</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
                video<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachNetStream</span><span style="color: #000000;">&#40;</span>netStream<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                videoDisplay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>video<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">//播放视频</span>
                netStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;stream&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                netStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bufferTime</span> = <span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h2>Demo截图</h2>
<p><strong>Publisher</strong></p>
<p><img class="alignnone size-full wp-image-694" title="a" src="http://www.flextheworld.com/wp-content/uploads/2010/02/a.png" alt="a" width="641" height="498" /></p>
<p><strong>Viewer</strong></p>
<p><img class="alignnone size-full wp-image-695" title="b" src="http://www.flextheworld.com/wp-content/uploads/2010/02/b.png" alt="b" width="642" height="547" /></p>
<h2>源代码下载</h2>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=24" title=" downloaded 480 times" >Stratus2Demo (480)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2010/02/flex-stratus-2-p2p.html/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Flex 迷你教程 &#8212; 在AdvancedDataGrid中合并单元格 （合并行）</title>
		<link>http://www.flextheworld.com/2009/12/flex-advanceddatagrid-rowspan.html</link>
		<comments>http://www.flextheworld.com/2009/12/flex-advanceddatagrid-rowspan.html#comments</comments>
		<pubDate>Sun, 20 Dec 2009 04:21:49 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[开源控件]]></category>
		<category><![CDATA[DataGrid rowspan]]></category>
		<category><![CDATA[合并单元格]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=633</guid>
		<description><![CDATA[在项目中我们对DataGrid的要求是很高的，但很不幸的Flex 的DataGird的功能是很傻的，这就催生了AdvancedDatgrid, 它确实解决了很多DataGrid不能做的事，比如多级排序，单元格选择，树状显示数据，合并表头等，但是不知道为什么它确忘记了 “合并单元格”这么重要的事。好在牛人是很多的，于是出现了MecGrid, NecGrid这样不错的能解决单元格合并的DataGrid, 不过他们都各有缺点。
MecGrid: （http://www.mechansp.com/index.php）
1. 不支持itemrender。
2. 单元格选择时无法获知整行数据。
3. 不支持xxxFunction设置比如（labelFunction）
4. 设置很不方便。在column设置中大量使用 number作为参数，非常非常的不利于使用，在线文档对这个ResourceXML的设置也没有提到具体细节，这个很头痛.
总结: MecGrid的使用非常不方便，而且完全不支持复杂数据类型，虽然实现了很多功能但都是固定功能，扩展性不强。这让他局限在只能作为表格使用。
NEC Grid （http://www.necst.co.jp/product/ibiz/column/ibizblock/chap7.html）

1. 不能改变行高。
2. 破换了itemrender的使用，我增加了一个ComboBox作为itemrender,但是他的显示完全不正常。如果itemrender的高度大于他的默认行高，显示会被切断。
3. 不支持单元格选择。
总结：这个DataGrid的使用非常方便，不过缺点也比较明显，尤其是对itemrender这条，要命的是他不能改变行高，但实际中我们的数据是很有可能换行的。另外他居然不支持单元格选择，作为一个AdvancedDatagird,单元格选择在很多时候是必要的。总的来说这个DataGrid用于对数据操作没有特殊要求的用户是不错的选择。
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-废话结束，教程开始的分割线&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;


在看完了老美和日本人做的DataGrid后找到一个韩国人做的，名字就叫AdavcnedDataGrid, 相比Mec和Nec, 扩展的功能比较单一，Bug也非常多，只有合并单元格功能，基于Flex 的AdvancedDataGrid实现。不过也是保留原有 AdvancedDataGrid功能最完整的, 为了和Flex AdvancedDataGrid 区分，我叫它KAdvancedDataGrid。
KAdvancedDataGrid (http://code.google.com/p/advanceddatagrid/)
文章末尾是KadvancedDataGird的下载，相对于原版，我修复了如下内容:

动态使用columns = XXXX不起作用。
当列数据为复杂类型时异常。
设置dataProvider为null时异常。
还有一些其他的异常，忘了&#8230;..

KAdvancedDataGrid的使用很简单，使用groupedColumns标签，把想要合并的列放进去，他会自动的将相同内容的单元格合并在一起。
如下图：

本例的代码在文章末尾，测试代码很简单，这里就不过多解释了，大家可以下载测试。
KAdvancedDataGrid的应用展示
下面几张截图是我使用KadvancedDataGrid作为原材料制作的显示员工出勤情况的日历控件（Calendar View），包括Day, Week, Month和Year View.  这里显示的是Week, Month 和Year View. 使用前面的MecDataGrid或者NecGrid要想实现这样的DatGrid比较困难，Mec是灵活性不够，只能创建它固定格式的Grid, Nec是无法处理复杂数据类型。图片的分辨率较大，点击查看大图
Month View

Week View 

Year View

源代码
源代码中的AdvancedDataGrid是我修改后的版本，原版可访问http://code.google.com/p/advanceddatagrid/


]]></description>
			<content:encoded><![CDATA[<p>在项目中我们对DataGrid的要求是很高的，但很不幸的Flex 的DataGird的功能是很傻的，这就催生了AdvancedDatgrid, 它确实解决了很多DataGrid不能做的事，比如多级排序，单元格选择，树状显示数据，合并表头等，但是不知道为什么它确忘记了 “合并单元格”这么重要的事。好在牛人是很多的，于是出现了MecGrid, NecGrid这样不错的能解决单元格合并的DataGrid, 不过他们都各有缺点。</p>
<p><strong>MecGrid: （http://www.mechansp.com/index.php）</strong></p>
<p>1. 不支持itemrender。<br />
2. 单元格选择时无法获知整行数据。<br />
3. 不支持xxxFunction设置比如（labelFunction）<br />
4. 设置很不方便。在column设置中大量使用 number作为参数，非常非常的不利于使用，在线文档对这个ResourceXML的设置也没有提到具体细节，这个很头痛.</p>
<p>总结: MecGrid的使用非常不方便，而且完全不支持复杂数据类型，虽然实现了很多功能但都是固定功能，扩展性不强。这让他局限在只能作为表格使用。<br />
<strong>NEC Grid （http://www.necst.co.jp/product/ibiz/column/ibizblock/chap7.html）</strong></p>
<p><img class="alignnone size-full wp-image-636" title="nec" src="http://www.flextheworld.com/wp-content/uploads/2009/12/nec.jpg" alt="nec" width="356" height="346" /></p>
<p>1. 不能改变行高。<br />
2. 破换了itemrender的使用，我增加了一个ComboBox作为itemrender,但是他的显示完全不正常。如果itemrender的高度大于他的默认行高，显示会被切断。<br />
3. 不支持单元格选择。</p>
<p>总结：这个DataGrid的使用非常方便，不过缺点也比较明显，尤其是对itemrender这条，要命的是他不能改变行高，但实际中我们的数据是很有可能换行的。另外他居然不支持单元格选择，作为一个AdvancedDatagird,单元格选择在很多时候是必要的。总的来说这个DataGrid用于对数据操作没有特殊要求的用户是不错的选择。</p>
<p><span style="color: #ff0000;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-废话结束，教程开始的分割线&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p><span style="color: #ff0000;"><span id="more-633"></span><br />
</span></p>
<p>在看完了老美和日本人做的DataGrid后找到一个韩国人做的，名字就叫AdavcnedDataGrid, 相比Mec和Nec, 扩展的功能比较单一，Bug也非常多，只有合并单元格功能，基于Flex 的AdvancedDataGrid实现。不过也是保留原有 AdvancedDataGrid功能最完整的, 为了和Flex AdvancedDataGrid 区分，我叫它KAdvancedDataGrid。</p>
<p><strong>KAdvancedDataGrid (http://code.google.com/p/advanceddatagrid/)</strong></p>
<p>文章末尾是KadvancedDataGird的下载，相对于原版，我修复了如下内容:</p>
<ol>
<li>动态使用columns = XXXX不起作用。</li>
<li>当列数据为复杂类型时异常。</li>
<li>设置dataProvider为null时异常。</li>
<li>还有一些其他的异常，忘了&#8230;..</li>
</ol>
<p>KAdvancedDataGrid的使用很简单，使用groupedColumns标签，把想要合并的列放进去，他会自动的将相同内容的单元格合并在一起。</p>
<p>如下图：</p>
<p><img class="alignnone size-full wp-image-638" title="kad" src="http://www.flextheworld.com/wp-content/uploads/2009/12/kad.jpg" alt="kad" width="631" height="298" /></p>
<p>本例的代码在文章末尾，测试代码很简单，这里就不过多解释了，大家可以下载测试。</p>
<p><strong>KAdvancedDataGrid的应用展示</strong></p>
<p>下面几张截图是我使用KadvancedDataGrid作为原材料制作的显示员工出勤情况的日历控件（Calendar View），包括Day, Week, Month和Year View.  这里显示的是Week, Month 和Year View. 使用前面的MecDataGrid或者NecGrid要想实现这样的DatGrid比较困难，Mec是灵活性不够，只能创建它固定格式的Grid, Nec是无法处理复杂数据类型。图片的分辨率较大，点击查看大图</p>
<p><strong>Month View</strong></p>
<p><a href="http://www.flextheworld.com/wp-content/uploads/2009/12/monthview.gif" rel="shadowbox[post-633];player=img;" target="_blank"><img class="alignnone size-medium wp-image-641" title="monthview" src="http://www.flextheworld.com/wp-content/uploads/2009/12/monthview-300x287.gif" alt="monthview" width="300" height="287" /></a></p>
<p><strong>Week View </strong></p>
<p><a href="http://www.flextheworld.com/wp-content/uploads/2009/12/WeekView.jpg" rel="shadowbox[post-633];player=img;" target="_blank"><strong><img class="alignnone size-medium wp-image-642" title="WeekView" src="http://www.flextheworld.com/wp-content/uploads/2009/12/WeekView-300x65.jpg" alt="WeekView" width="300" height="65" /></strong></a></p>
<p><strong>Year View</strong></p>
<p><a href="http://www.flextheworld.com/wp-content/uploads/2009/12/yearView.gif" rel="shadowbox[post-633];player=img;" target="_blank"><strong><img class="alignnone size-medium wp-image-643" title="yearView" src="http://www.flextheworld.com/wp-content/uploads/2009/12/yearView-300x54.gif" alt="yearView" width="300" height="54" /></strong></a></p>
<p><strong>源代码</strong></p>
<p>源代码中的AdvancedDataGrid是我修改后的版本，原版可<strong>访问http://code.google.com/p/advanceddatagrid/</strong></p>
<p><strong><a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=18" title=" downloaded 860 times" >mergeableDataGrid (860)</a><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/12/flex-advanceddatagrid-rowspan.html/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>完美实现TextArea内按Enter发送消息并清空内容</title>
		<link>http://www.flextheworld.com/2009/08/textarea-enter-send-message.html</link>
		<comments>http://www.flextheworld.com/2009/08/textarea-enter-send-message.html#comments</comments>
		<pubDate>Thu, 06 Aug 2009 12:44:34 +0000</pubDate>
		<dc:creator>Albert Zhang</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[TestArea]]></category>
		<category><![CDATA[发送信息]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=564</guid>
		<description><![CDATA[利用KeyboardEvent.KEY_DOWN和TextEvent.TEXT_INPUT事件结合，可以用FlashPlayer 10中的TextArea完美实现消息发送框的功能。包括：
按Enter键立即发送消息、消息发送后立即清空TextArea、同时按Ctrl/Shift+Enter回车换行。
原理是：先判断KEY_DOWN事件中按下的是什么键，如果是Shift/Ctrl+Enter，则用代码向TextArea中插入一个换行符（这里flashplayer 9和10不一样，在9中按ctrl+Enter默认就是换行，而10不会，所以要用代码插入）。如果只按下了Enter，则在TEXT_INPUT事件处理中用preventDefault()来阻止默认的换行动作。
代码如下：

?View Code ACTIONSCRIPT3//下面三个变量用来保存KEY_DOWN事件时键盘的状态
&#160;
var shiftKey:Boolean;
&#160;
var ctrlKey:Boolean;
&#160;
var keyCode:int;
&#160;
var messageInput:TextArea;
&#160;
messageInput.addEventListener&#40;KeyboardEvent.KEY_DOWN,onKeyDown&#41;;
&#160;
messageInput.addEventListener&#40;TextEvent.TEXT_INPUT,onTextInput&#41;;
&#160;
private function onKeyDown&#40;e:KeyboardEvent&#41;:void&#123;
&#160;
//如果按下Enter时还按下Shift/Ctrl，则换行
&#160;
if&#40; e.keyCode==Keyboard.ENTER &#38;amp;&#38;amp; &#40;e.shiftKey &#124;&#124; e.ctrlKey&#41; &#41;&#123;
&#160;
callLater&#40;function&#40;&#41;:void&#123; //注意这个callLater
&#160;
var msg:String = messageInput.text;
&#160;
var part1:String = msg.substring&#40;0, messageInput.selectionBeginIndex&#41;;
&#160;
var part2:String = msg.substring&#40;messageInput.selectionEndIndex, 0x7fffffff&#41;;
&#160;
var selIndex:int = messageInput.selectionBeginIndex + 1;
&#160;
messageInput.text = part1 + &#34;\n&#34; + part2;
&#160;
messageInput.setSelection&#40;selIndex,selIndex&#41;;
&#160;
&#125;&#41;;
&#160;
keyCode = -1; //标识本次按键不需要TEXT_INPUT事件配合处理
&#160;
return;
&#160;
&#125;
&#160;
shiftKey = e.shiftKey;
&#160;
ctrlKey = e.ctrlKey;
&#160;
keyCode = e.keyCode;
&#160;
&#125;
&#160;
private function onTextInput&#40;evt:TextEvent&#41;:void&#123;
&#160;
if&#40;keyCode == -1&#41;&#123;
&#160;
return;
&#160;
&#125;
&#160;
if&#40;keyCode==Keyboard.ENTER &#38;amp;&#38;amp; !shiftKey [...]]]></description>
			<content:encoded><![CDATA[<p>利用KeyboardEvent.KEY_DOWN和TextEvent.TEXT_INPUT事件结合，可以用FlashPlayer 10中的TextArea完美实现消息发送框的功能。包括：</p>
<p>按Enter键立即发送消息、消息发送后立即清空TextArea、同时按Ctrl/Shift+Enter回车换行。</p>
<p>原理是：先判断KEY_DOWN事件中按下的是什么键，如果是Shift/Ctrl+Enter，则用代码向TextArea中插入一个换行符（这里flashplayer 9和10不一样，在9中按ctrl+Enter默认就是换行，而10不会，所以要用代码插入）。如果只按下了Enter，则在TEXT_INPUT事件处理中用preventDefault()来阻止默认的换行动作。</p>
<p>代码如下：<span id="more-564"></span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p564code12'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56412"><td class="code" id="p564code12"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//下面三个变量用来保存KEY_DOWN事件时键盘的状态</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">shiftKey</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">ctrlKey</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">keyCode</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> messageInput<span style="color: #000066; font-weight: bold;">:</span>TextArea<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=keyboardevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboardevent.html"><span style="color: #004993;">KeyboardEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">KEY_DOWN</span><span style="color: #000066; font-weight: bold;">,</span>onKeyDown<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=textevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textevent.html"><span style="color: #004993;">TextEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TEXT_INPUT</span><span style="color: #000066; font-weight: bold;">,</span>onTextInput<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onKeyDown<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=keyboardevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboardevent.html"><span style="color: #004993;">KeyboardEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//如果按下Enter时还按下Shift/Ctrl，则换行</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span>==<a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER</span> <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">shiftKey</span> <span style="color: #000066; font-weight: bold;">||</span> e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ctrlKey</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
callLater<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span> <span style="color: #009900; font-style: italic;">//注意这个callLater</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> msg<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> part1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = msg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">substring</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectionBeginIndex</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> part2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = msg<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">substring</span><span style="color: #000000;">&#40;</span>messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectionEndIndex</span><span style="color: #000066; font-weight: bold;">,</span> 0x7fffffff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> selIndex<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectionBeginIndex</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = part1 <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> part2<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setSelection</span><span style="color: #000000;">&#40;</span>selIndex<span style="color: #000066; font-weight: bold;">,</span>selIndex<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">keyCode</span> = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//标识本次按键不需要TEXT_INPUT事件配合处理</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">shiftKey</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">shiftKey</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">ctrlKey</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ctrlKey</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">keyCode</span> = e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">keyCode</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onTextInput<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textevent.html"><span style="color: #004993;">TextEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">keyCode</span> == <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">keyCode</span>==<a href="http://www.google.com/search?q=keyboard%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:keyboard.html"><span style="color: #004993;">Keyboard</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ENTER</span> <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">shiftKey</span> <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">ctrlKey</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
evt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">preventDefault</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
callLater<span style="color: #000000;">&#40;</span><span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//sendMessage()即为发送消息的方法，它应该返回一个Boolean值，以此来决定是否清空消息框</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> sendMessage<span style="color: #000000;">&#40;</span>messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">htmlText</span> = <span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
messageInput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setSelection</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: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/08/textarea-enter-send-message.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Flex 4 &amp; Flash Builder 4 快速入门</title>
		<link>http://www.flextheworld.com/2009/06/flex-4-flash-builder-4.html</link>
		<comments>http://www.flextheworld.com/2009/06/flex-4-flash-builder-4.html#comments</comments>
		<pubDate>Tue, 30 Jun 2009 01:24:56 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIRIA]]></category>
		<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Flex gumbo]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=541</guid>
		<description><![CDATA[前些天和AIRIA的几位网友一起编写的《Flex 4 &#38; Flash Builder 4》 快速入门终于发布了，这本电子教程主要向大家介绍如何使用Flash Builder 4进行开发以及Flex SDK 4中的新特性(注:Flex Builder 4等于Flash Builder 4，以后没有以Flex命名的IDE了，只有SDK仍以Flex命名)，我的教程都集中在第四章&#8211;Flex 4新特性，如果大家阅读有什么疑问的话可以直接问我，或者到AIRIA论坛中发帖。

目 录（图书目录已编入PDF“书签”栏） 
第一章 Flash Builder 4 背景
1.1 从Flex Builder到Flash Builder
第二章 Flash Builder 4 界面
2.1 主界面
2.2 主菜单
2.3 工具条
2.4 主要窗口

第三章 Flash Builder 4 新特性
3.1 Package explorer
3.2 悬停时的ASDOC提示
3.3 Getter &#38; Setter
3.4 自动生成EventHandler
3.5 条件断点
第四章 Flex SDK 4 新特性
4.1 主题
4.2 布局
4.3 特效
4.4 样式
4.5 状态
4.6 双向绑定
4.7 ASDoc
4.8 SWFObject 与 HTML Template
第五章 自定义组件开发
5.1 自定义Flex组件
5.2 MXML组件开发
5.3 ActionScript组件开发
第六章 与服务端通信
6.1 通过Http Service与服务端通信
6.2 通过Web Service与服务端通信
6.3 通过Remoting与服务端通信
6.4 与Flash Media Server交互
《Flash Builder 4 快速入门》内容简介
 在Adobe发布Flash Builder 4后，艾睿论坛 （bbs.airia.cn）编辑团队协作完成了这部教学。 《Flash Builder 4 快速入门》6月25日正式发布第一个版本，今后还会根据读者需要进行更新。
本书适合谁读？
《Flash Builder 4 快速入门》除了适合想学习FLEX开发和正在学习FLEX开发的朋友，也广泛适用与FLASH、 Actionscript开发者进行转型和深入学习。包括.NET、JAVA开发人员在内，这本书都将为你日后的含RIA开发工作奠定牢固的知识基础。
章节简介：
本书1-2章主要为新接触FLEX开发的朋友提供入门帮助，以图文并茂的方式从零基础开始指引新手走进 FLEX开发，如果是有一定基础的FLEX开发者，这两章可以简单翻阅。3-5章开始进阶学习， 介绍FB4 / FLEX SDK 4 新特性与开发实 例，适合绝大多数的FLEX开发者阅读。 第6章为通信服务方面的必备知识，这一章以实际案例的方式展示了FLEX与服务端通信的4种方式。
电子书中大部分章节，作者还做出了“提示”“！总结” “！思考”的高亮片段，以此帮助读者更好的学习。
在PDF的最后一页，放置了FLASH讨论簿，这是交互式PDF应用的一个小小尝试，AIRIA以后出版的PDF还会放入更多交互应用。
本书作者：
本书凝聚了艾睿编辑团队各位作者的大量心血，以下是参与本书编辑的作者，如果你在阅读的期间遇到问题也可以进入Flash Builder快速入门专栏联系作者，或进入作者的博客与其交流。
他们分别是（排名不分先后）：
罗楷
http://www.flextheworld.com
kevin.luo.sl@gmail.com
郭峰
http://www.hydra1983.com
Edison@airia.cn
郑会宾
http://www.flexers.cn
momoko8443@163.com
唐凡
http://www.tangfanzone.com
woodytf@sina.com
陆仕桑
http://lushisang.com
lushisang@gmail.com


 《Flash Builder 4 快速入门》专栏：
http://www.airia.cn/flashbuilder/
《Flash Builder 4快速入门 》PDF、源码包 下载页：
http://www.airia.cn/flashbuilder/fb4Qbook/source/
下载 Adobe Reader 9 阅读器:

下载地址http://www.onlinedown.net/soft/2696.htm

本帖（以上内容）欢迎大家踊跃转载。让更多的朋友顺利走入FLEX开发。
FQA：
为什么我打开需要密码？
编辑团队对PDF的“修改权限”设置了密码，我们希望可以保证该文档的完整性、安全性，不希望文档被任意篡改,最终目的是为了保障读者权益。但这并不影响阅读和学习，通常低版本的Adobe Reader 会报出需要密码，请使用 Adobe Reader 9 阅读器。
]]></description>
			<content:encoded><![CDATA[<p>前些天和AIRIA的几位网友一起编写的《Flex 4 &amp; Flash Builder 4》 快速入门终于发布了，这本电子教程主要向大家介绍如何使用Flash Builder 4进行开发以及Flex SDK 4中的新特性(注:Flex Builder 4等于Flash Builder 4，以后没有以Flex命名的IDE了，只有SDK仍以Flex命名)，我的教程都集中在第四章&#8211;Flex 4新特性，如果大家阅读有什么疑问的话可以直接问我，或者到<a href="http://bbs.airia.cn" target="_blank">AIRIA论坛</a>中发帖。</p>
<p><img class="alignnone size-full wp-image-542" title="fm" src="http://www.flextheworld.com/wp-content/uploads/2009/06/fm.jpg" alt="fm" width="439" height="468" /><span id="more-541"></span></p>
<p><strong><span style="font-size: x-large;">目 录<span style="font-size: small;"><span style="color: #666666;">（图书目录已编入PDF“书签”栏）</span></span></span></strong><strong> </strong></p>
<p><strong>第一章 Flash Builder 4 背景</strong></p>
<p><strong></strong><span style="color: #666666;">1.1 从Flex Builder到Flash Builder</span></p>
<p><strong>第二章 Flash Builder 4 界面<br />
</strong><span style="color: #666666;">2.1 主界面<br />
2.2 主菜单<br />
2.3 工具条<br />
2.4 主要窗口</span><br />
<strong><br />
第三章 Flash Builder 4 新特性<br />
</strong><span style="color: #666666;">3.1 Package explorer<br />
3.2 悬停时的ASDOC提示<br />
3.3 Getter &amp; Setter<br />
3.4 自动生成EventHandler<br />
3.5 条件断点</span></p>
<p><strong>第四章 Flex SDK 4 新特性<br />
</strong><span style="color: #666666;">4.1 主题<br />
4.2 布局<br />
4.3 特效<br />
4.4 样式<br />
4.5 状态<br />
4.6 双向绑定<br />
4.7 ASDoc<br />
4.8 SWFObject 与 HTML Template</span><strong></strong></p>
<p><strong>第五章 自定义组件开发</strong></p>
<p><strong></strong><span style="color: #666666;">5.1 自定义Flex组件<br />
5.2 MXML组件开发<br />
5.3 ActionScript组件开发</span><strong></strong></p>
<p><strong>第六章 与服务端通信</strong></p>
<p><strong></strong><span style="color: #666666;">6.1 通过Http Service与服务端通信<br />
6.2 通过Web Service与服务端通信<br />
6.3 通过Remoting与服务端通信<br />
6.4 与Flash Media Server交互</span></p>
<p><strong><span style="font-size: large;">《Flash Builder 4 快速入门》内容简介</span></strong></p>
<p><strong></strong> 在Adobe发布Flash Builder 4后，<a href="http://www.airia.cn/">艾睿</a>论坛 （bbs.airia.cn）编辑团队协作完成了这部教学。 《Flash Builder 4 快速入门》6月25日正式发布第一个版本，今后还会根据读者需要进行更新。</p>
<p><strong><span style="font-size: large;"><span style="font-size: medium;">本书适合谁读？</span></span></strong></p>
<p>《Flash Builder 4 快速入门》除了适合想学习FLEX开发和正在学习FLEX开发的朋友，也广泛适用与FLASH、 Actionscript开发者进行转型和深入学习。包括.NET、JAVA开发人员在内，这本书都将为你日后的含RIA开发工作奠定牢固的知识基础。<span style="font-size: medium;"><strong></strong></span></p>
<p><strong>章节简介：</strong></p>
<p><strong></strong>本书1-2章主要为新接触FLEX开发的朋友提供入门帮助，以图文并茂的方式从零基础开始指引新手走进 FLEX开发，如果是有一定基础的FLEX开发者，这两章可以简单翻阅。3-5章开始进阶学习， 介绍FB4 / FLEX SDK 4 新特性与开发实 例，适合绝大多数的FLEX开发者阅读。 第6章为通信服务方面的必备知识，这一章以实际案例的方式展示了FLEX与服务端通信的4种方式。</p>
<p><span style="font-size: small;">电子书中大部分章节，作者还做出了<span style="color: #cc9900;">“提示”</span><span style="color: #cc0000;">“！总结” “！思考”</span>的高亮片段，以此帮助读者更好的学习。</span></p>
<p>在PDF的最后一页，放置了FLASH讨论簿，这是交互式PDF应用的一个小小尝试，AIRIA以后出版的PDF还会放入更多交互应用。</p>
<p><span style="font-size: medium;"><strong>本书作者：</strong></span></p>
<p><strong></strong>本书凝聚了艾睿编辑团队各位作者的大量心血，以下是参与本书编辑的作者，如果你在阅读的期间遇到问题也可以进入<a href="http://www.airia.cn/flashbuilder">Flash Builder</a>快速入门专栏联系作者，或进入作者的博客与其交流。</p>
<p>他们分别是（排名不分先后）：</p>
<p>罗楷</p>
<p>http://www.flextheworld.com</p>
<p>kevin.luo.sl@gmail.com</p>
<p>郭峰</p>
<p>http://www.hydra1983.com</p>
<p>Edison@airia.cn</p>
<p>郑会宾</p>
<p>http://www.flexers.cn</p>
<p>momoko8443@163.com</p>
<p>唐凡</p>
<p>http://www.tangfanzone.com</p>
<p>woodytf@sina.com</p>
<p>陆仕桑</p>
<p>http://lushisang.com</p>
<p>lushisang@gmail.com</p>
<p><strong><br />
</strong></p>
<p><strong> 《Flash Builder 4 快速入门》专栏：<br />
</strong><a href="http://www.airia.cn/flashbuilder/">http://www.airia.cn/flashbuilder/</a><strong></strong></p>
<p><strong>《Flash Builder 4快速入门 》PDF、源码包 下载页：</strong><a href="http://www.airia.cn/flashbuilder/fb4Qbook/source/"></a></p>
<p><a href="http://www.airia.cn/flashbuilder/fb4Qbook/source/">http://www.airia.cn/flashbuilder/fb4Qbook/source/</a><strong></strong></p>
<p><strong>下载 Adobe Reader 9 阅读器:<br />
</strong><br />
下载地址<a href="http://www.onlinedown.net/soft/2696.htm">http://www.onlinedown.net/soft/2696.htm<br />
</a><strong></strong></p>
<p><strong>本帖（以上内容）欢迎大家踊跃转载。让更多的朋友顺利走入FLEX开发。</strong></p>
<p><strong>FQA：</strong></p>
<p><strong></strong><strong><span style="color: #0033ff;">为什么我打开需要密码？</span></strong></p>
<p>编辑团队对PDF的“修改权限”设置了密码，我们希望可以保证该文档的完整性、安全性，不希望文档被任意篡改,最终目的是为了保障读者权益。但这并不影响阅读和学习，通常低版本的<strong>Adobe Reader 会报出需要密码，请使用 Adobe Reader 9 阅读器。</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/06/flex-4-flash-builder-4.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Flex迷你教程 &#8212; Flex SDK 4新特性:布局</title>
		<link>http://www.flextheworld.com/2009/06/flex4-layout.html</link>
		<comments>http://www.flextheworld.com/2009/06/flex4-layout.html#comments</comments>
		<pubDate>Thu, 18 Jun 2009 01:59:36 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[布局]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=536</guid>
		<description><![CDATA[继续第二章，布局  
简介
这篇教程中我们将通过一些简单的例子初步的学习Flex SDK 4中新的布局方式。
学习目标

初步了解SDK4中布局有哪些变化。
学会使用新的布局方式。

准备工作
下载并安装Flash Builder 4
实现步骤
在之前的Flex SDK中，布局是在控件或者容器中单独定义的，因此我们的控件，比如List, TileList, and HorizontalList，他们全都有完全相同的方法，只是布局方式不同。在Flex 4中，布局已经从控件中剥离出来。这样我们可以更加灵活的对控件进行布局，比如在运行时将容器的布局方式由横向改为纵向。这在Flex 3中是很难实现的， 因为我们很难在运行时把List改为TileList 或者将Hbox改为Vbox。
在Flex 4的spark包中已经没有了原来的Hbox, Vbox, Box以及Canvas容器，取而代之的是Group，另一个新的容器是SkinnableContainer，它与Group的区别是我们可以为它定义皮肤。Group不能定义皮肤但有更高的执行效率以及使应用程序的体积更小。
我们现在来看一组例子，在Flex 4中定义List, TileList以及 HorizontalList
1. List
&#60;s:List /&#62;
2. HorizontalList
&#60;s:List&#62;
    &#60;s:layout&#62;
        &#60;s:HorizontalLayout /&#62;
    &#60;/s:layout&#62;
&#60;/s:List&#62;
3. Tiled List
&#60;s:List&#62;
    &#60;s:layout&#62;
        &#60;s:TileLayout [...]]]></description>
			<content:encoded><![CDATA[<p>继续第二章，布局 <img src='http://www.flextheworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>简介</h2>
<p>这篇教程中我们将通过一些简单的例子初步的学习Flex SDK 4中新的布局方式。</p>
<h2>学习目标</h2>
<ol>
<li>初步了解SDK4中布局有哪些变化。</li>
<li>学会使用新的布局方式。</li>
</ol>
<h2>准备工作</h2>
<p>下载并安装<a href="http://www.adobe.com/go/flashbuilder4_download%22%20rel=%22nofollow%22%20href=%22http://www.adobe.com/go/flashbuilder4_downloadflashbuilder4_download" target="_blank">Flash Builder 4</a></p>
<h2>实现步骤</h2>
<p>在之前的Flex SDK中，布局是在控件或者容器中单独定义的，因此我们的控件，比如List, TileList, and HorizontalList，他们全都有完全相同的方法，只是布局方式不同。在Flex 4中，布局已经从控件中剥离出来。这样我们可以更加灵活的对控件进行布局，比如在运行时将容器的布局方式由横向改为纵向。这在Flex 3中是很难实现的， 因为我们很难在运行时把List改为TileList 或者将Hbox改为Vbox。<span id="more-536"></span></p>
<p>在Flex 4的spark包中已经没有了原来的Hbox, Vbox, Box以及Canvas容器，取而代之的是Group，另一个新的容器是SkinnableContainer，它与Group的区别是我们可以为它定义皮肤。Group不能定义皮肤但有更高的执行效率以及使应用程序的体积更小。</p>
<p>我们现在来看一组例子，在Flex 4中定义List, TileList以及 HorizontalList</p>
<p>1. List</p>
<pre style="font-family: monospace;"><span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Alist+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">List</span></a> <span style="color: #339933;">/&gt;</span></pre>
<p>2. HorizontalList</p>
<pre style="font-family: monospace;"><span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>List<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>HorizontalLayout <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>List<span style="color: #339933;">&gt;</span></pre>
<p>3. Tiled List</p>
<pre style="font-family: monospace;"><span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>List<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>TileLayout <span style="color: #339933;">/&gt;</span>
    <span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>List<span style="color: #339933;">&gt;

</span>上面的例子中我们通过设置layout标签中的HorizontalLayou与TileLayout实现了3种不同List的布局，可以看到虽然从形式上样式的定义变得
更“复杂”了，但是布局的解耦让我们对控件的使用变得更加灵活。

除了控件的布局方式改变外，Flex 4中的滚动条也从控件中剥离了出来，默认的容器是没有滚动条以及virtualization的，我们来看下面显示滚
动条的例子。
<pre style="font-family: monospace;"><span style="color: #339933;">&lt;?</span>xml version<span style="color: #339933;">=</span><span style="color: #0000ff;">"1.0"</span> encoding<span style="color: #339933;">=</span><span style="color: #0000ff;">"utf-8"</span><span style="color: #339933;">?&gt;</span>
<span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>Application xmlns<span style="color: #339933;">:</span>fx<span style="color: #339933;">=</span><span style="color: #0000ff;">"http://ns.adobe.com/mxml/2009"</span> xmlns<span style="color: #339933;">:</span>s<span style="color: #339933;">=</span><span style="color: #0000ff;">"library://ns.adobe.com/flex/spark"</span> xmlns<span style="color: #339933;">:</span>mx<span style="color: #339933;">=</span><span style="color: #0000ff;">"library://ns.adobe.com/flex/halo"</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Apanel+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Panel</span></a> title<span style="color: #339933;">=</span><span style="color: #0000ff;">"Horizontal Panel"</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">"300"</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">"220"</span> left<span style="color: #339933;">=</span><span style="color: #0000ff;">"20"</span> top<span style="color: #339933;">=</span><span style="color: #0000ff;">"20"</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>Scroller width<span style="color: #339933;">=</span><span style="color: #0000ff;">"100%"</span> height<span style="color: #339933;">=</span><span style="color: #0000ff;">"100%"</span><span style="color: #339933;">&gt;</span>
        <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>Group<span style="color: #339933;">&gt;</span>
           <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
               <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>HorizontalLayout useVirtualLayout<span style="color: #339933;">=</span><span style="color: #0000ff;">"true"</span> <span style="color: #339933;">/&gt;</span>
           <span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>layout<span style="color: #339933;">&gt;</span>
           <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span>TextInput <span style="color: #339933;">/&gt;</span>
           <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> label<span style="color: #339933;">=</span><span style="color: #0000ff;">"clear"</span> <span style="color: #339933;">/&gt;</span>
           <span style="color: #339933;">&lt;</span>mx<span style="color: #339933;">:</span>DateChooser <span style="color: #339933;">/&gt;</span>
           <span style="color: #339933;">&lt;</span>s<span style="color: #339933;">:</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Abutton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Button</span></a> label<span style="color: #339933;">=</span><span style="color: #0000ff;">"submit"</span> <span style="color: #339933;">/&gt;</span>
        <span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>Group<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>Scroller<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>Panel<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>s<span style="color: #339933;">:</span>Application<span style="color: #339933;">&gt;

</span>上面的代码中我们通过使用Scroller控件给Group容器加上了滚动条，如果把Scroll放在Panel的外面则滚动条出现在Panel的外部。
<pre style="font-family: monospace;">
<pre style="font-family: monospace;">编译运行上面的代码
<img class="alignnone size-full wp-image-537" title="Flash_Builder_4_5Z_1J_layout_1" src="http://www.flextheworld.com/wp-content/uploads/2009/06/Flash_Builder_4_5Z_1J_layout_1.jpg" alt="Flash_Builder_4_5Z_1J_layout_1" width="349" height="387" /></pre>
</pre>
<p>对布局的基本介绍就到这里，同学们可以到<a title="http://livedocs.adobe.com/flex/gumbo/html/WSD42D542D-CEFF-47e2-AFD5-C11F3E9B5AE2.html" rel="nofollow" href="http://livedocs.adobe.com/flex/gumbo/html/WSD42D542D-CEFF-47e2-AFD5-C11F3E9B5AE2.html">Spark Layout Specification</a> 查看更详细的内容。</p>
<h2>本节源码</h2>
<p><a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=14" title=" downloaded 309 times" >Layout Demo (309)</a></pre>
</pre>
<h2>总结</h2>
<p>布局在Flex 4中有了很大的变化，就像我刚才提到的，布局的解耦让我们对容器，控件的界面操作变得更加灵活与合理。不过Flex 3中的布局方式仍然在mx控件中有效，所以我们也不必担心Flex 3程序向Flex 4移植的问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/06/flex4-layout.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex 迷你教程 &#8212; Flex SDK 4新特性：主题</title>
		<link>http://www.flextheworld.com/2009/06/flex4-heme.html</link>
		<comments>http://www.flextheworld.com/2009/06/flex4-heme.html#comments</comments>
		<pubDate>Tue, 16 Jun 2009 07:04:47 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[Flash Builder 4]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[Flex gumbo]]></category>
		<category><![CDATA[Flex 主题]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=511</guid>
		<description><![CDATA[这次的教程主要针对Flex SDK 4的新特性，一共有12篇。会全部收录在airia.cn出品的《Flash Builder 4 入门教学》中，这本电子教程现正在编辑阶段，里面包含了所有Flash Builder 4新增加内容的介绍，使用教程等，希望在它发布之后大家能够喜欢。现在我将部分的内容提前放出，也算是预告片  
简介
学习Flex SDK 4的新特性 &#8212; 主题
学习目标

切换Flash Builder 4自带的多款主题。
知道主题的存放位置。
知道主题应用的原理。

准备工作
下载并安装Flash Builder 4
实现步骤
在Flash Builder 4以前，Adobe默认的主题是Halo, 而从Flash Builder 4开始，默认的主题变成了Spark, Spark主题中使用了很多图片作为控件的皮肤，因此Spark只支持部分的色彩样式, 它们是baseColor, color, contentBackgroundColor, focusColor, symbolColor, selectionColor, and rollOverColor,如果同学们想改变一些控件的背景，比如Button的背景样式，我们需要重新定义背景的skin图片才可以做到。当然我们也 可以使用原来的Halo主题。现在我们就来看看如何使用主题。
Flash Builder 4中包含了9款默认主题，其中两款Spark主题，七款Halo主题。这里有必要提一提它们的区别，在Flash Builder 4中，由于出现了新的library://ns.adobe.com/flex/spark (xmlns:s)名称空间,代表新的spark.*包中的控件，所以Flash Builder 4 中同时存在了原来的mx.*以及spark.*中的两组控件。因此在Flash Builder 4中css style也加入了名称空间的支持，比如

?View Code CSS@namespace s &#34;library://ns.adobe.com/flex/spark&#34;;
@namespace mx &#34;library://ns.adobe.com/flex/halo&#34;;
&#160;
s&#124;Button &#123;
color: #FF0000;
&#125;
&#160;
mx&#124;DateChooser &#123;
color: #FF0000;
&#125;

其中S&#124;Button 代表了Spark包中Button的样式，mx&#124;DateChooser则代表mx包中DateChooser的样式。
回到我们的主题选择，首先创建一个名为HelloWorld的Flex项目。接下来
1. [...]]]></description>
			<content:encoded><![CDATA[<p>这次的教程主要针对Flex SDK 4的新特性，一共有12篇。会全部收录在airia.cn出品的《Flash Builder 4 入门教学》中，这本电子教程现正在编辑阶段，里面包含了所有Flash Builder 4新增加内容的介绍，使用教程等，希望在它发布之后大家能够喜欢。现在我将部分的内容提前放出，也算是预告片 <img src='http://www.flextheworld.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>简介</h2>
<p>学习Flex SDK 4的新特性 &#8212; 主题</p>
<h2><strong>学习目标</strong></h2>
<ol>
<li>切换Flash Builder 4自带的多款主题。</li>
<li>知道主题的存放位置。</li>
<li>知道主题应用的原理。<span id="more-511"></span></li>
</ol>
<h2>准备工作</h2>
<p>下载并安装<a href="http://www.adobe.com/go/flashbuilder4_download&quot; rel=&quot;nofollow&quot; href=&quot;http://www.adobe.com/go/flashbuilder4_downloadflashbuilder4_download" target="_blank">Flash Builder 4</a></p>
<h2>实现步骤</h2>
<p>在Flash Builder 4以前，Adobe默认的主题是Halo, 而从Flash Builder 4开始，默认的主题变成了Spark, Spark主题中使用了很多图片作为控件的皮肤，因此Spark只支持部分的色彩样式, 它们是baseColor, color, contentBackgroundColor, focusColor, symbolColor, selectionColor, and rollOverColor,如果同学们想改变一些控件的背景，比如Button的背景样式，我们需要重新定义背景的skin图片才可以做到。当然我们也 可以使用原来的Halo主题。现在我们就来看看如何使用主题。</p>
<p>Flash Builder 4中包含了9款默认主题，其中两款Spark主题，七款Halo主题。这里有必要提一提它们的区别，在Flash Builder 4中，由于出现了新的library://ns.adobe.com/flex/spark (xmlns:s)名称空间,代表新的spark.*包中的控件，所以Flash Builder 4 中同时存在了原来的mx.*以及spark.*中的两组控件。因此在Flash Builder 4中css style也加入了名称空间的支持，比如</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p511code15'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p51115"><td class="code" id="p511code15"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@namespace s &quot;library://ns.adobe.com/flex/spark&quot;;</span>
<span style="color: #a1a100;">@namespace mx &quot;library://ns.adobe.com/flex/halo&quot;;</span>
&nbsp;
s|Button <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FF0000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
mx|DateChooser <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FF0000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>其中S|Button 代表了Spark包中Button的样式，mx|DateChooser则代表mx包中DateChooser的样式。</p>
<p>回到我们的主题选择，首先创建一个名为HelloWorld的Flex项目。接下来</p>
<p><strong>1. 右键点击项目，选择属性</strong></p>
<p><img class="alignnone size-full wp-image-516" title="theme_1" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_1.jpg" alt="theme_1" width="357" height="494" /></p>
<p><strong>2. 选择Flex主题。</strong></p>
<p>同学们可以看到右边显示了8款主题，其中第九款，也就是Halo.swc是没有显示在这里的，我们需要用导入主题的方式将其加入，我们在这里双击WireFrame主题。</p>
<p><img class="alignnone size-full wp-image-517" title="theme_2" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_2.jpg" alt="theme_2" width="779" height="429" /></p>
<p>在HelloWorld.mxml中插入下面代码并编译运行 (代码中的布局方式也改变了，详情请查看布局章节)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p511code16'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p51116"><td class="code" id="p511code16"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Application</span> <span style="color: #000066;">xmlns:fx</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/mxml/2009&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:s</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/spark&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;library://ns.adobe.com/flex/halo&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">minWidth</span>=<span style="color: #ff0000;">&quot;1024&quot;</span> <span style="color: #000066;">minHeight</span>=<span style="color: #ff0000;">&quot;768&quot;</span> <span style="color: #000066;">preloader</span>=<span style="color: #ff0000;">&quot;mx.preloaders.DownloadProgressBar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:HGroup</span>  <span style="color: #000066;">gap</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">horizontalCenter</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">top</span>=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Panel</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Spark Panel&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:HorizontalLayout</span> <span style="color: #000066;">paddingLeft</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">paddingTop</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:layout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>	
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;s:Button</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Spark 按钮&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 		
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:HGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/s:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>左图是默认的spark样式，右图是切换wireframe样式后运行的结果<br />
<img class="alignnone size-full wp-image-523" title="theme_4" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_4.jpg" alt="theme_4" width="222" height="229" /><br />
<span style="color: #ff0000;"><strong>注: 如果同学们选择的是Halo系列的主题，那么这里运行后仍然看到的会是Spark主题，这是因为Halo主题只对mx.controls里的控件有效，稍后会为同学们演示。</strong></span></p>
<p><strong>3. 我们已经知道了如何切换主题，现在来看看主题的存放位置以及主题是如何被应用的</strong></p>
<p>主题的默认存放位置在<br />
<span style="color: #ff0000;"><strong>Flash Builder 4安装目录/sdks/4.0.0/frameworks/themes/</strong></span></p>
<p>打开后会看见9个文件夹，分别对应一个主题。我们在HelloWorld项目文件夹中打开配置文件.actionScriptProperties。<br />
下图中红色框部分表示了主题的配置。</p>
<p><img class="alignnone size-full wp-image-524" title="theme_5" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_5.jpg" alt="theme_5" width="530" height="494" /></p>
<p>我们继续来看看主题包里都用什么，将wireframe.swc改名为wireframe.zip，解压。解压后可见下面这些文件。</p>
<p><img class="alignnone size-full wp-image-525" title="theme_6" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_6.jpg" alt="theme_6" width="265" height="113" /></p>
<p>很明显default.css是主题的样式设置，我们可以对其修改以改变主题的配置。注意default.css中的名称空间 @namespace &#8220;library://ns.adobe.com/flex/spark&#8221;; 表示了他对spark系列的控件有效。</p>
<p>好了，以上就是Flash Builder 4中对主题的选择。现在我们来继续扩展一些内容。刚才我提到spark以及wireframe主题只对spark包中的控件有效，也就是对Flex Builder 3中的控件是没有效果的，我们来做个实验。将下面的代码放入HelloWorld.mxml，我在其中加入了mx:Panel以及mx: Button。现在同样选择wireframe主题，运行。我们可以看到下图的效果。</p>
<p><img class="alignnone size-full wp-image-526" title="theme_7" src="http://www.flextheworld.com/wp-content/uploads/2009/06/theme_7.jpg" alt="theme_7" width="520" height="379" /></p>
<p>右边的mx Panel以及Button显示了默认的Spark样式，说明了wireframe的设置对其无效。那么是否可以继续使用flex builder 3中的样式呢？当然可以，在themes文件夹中的Halo就代表了Flex 3中的默认样式，我们再次打开样式选择面板，点击“导入样式”，选择Halo文件夹中的halo.swc导入。之后我们在Other 一栏里会看见它，见下图</p>
<p><img class="alignnone size-full wp-image-527" title="flash_builder_4_5z_1j_3d_theme_8" src="http://www.flextheworld.com/wp-content/uploads/2009/06/flash_builder_4_5z_1j_3d_theme_8.jpg" alt="flash_builder_4_5z_1j_3d_theme_8" width="524" height="350" /></p>
<p>双击导入，再次运行刚才的代码</p>
<p><img class="alignnone size-full wp-image-528" title="flash_builder_4_5z_1j_3d_theme_9" src="http://www.flextheworld.com/wp-content/uploads/2009/06/flash_builder_4_5z_1j_3d_theme_9.jpg" alt="flash_builder_4_5z_1j_3d_theme_9" width="519" height="310" /><br />
同学们可以看到右侧已经显示了我们熟悉的Flex 3中的默认样式，而左侧的Spark控件仍然显示了Spark的默认样式。</p>
<h3>本节源码</h3>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=13" title=" downloaded 278 times" >Flex4 Theme Demo (278)</a>
<h2>总结</h2>
<p>本节中介绍了Flash Builder 4中主题的使用方法，现在的方式让主题的开发与使用更加的规范化，相信以后会出现越来越多更加实用，漂亮的主题</p>
<h2>思考</h2>
<p>如何让Spark与mx控件同时应用一款主题?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/06/flex4-heme.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flex迷你教程 &#8212; SDK3.2+TweenLite实现Amazon window shop 3D浏览效果</title>
		<link>http://www.flextheworld.com/2009/03/flex-3d-amazon-window.html</link>
		<comments>http://www.flextheworld.com/2009/03/flex-3d-amazon-window.html#comments</comments>
		<pubDate>Wed, 18 Mar 2009 15:26:15 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[TweenLite]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=469</guid>
		<description><![CDATA[从 Flex SDK3.2开始，Adobe 对所有可视化控件增加了3D控制属性 rotationX, rotationY, rotaionZ, Z等。今天就用这四个属性模拟亚马逊的Windowshop (http://www.windowshop.com/)，当然这里只是为了演示在Flex SDK 3.2+中我们可以比较容易的实现这样的效果，代码中并没有研究自动对焦到任意图片的算法，只是模拟对焦到两张图片。
Demo中用到了TweenLite对坐标变换进行动画效果处理，TweenLite在众多Tween package中效率是上乘的。在这里下载.
亚马逊 window shop截图:

Demo:
点击Demo中的按钮会对焦放大到响应图片，移动Slider bar尝试3D变换.


进入演示
源文件下载:


]]></description>
			<content:encoded><![CDATA[<p>从 Flex SDK3.2开始，Adobe 对所有可视化控件增加了3D控制属性 rotationX, rotationY, rotaionZ, Z等。今天就用这四个属性模拟亚马逊的Windowshop (http://www.windowshop.com/)，当然这里只是为了演示在Flex SDK 3.2+中我们可以比较容易的实现这样的效果，代码中并没有研究自动对焦到任意图片的算法，只是模拟对焦到两张图片。<span id="more-469"></span></p>
<p>Demo中用到了TweenLite对坐标变换进行动画效果处理，TweenLite在众多Tween package中效率是上乘的。在<a href="http://blog.greensock.com/tweenliteas3/" target="_blank">这里下载</a>.</p>
<p>亚马逊 window shop截图:</p>
<p><img class="alignnone size-full wp-image-470" title="amazon" src="http://www.flextheworld.com/wp-content/uploads/2009/03/amazon.jpg" alt="amazon" width="523" height="269" /></p>
<p>Demo:</p>
<p>点击Demo中的按钮会对焦放大到响应图片，移动Slider bar尝试3D变换.<strong><br />
</strong></p>
<p><a href="http://www.flextheworld.com/flash/AmazonWindowDemo.swf" rel="shadowbox[post-469];width=640;height=385;" target="_blank"><img class="alignnone size-full wp-image-475" title="demo1" src="http://www.flextheworld.com/wp-content/uploads/2009/03/demo1.jpg" alt="demo1" width="520" height="448" /></a></p>
<h3><a href="http://www.flextheworld.com/flash/AmazonWindowDemo.swf" rel="shadowbox[post-469];width=640;height=385;" target="_blank">进入演示</a></h3>
<h3>源文件下载:</h3>
<p><!--easy2hide start--><br />
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=10" title=" downloaded 638 times" >SourceFile (638)</a><br />
<!--easy2hide end--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/03/flex-3d-amazon-window.html/feed</wfw:commentRss>
		<slash:comments>233</slash:comments>
		</item>
		<item>
		<title>Flex 迷你教程 — 基于Stratus的P2P网络电话 (3)</title>
		<link>http://www.flextheworld.com/2009/01/flex-stratus-phone-3.html</link>
		<comments>http://www.flextheworld.com/2009/01/flex-stratus-phone-3.html#comments</comments>
		<pubDate>Sat, 17 Jan 2009 14:40:07 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[P2P]]></category>
		<category><![CDATA[FMS]]></category>
		<category><![CDATA[Stratus]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=276</guid>
		<description><![CDATA[在Flex 迷你教程 — 基于Stratus的P2P网络电话 (2)中我们已经知道如何链接一个客户端并且互相发送短信，今天来扩展下面的这些内容

呼叫时在被呼叫端显示 &#8220;接受&#8221;，点击接受后双方建立链接。
呼叫试或者接通后可以挂机。
添加视频与音频通信。

首先来看看Demo:
Demo 操作:
1. 输入任意名称，点击链接 （两台机器或者两个浏览器）
2. 输入对方的peerId，点击呼叫
3. 被呼叫方点击 &#8220;接受&#8221; 建立链接。
4. 开始语音，视频，文字通讯.
5. 挂机
Demo地址:
http://flextheworld.com/flash/p2p/P2pPhoneDemo.html

Demo截图:

新添加的代码
首先是修改call() function, 根据不同的label执行不同的事件，如果callYou.label是 &#8220;接受&#8221;，执行accpetHandle()与呼叫者建立链接，如果是&#8221;挂断&#8221;，那么执行hangup()挂断双方的通讯，如果是其他(也就是&#8221;呼叫&#8221;)，则执行后面的内容。
呼叫时调用publishVide和publishAudio将视频与音频附加到outgoingStream发送。在onConnectSuccesss事件中播放被呼叫者返回的视频和音频。监听onHangup事件来控制挂断。呼叫时将“呼叫”改为“挂断”。

?View Code ACTIONSCRIPT3//呼叫对方的方法，现在是呼叫者角色
private function call&#40;&#41;:void&#123;
&#160;
if&#40;callYou.label == &#34;接受&#34;&#41;&#123;
accpetHandle&#40;&#41;;
callYou.label = &#34;挂断&#34;
return;
&#125;else if&#40;callYou.label == &#34;挂断&#34;&#41;&#123;
outgoingStream.send&#40;&#34;onHangup&#34;&#41;
this.hangup&#40;&#41;
&#160;
return;
&#125;
&#160;
...............
&#160;
//发送视频
publishVideo&#40;&#41;;
//发送音频
publishAudio&#40;&#41;
&#160;
..........
&#160;
//监听onConnectSuccess事件，确定链接成功
i.onConnectSuccess = function&#40;name:String&#41;:void
&#123;
info.text += &#34;与&#34;+name + &#34;链接成功n&#34;;
sendMessageBtn.enabled = true;
incomingStream.receiveAudio&#40;true&#41;
incomingStream.receiveAudio&#40;true&#41;
remoteVideo = new Video&#40;&#41;;
remoteVideo.width = 160;
remoteVideo.height = 120;
remoteVideo.attachNetStream&#40;incomingStream&#41;;
remoteVideoDisplay.addChild&#40;remoteVideo&#41;;
sendMessageBtn.enabled = true;
&#125;
&#160;
i.onHangup = function&#40;&#41;:void&#123;
hangup&#40;&#41;
&#125;
&#160;
incomingStream.client = i
&#160;
callYou.label = &#34;挂断&#34;

被呼叫者在监听到呼叫者的呼叫时不马上回应，只是提示被呼叫者 “正在被链接”，同时将“呼叫”改为“接受”, 监听onHangup事件

?View Code [...]]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://www.flextheworld.com/2009/01/flex-stratus-phone-2.html" target="_blank">Flex 迷你教程 — 基于Stratus的P2P网络电话 (2)</a>中我们已经知道如何链接一个客户端并且互相发送短信，今天来扩展下面的这些内容</p>
<ol>
<li>呼叫时在被呼叫端显示 &#8220;接受&#8221;，点击接受后双方建立链接。</li>
<li>呼叫试或者接通后可以挂机。</li>
<li>添加视频与音频通信。</li>
</ol>
<h2>首先来看看Demo:</h2>
<p><strong>Demo 操作:</strong></p>
<p>1. 输入任意名称，点击链接 （两台机器或者两个浏览器）<br />
2. 输入对方的peerId，点击呼叫<br />
3. 被呼叫方点击 &#8220;接受&#8221; 建立链接。<br />
4. 开始语音，视频，文字通讯.<br />
5. 挂机</p>
<p><strong>Demo地址:</strong></p>
<p><a href="http://flextheworld.com/flash/p2p/P2pPhoneDemo.html" target="_blank">http://flextheworld.com/flash/p2p/P2pPhoneDemo.html</a></p>
<p><a href="http://flextheworld.com/flash/p2p/P2pPhoneDemo.html" target="_blank"><span id="more-276"></span></a></p>
<p><strong>Demo截图:</strong></p>
<p><img class="alignnone size-full wp-image-279" title="e59bbee78987-1" src="http://www.flextheworld.com/wp-content/uploads/2009/01/e59bbee78987-1.jpg" alt="e59bbee78987-1" width="640" height="400" /></p>
<h2>新添加的代码</h2>
<p>首先是修改call() function, 根据不同的label执行不同的事件，如果callYou.label是 &#8220;接受&#8221;，执行accpetHandle()与呼叫者建立链接，如果是&#8221;挂断&#8221;，那么执行hangup()挂断双方的通讯，如果是其他(也就是&#8221;呼叫&#8221;)，则执行后面的内容。</p>
<p>呼叫时调用publishVide和publishAudio将视频与音频附加到outgoingStream发送。在onConnectSuccesss事件中播放被呼叫者返回的视频和音频。监听onHangup事件来控制挂断。呼叫时将“呼叫”改为“挂断”。</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p276code22'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27622"><td class="code" id="p276code22"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//呼叫对方的方法，现在是呼叫者角色</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>callYou<span style="color: #000066; font-weight: bold;">.</span>label == <span style="color: #990000;">&quot;接受&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
accpetHandle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
callYou<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;挂断&quot;</span>
<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>callYou<span style="color: #000066; font-weight: bold;">.</span>label == <span style="color: #990000;">&quot;挂断&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onHangup&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>hangup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">...............</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//发送视频</span>
publishVideo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//发送音频</span>
publishAudio<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">..........</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//监听onConnectSuccess事件，确定链接成功</span>
i<span style="color: #000066; font-weight: bold;">.</span>onConnectSuccess = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;与&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;链接成功n&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
sendMessageBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>
remoteVideo = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">160</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">120</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachNetStream</span><span style="color: #000000;">&#40;</span>incomingStream<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideoDisplay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>remoteVideo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
sendMessageBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
i<span style="color: #000066; font-weight: bold;">.</span>onHangup = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
hangup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = i
&nbsp;
callYou<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;挂断&quot;</span></pre></td></tr></table></div>

<p>被呼叫者在监听到呼叫者的呼叫时不马上回应，只是提示被呼叫者 “正在被链接”，同时将“呼叫”改为“接受”, 监听onHangup事件</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p276code23'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27623"><td class="code" id="p276code23"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initSendStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">..........</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//监听onPeerConnect事件</span>
<span style="color: #6699cc; font-weight: bold;">var</span> o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
o<span style="color: #000066; font-weight: bold;">.</span>onPeerConnect = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>subscriberStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a>
<span style="color: #000000;">&#123;</span>
<span style="color: #000066; font-weight: bold;">..........</span>
&nbsp;
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>
<span style="color: #000066; font-weight: bold;">..........</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//监听onIncomingCall事件，用于确定链接成功</span>
i<span style="color: #000066; font-weight: bold;">.</span>onIncomingCall = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #009900; font-style: italic;">//显示链接成功后，对呼叫者发布我的信息流，名称为callee</span>
<span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; 正在呼叫你n&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
callYou<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;接受&quot;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
i<span style="color: #000066; font-weight: bold;">.</span>onHangup = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
hangup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = i<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
myStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = o<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>点击“接受”后，开始向呼叫者发送信息流，包括视频与音频。同时播放呼叫者发送的视频与音频，最后发出onConnectSuccess事件</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p276code24'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27624"><td class="code" id="p276code24"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//同意链接后，发送stream到呼叫端，包括音频，视频的发送。 同时播放呼叫端发出的视频，音频</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> accpetHandle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
<span style="color: #009900; font-style: italic;">//向呼叫端发送信息流</span>
outgoingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">.</span>DIRECT_CONNECTIONS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> outgoingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;callee&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//将视频，音频附加到outgoingStream</span>
publishAudio<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
publishVideo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//播放接受到的视频，音频</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">receiveAudio</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span>
remoteVideo = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">160</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">120</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachNetStream</span><span style="color: #000000;">&#40;</span>incomingStream<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
remoteVideoDisplay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>remoteVideo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #009900; font-style: italic;">//链接成功事件，呼叫端响应</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onConnectSuccess&quot;</span><span style="color: #000066; font-weight: bold;">,</span>userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
sendMessageBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>点击挂机后在上面提到的call()中执行hangup(), 同时发送onHangup事件，这样另一方也能挂断电话。挂机后将&#8221;挂机&#8221;再改为&#8221;呼叫&#8221;，允许下一次的呼叫和链接</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p276code25'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27625"><td class="code" id="p276code25"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//挂断电话，清空所有stream，只保持于stratus的链接</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> hangup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>incomingStream<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> incomingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>outgoingStream<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> outgoingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>controlStream<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
controlStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
controlStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> netStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
incomingStream = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
outgoingStream = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
controlStream = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>localVideo <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
localVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>remoteVideo <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
remoteVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;挂机！&quot;</span>
callYou<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;呼叫&quot;</span>
sendMessageBtn<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">enabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>publishVideo和publishAudio function</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p276code26'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p27626"><td class="code" id="p276code26"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//发送视频</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> publishVideo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> cameras<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">names</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> camera<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> findDefaultCamera<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a> = <span style="color: #0033ff; font-weight: bold;">false</span>
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cameras <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> cameras<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span>cameras<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>cameras<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == <span style="color: #990000;">&quot;USB Video Class Video&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
camera = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
findDefaultCamera = <span style="color: #0033ff; font-weight: bold;">true</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>findDefaultCamera<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
camera = <a href="http://www.google.com/search?q=camera%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:camera.html"><span style="color: #004993;">Camera</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getCamera</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
camera<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setQuality</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;">90</span><span style="color: #000000;">&#41;</span>
&nbsp;
localVideo = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=video%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:video.html"><span style="color: #004993;">Video</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
localVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">160</span><span style="color: #000066; font-weight: bold;">;</span>
localVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">120</span><span style="color: #000066; font-weight: bold;">;</span>
localVideo<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachCamera</span><span style="color: #000000;">&#40;</span>camera<span style="color: #000000;">&#41;</span>
localVideoDisplay<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>localVideo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #009900; font-style: italic;">//发送音频</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> publishAudio<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> mics<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=array%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:array.html"><span style="color: #004993;">Array</span></a> = <a href="http://www.google.com/search?q=microphone%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:microphone.html"><span style="color: #004993;">Microphone</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">names</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>mics <span style="color: #000066; font-weight: bold;">&amp;</span>amp<span style="color: #000066; font-weight: bold;">;&amp;</span>amp<span style="color: #000066; font-weight: bold;">;</span> mics<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">attachAudio</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=microphone%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:microphone.html"><span style="color: #004993;">Microphone</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getMicrophone</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h2>源文件下载 (装了一个类似论坛的回复才能下载的插件，试试)</h2>
<p><!--easy2hide start--><br />
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=5" title="Version1 downloaded 871 times" >P2pPhoneDemo3 (871)</a><br />
<!--easy2hide end--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/flex-stratus-phone-3.html/feed</wfw:commentRss>
		<slash:comments>347</slash:comments>
		</item>
		<item>
		<title>Flex 迷你教程 — 基于Stratus的P2P网络电话 (2)</title>
		<link>http://www.flextheworld.com/2009/01/flex-stratus-phone-2.html</link>
		<comments>http://www.flextheworld.com/2009/01/flex-stratus-phone-2.html#comments</comments>
		<pubDate>Sat, 10 Jan 2009 08:53:39 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[FMS]]></category>
		<category><![CDATA[Flex 迷你教程]]></category>
		<category><![CDATA[P2P]]></category>
		<category><![CDATA[Stratus]]></category>
		<category><![CDATA[网络电话]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=248</guid>
		<description><![CDATA[接上篇，这一讲里我告诉大家如何链接另一个flash客户端，并且发送文字信息，在下一讲中会引入更多的内容，比如，“是否接收对方呼叫”，“语音和视频的发送” 等等。
看这篇教程时一定要把自己分成“呼叫者”和“被呼叫者”两个身份来看，否者有可能会看得头晕，呵呵。现在我们开始。
1. 首先了解一下我们会用到的变量, 这里要最主要的四个NetStream，他们的作用请看注释。


?View Code ACTIONSCRIPT3//链接Adobe stratus 服务器
private const StratusAddress:String = &#34;rtmfp://stratus.adobe.com&#34;;
&#160;
//Developer Key,如果没有请根据Flex 迷你教程 -- 基于Stratus的P2P网络电话 (1)中的提示申请
private const DeveloperKey:String = &#34;xxxxxx&#34;;
&#160;
//我们需要一个nectConnetion与stratus 服务器链接
private var netConnection:NetConnection;
&#160;
//用于对外发布自己的身份信息流
private var myStream:NetStream;
&#160;
//用于链接后对外发布自己的信息流，比如音频，视频，文字
private var outgoingStream:NetStream;
&#160;
//进入的信息流，这个流对应呼叫者的outgoingStream，用这个流尝试播放发布者发布的信息，比如音频，视频，文字
private var incomingStream:NetStream;
&#160;
//用于尝试播放被呼叫者的身份信息流myStream发送的信息，被呼叫者在发送自己的身份信息流时会监听呼叫者对myStream的播放请求
private var controlStream:NetStream;

2. 下面是主要用到的方法。
呼叫者的主要方法/事件触发顺序，
init()
netConnectionHandler() &#8212; case &#8220;NetConnection.Connect.Success&#8221;:
initSendStream();
call();
onConnectSuccess()
onIm()
被呼叫者主要方法／事件的调用触发顺序
init()
netConnectionHandler() &#8212; case &#8220;NetConnection.Connect.Success&#8221;:
initSendStream();
onPeerConnect();
onIncomingCall();
onIm();
3. Demo (请打开两个浏览器进行Demo) :
操作方法:

任意填写用户名，点击链接。
在另一个浏览器同样登陆。
用其中一个的peerid作为链接ID呼叫对方。
链接成功后可以信息聊天。


4. 源代码下载与主要方法代码，学习请看注释，写的很清楚
输入用户名，点击 “链接”时触发下面的代码

?View Code ACTIONSCRIPT3//链接 adobe stratus 服务器
private function init&#40;&#41;:void&#123;
&#160;
	if&#40;userName.text == &#34;&#34;&#41;
	&#123;
		Alert.show&#40;&#34;请输入任意用户名&#34;,&#34;错误&#34;&#41;
		return
	&#125;
	netConnection = new [...]]]></description>
			<content:encoded><![CDATA[<p>接上篇，这一讲里我告诉大家如何链接另一个flash客户端，并且发送文字信息，在下一讲中会引入更多的内容，比如，“是否接收对方呼叫”，“语音和视频的发送” 等等。</p>
<p>看这篇教程时一定要把自己分成“呼叫者”和“被呼叫者”两个身份来看，否者有可能会看得头晕，呵呵。现在我们开始。</p>
<h2>1. 首先了解一下我们会用到的变量, 这里要最主要的四个NetStream，他们的作用请看注释。</h2>
<p><span id="more-248"></span></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code34'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24834"><td class="code" id="p248code34"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//链接Adobe stratus 服务器</span>
<span style="color: #0033ff; font-weight: bold;">private</span> const StratusAddress<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;rtmfp://stratus.adobe.com&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//Developer Key,如果没有请根据Flex 迷你教程 -- 基于Stratus的P2P网络电话 (1)中的提示申请</span>
<span style="color: #0033ff; font-weight: bold;">private</span> const DeveloperKey<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;xxxxxx&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//我们需要一个nectConnetion与stratus 服务器链接</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> netConnection<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netconnection%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netconnection.html"><span style="color: #004993;">NetConnection</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//用于对外发布自己的身份信息流</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> myStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//用于链接后对外发布自己的信息流，比如音频，视频，文字</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> outgoingStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//进入的信息流，这个流对应呼叫者的outgoingStream，用这个流尝试播放发布者发布的信息，比如音频，视频，文字</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> incomingStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//用于尝试播放被呼叫者的身份信息流myStream发送的信息，被呼叫者在发送自己的身份信息流时会监听呼叫者对myStream的播放请求</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> controlStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div>

<h2>2. 下面是主要用到的方法。</h2>
<h3>呼叫者的主要方法/事件触发顺序，</h3>
<p>init()<br />
netConnectionHandler() &#8212; case &#8220;NetConnection.Connect.Success&#8221;:<br />
initSendStream();<br />
call();<br />
onConnectSuccess()<br />
onIm()</p>
<h3>被呼叫者主要方法／事件的调用触发顺序</h3>
<p>init()<br />
netConnectionHandler() &#8212; case &#8220;NetConnection.Connect.Success&#8221;:<br />
initSendStream();<br />
onPeerConnect();<br />
onIncomingCall();<br />
onIm();</p>
<h2>3. Demo (请打开两个浏览器进行Demo) :</h2>
<h3>操作方法:</h3>
<ol>
<li>任意填写用户名，点击链接。</li>
<li>在另一个浏览器同样登陆。</li>
<li>用其中一个的peerid作为链接ID呼叫对方。</li>
<li>链接成功后可以信息聊天。</li>
</ol>
<p><object width="520" height="516" data="http://www.flextheworld.com/flash/P2pPhoneDemo.swf" type="application/x-shockwave-flash"><param name="src" value="http://www.flextheworld.com/flash/P2pPhoneDemo.swf" /></object></p>
<h2>4. 源代码下载与主要方法代码，学习请看注释，写的很清楚</h2>
<h3>输入用户名，点击 “链接”时触发下面的代码</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code35'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24835"><td class="code" id="p248code35"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//链接 adobe stratus 服务器</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> == <span style="color: #990000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;请输入任意用户名&quot;</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #990000;">&quot;错误&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span>
	<span style="color: #000000;">&#125;</span>
	netConnection = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netconnection%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netconnection.html"><span style="color: #004993;">NetConnection</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	netConnection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> netConnectionHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	netConnection<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">connect</span><span style="color: #000000;">&#40;</span>StratusAddress <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;/&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> DeveloperKey<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//服务器地址里需要开发者Key</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>与stratus链接成功后在case &#8220;NetConnection.Connect.Success&#8221;里调用下面的方法</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code36'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24836"><td class="code" id="p248code36"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initSendStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//这三行表示我对外发布一个名称为netConnection.nearID的流，呼叫者通过我的nearID与我链接后，如果播放</span>
	<span style="color: #009900; font-style: italic;">//这个名称为netConnection.nearID的流，会出发onPeerConnect事件，这样我就知道有人链接我</span>
	myStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">.</span>DIRECT_CONNECTIONS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	myStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> netStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	myStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">.</span>nearID<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//监听onPeerConnect事件</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> o<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	o<span style="color: #000066; font-weight: bold;">.</span>onPeerConnect = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>subscriberStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009900; font-style: italic;">//当我收到呼叫者的链接请求后，尝试播放呼叫者的流名为&quot;caller&quot;的流，farID代表呼叫者的唯一ID，也就是前面提到的nearID</span>
		<span style="color: #009900; font-style: italic;">//我通过farID找到呼叫者</span>
	    incomingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span>subscriberStream<span style="color: #000066; font-weight: bold;">.</span>farID<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> incomingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;caller&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #009900; font-style: italic;">//监听onIm事件，用于收取文字信息</span>
        <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
        i<span style="color: #000066; font-weight: bold;">.</span>onIm = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #009900; font-style: italic;">//监听onIncomingCall事件，用于确定链接成功</span>
        i<span style="color: #000066; font-weight: bold;">.</span>onIncomingCall = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
        <span style="color: #000000;">&#123;</span>
        	<span style="color: #009900; font-style: italic;">//显示链接成功后，对呼叫者发布我的信息流，名称为callee</span>
            <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; 已经与你链接<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
            outgoingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">.</span>DIRECT_CONNECTIONS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> outgoingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;callee&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onConnectSuccess&quot;</span><span style="color: #000066; font-weight: bold;">,</span>userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
        incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = i<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
        <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	myStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = o<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>呼叫者输入对方Peerid，点击呼叫后执行下面的代码</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code37'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24837"><td class="code" id="p248code37"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//通过对方的peerId链接被呼叫者，播放对方的身份信息流</span>
    controlStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span>peerId<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    controlStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> netStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    controlStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span>peerId<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//同时对外发布呼叫者的信息流</span>
    outgoingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">.</span>DIRECT_CONNECTIONS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> outgoingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;caller&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//尝试播放被呼叫者的信息流</span>
    incomingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> peerId<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> incomingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;callee&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;正在呼叫，请稍候...... <span style="">\n</span><span style="">\n</span>&quot;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//监听信息发布事件</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
    i<span style="color: #000066; font-weight: bold;">.</span>onIm = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #009900; font-style: italic;">//监听onConnectSuccess事件，确定链接成功</span>
     i<span style="color: #000066; font-weight: bold;">.</span>onConnectSuccess = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;与&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;链接成功<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span> 
&nbsp;
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = i
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>被呼叫者在收到呼叫时执行</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code38'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24838"><td class="code" id="p248code38"><pre class="actionscript3" style="font-family:monospace;">o<span style="color: #000066; font-weight: bold;">.</span>onPeerConnect = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span>subscriberStream<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a>
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">//当我收到呼叫者的链接请求后，尝试播放呼叫者的流名为&quot;caller&quot;的流，farID代表呼叫者的唯一ID，也就是前面提到的nearID</span>
	<span style="color: #009900; font-style: italic;">//我通过farID找到呼叫者</span>
    incomingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span>subscriberStream<span style="color: #000066; font-weight: bold;">.</span>farID<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> incomingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">play</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;caller&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #009900; font-style: italic;">//监听onIm事件，用于收取文字信息</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
    i<span style="color: #000066; font-weight: bold;">.</span>onIm = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #009900; font-style: italic;">//监听onIncomingCall事件，用于确定链接成功</span>
    i<span style="color: #000066; font-weight: bold;">.</span>onIncomingCall = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
    <span style="color: #000000;">&#123;</span>
    	<span style="color: #009900; font-style: italic;">//显示链接成功后，对呼叫者发布我的信息流，名称为callee</span>
        <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot; 已经与你链接<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
        outgoingStream = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000000;">&#40;</span>netConnection<span style="color: #000066; font-weight: bold;">,</span> <a href="http://www.google.com/search?q=netstream%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstream.html"><span style="color: #004993;">NetStream</span></a><span style="color: #000066; font-weight: bold;">.</span>DIRECT_CONNECTIONS<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=netstatusevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:netstatusevent.html"><span style="color: #004993;">NetStatusEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NET_STATUS</span><span style="color: #000066; font-weight: bold;">,</span> outgoingStreamHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">publish</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;callee&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
        outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onConnectSuccess&quot;</span><span style="color: #000066; font-weight: bold;">,</span>userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
    incomingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">client</span> = i<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>呼叫者与被呼叫者链接成功后执行</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code39'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24839"><td class="code" id="p248code39"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//监听onConnectSuccess事件，确定链接成功</span>
i<span style="color: #000066; font-weight: bold;">.</span>onConnectSuccess = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;与&quot;</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;链接成功<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h3>发送信息与接收信息代码</h3>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p248code40'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p24840"><td class="code" id="p248code40"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//用outgoingStream对外发布信息流</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
   <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
    outgoingStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;onIm&quot;</span><span style="color: #000066; font-weight: bold;">,</span>userName<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//监听信息发布事件</span>
<span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000066; font-weight: bold;">;</span>
i<span style="color: #000066; font-weight: bold;">.</span>onIm = <span style="color: #339966; font-weight: bold;">function</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #004993;">info</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">name</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<h2>源代码</h2>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=4" title="Version0.5 downloaded 1387 times" >P2PhoneDemo1 (1387)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/flex-stratus-phone-2.html/feed</wfw:commentRss>
		<slash:comments>108</slash:comments>
		</item>
	</channel>
</rss>
