<?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>RichMedia+ &#187; SharedObject</title>
	<atom:link href="http://blog.richmediaplus.com/tag/sharedobject/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.richmediaplus.com</link>
	<description>About the Adobe&#039;s RIA related solution and technology, like Adobe Air, Adobe Flex, Mobile Dev. You also can find the SEO for Flex, RIA, User Ex in this blog.</description>
	<lastBuildDate>Fri, 16 Dec 2011 09:33:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create Trail Information &amp; Expired Date in ActionScript3 &amp; Flex</title>
		<link>http://blog.richmediaplus.com/2009/04/create-trail-information-and-expired-date-in-actionscript3-and-flex3/</link>
		<comments>http://blog.richmediaplus.com/2009/04/create-trail-information-and-expired-date-in-actionscript3-and-flex3/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 09:39:36 +0000</pubDate>
		<dc:creator>Alvin / Aedis.Ju</dc:creator>
				<category><![CDATA[ActionScript Library]]></category>
		<category><![CDATA[ActionScript3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[richmediaplus Lab]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Expired Date]]></category>
		<category><![CDATA[richmediaplus library]]></category>
		<category><![CDATA[richmediaplus.trail.Trail]]></category>
		<category><![CDATA[SharedObject]]></category>
		<category><![CDATA[Trail Information]]></category>

		<guid isPermaLink="false">http://blog.richmediaplus.com/?p=124</guid>
		<description><![CDATA[在很多Flex的登錄窗口應用中，利用SharedObject可以完成記住帳號等問題。今天將給大家展示合理利用SharedObject完成的另外一個鮮為人知的秘密功能。 在流行OpenSource之前，很多Flex Component都是收費的，那收費肯定也會牽扯到Flex Component的試用。其實試用版和注冊版里面的功能是一樣的，就是多了幾個多用戶是否已經注冊的驗證判斷而已。 那我們怎么判斷用戶是否已經過期呢？請看下面的代碼（簡單是簡單了點，但其實思路上一樣的哦）： 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 [...]
Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2009/03/htmlformatforreducedatabasestorageinclient/' rel='bookmark' title='htmlFormat for Reduce DataBase Storage in Client'>htmlFormat for Reduce DataBase Storage in Client</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2009/10/use-textevent-link-set-trust-web-sites-solution/' rel='bookmark' title='TextEvent.LINK 建立安全信任網址跳轉方案'>TextEvent.LINK 建立安全信任網址跳轉方案</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><em>在很多Flex的登錄窗口應用中，利用SharedObject可以完成記住帳號等問題。今天將給大家展示合理利用SharedObject完成的另外一個鮮為人知的秘密功能。</em></p>
<p>在流行OpenSource之前，很多Flex Component都是收費的，那收費肯定也會牽扯到Flex Component的試用。其實試用版和注冊版里面的功能是一樣的，就是多了幾個多用戶是否已經注冊的驗證判斷而已。</p>
<p>那我們怎么判斷用戶是否已經過期呢？請看下面的代碼（簡單是簡單了點，但其實思路上一樣的哦）：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> trialErrorMessage<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;The trial period has been passed.&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> undefinedMessage<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;Unknow Error!&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>richmediaplus<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>DateUtils<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SharedObject</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SharedObjectFlushStatus</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #3f5fbf;">/**
 * 驗證是否已過試用期期。
 * @return True: 超出試用期; False: 試用期內
 * @author Alvin/AedisJu
 * @blog http://blog.richmediaplus.com
 */</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> checkExpDate<span style="color: #000000;">&#40;</span>className<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> <span style="color: #000000;">&#123;</span>
	trialErrorMessage = className <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;:: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> trialErrorMessage<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> so<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">SharedObject</span> = <span style="color: #004993;">SharedObject</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getLocal</span><span style="color: #000000;">&#40;</span>className<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>
	<span style="color: #6699cc; font-weight: bold;">var</span> strExpDate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = so<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>validateData<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//調試的時候記住清空啊！</span>
	<span style="color: #009900; font-style: italic;">//so.clear()</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//如果第一次使用，計算試用期過期時間。</span>
	<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>strExpDate == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> trailBeginDate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</span><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;">//效率，讓你10秒就過期啦！</span>
		trailBeginDate = DateUtils<span style="color: #000066; font-weight: bold;">.</span>dateAdd<span style="color: #000000;">&#40;</span>DateUtils<span style="color: #000066; font-weight: bold;">.</span>SECONDS<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">,</span> trailBeginDate<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		so<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>validateData = trailBeginDate<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> flushStatus<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
			flushStatus = so<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</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;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span>undefinedMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<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>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>flushStatus <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>
			<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>flushStatus<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #004993;">SharedObjectFlushStatus</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PENDING</span><span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span>undefinedMessage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
					<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: #009900; font-style: italic;">//trace(&quot;Requesting permission to save object...&quot;)</span>
					<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: #004993;">SharedObjectFlushStatus</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">FLUSHED</span><span style="color: #000066; font-weight: bold;">:</span>
					<span style="color: #009900; font-style: italic;">//trace(&quot;Value flushed to disk.&quot;)</span>
					<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900; font-style: italic;">//試用期過期時間與今天比較，如果今天已經超過試用期，則返回true。</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> strNowDate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Date</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Date</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>strExpDate <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> strNowDate<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		<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;
	<span style="color: #0033ff; font-weight: bold;">return</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>判斷寫好了，那么就加到Flex Component中去吧：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>richmediaplus<span style="color: #000066; font-weight: bold;">.</span>trail
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getQualifiedClassName</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>containers<span style="color: #000066; font-weight: bold;">.</span>Panel<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #3f5fbf;">/**
	 * TrailPanel
	 * @author Alvin/AedisJu
	 * @blog http://blog.richmediaplus.com
	 */</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> TrailPanel <span style="color: #0033ff; font-weight: bold;">extends</span> Panel
	<span style="color: #000000;">&#123;</span>
		include <span style="color: #990000;">&quot;trail.as&quot;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> TrailPanel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</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>checkExpDate<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;com.richmediaplus.trail.TrailPanel&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span>trialErrorMessage<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;">this</span><span style="color: #000066; font-weight: bold;">.</span>title = <span style="color: #990000;">&quot;Free trail product!&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>加到Flex Application里面：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Application xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>trail=<span style="color: #990000;">&quot;com.richmediaplus.trail.*&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>trail<span style="color: #000066; font-weight: bold;">:</span>TrailPanel <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;400&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>沒錯，就是這么簡單啦！<br />
看看過期后的反應如何!<br />
<div id="attachment_125" class="wp-caption aligncenter" style="width: 540px"><img class="size-full wp-image-125" title="Trail Error" src="http://blog.richmediaplus.com/wp-content/uploads/2009/04/trailerror.png" alt="Trail Error in ActionScript3 &amp; Flex" width="530" height="284" /><p class="wp-caption-text">Trail Error in ActionScript3 &amp; Flex</p></div></p>
<p>工程代碼下載：<a title="TrailExample" href="http://code.richmediaplus.com/TrailExample/TrailExample.rar" target="_blank">TrailExample.rar</a></p>
<p>Related posts:<ol>
<li><a href='http://blog.richmediaplus.com/2009/03/htmlformatforreducedatabasestorageinclient/' rel='bookmark' title='htmlFormat for Reduce DataBase Storage in Client'>htmlFormat for Reduce DataBase Storage in Client</a></li>
<li><a href='http://blog.richmediaplus.com/2011/05/flex-3-style-module/' rel='bookmark' title='Flex 3 Style Module'>Flex 3 Style Module</a></li>
<li><a href='http://blog.richmediaplus.com/2009/10/use-textevent-link-set-trust-web-sites-solution/' rel='bookmark' title='TextEvent.LINK 建立安全信任網址跳轉方案'>TextEvent.LINK 建立安全信任網址跳轉方案</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.richmediaplus.com/2009/04/create-trail-information-and-expired-date-in-actionscript3-and-flex3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

