<?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>Thai Coding</title>
	<atom:link href="http://www.thaicoding.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thaicoding.net</link>
	<description>We love Programming</description>
	<lastBuildDate>Sat, 12 May 2012 23:29:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>เริ่มต้นหัดเขียน JQuery</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-jquery/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-jquery/#comments</comments>
		<pubDate>Sat, 12 May 2012 23:29:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ตัวอย่าง jquery]]></category>
		<category><![CDATA[หัด jquery]]></category>
		<category><![CDATA[เริ่มต้นหัดเขียน JQuery]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1365</guid>
		<description><![CDATA[Tweet ถ้าพูดถึง Javascript ที่เป็น library แล้วคงไม่มีใครไม่รู้จัก JQuery เพราะเป็น Library ที่นิยมมาก JQuery เป็นตัวช่วยในการพัฒนา Website ที่ใช้ javascript เพราะตัว JQuery นั้นจะมีตัวช่วยทั้งในการเลือกและควบคุม element ต่างๆที่เป็น tag html ต่างๆ ทั้งที่เรากำหนดชื่อ หรือ คลาส อย่างง่ายได้รวมไปถึงการใช้งาน ajax และมี UI ต่างๆที่สวยงามให้เรียกใช้ได้มากมาย ส่วนขั้นตอนการใช้งานก็ไม่มีอะไรมากแค่ไป download file จาก http://jquery.com/ มาแล้วทำการ include หรือเรียกใช้ใน file ที่เราต้องการเท่านั้นเอง ส่วนไฟล์ที่ทำการ download จะมีให้เลือก 2 แบบคือแบบ min จะเป็นไฟล์ที่ผ่านการบีบอัดให้เราใช้งานและมีขนาดไฟล์ขนาดเล็ก ส่วนที่เป็นชื่อไฟล์ไม่มีคำว่า min จะไม่มีการบีบอัดเหมาะสำหรับผู้ที่ต้องการนำโค้ด JQuery มาพัฒนาต่อให้เป็นแบบฉบับของตัวเอง ขั้นแรกในการเขียนก็ต้องใส่ tag [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b8%2595%25e0%25b9%2589%25e0%25b8%2599%25e0%25b8%25ab%25e0%25b8%25b1%25e0%25b8%2594%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-jquery%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-jquery/" data-count="vertical" data-via="" data-lang="de" data-text="เริ่มต้นหัดเขียน JQuery &raquo; Thai Coding #jquery #ตัวอย่า [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ถ้าพูดถึง Javascript ที่เป็น library แล้วคงไม่มีใครไม่รู้จัก JQuery เพราะเป็น Library ที่นิยมมาก JQuery เป็นตัวช่วยในการพัฒนา Website ที่ใช้ javascript เพราะตัว JQuery นั้นจะมีตัวช่วยทั้งในการเลือกและควบคุม element ต่างๆที่เป็น tag html ต่างๆ ทั้งที่เรากำหนดชื่อ หรือ คลาส อย่างง่ายได้รวมไปถึงการใช้งาน ajax และมี UI ต่างๆที่สวยงามให้เรียกใช้ได้มากมาย</p>
<p>ส่วนขั้นตอนการใช้งานก็ไม่มีอะไรมากแค่ไป download file จาก http://jquery.com/ มาแล้วทำการ include หรือเรียกใช้ใน file ที่เราต้องการเท่านั้นเอง ส่วนไฟล์ที่ทำการ download จะมีให้เลือก 2 แบบคือแบบ min จะเป็นไฟล์ที่ผ่านการบีบอัดให้เราใช้งานและมีขนาดไฟล์ขนาดเล็ก ส่วนที่เป็นชื่อไฟล์ไม่มีคำว่า min จะไม่มีการบีบอัดเหมาะสำหรับผู้ที่ต้องการนำโค้ด JQuery มาพัฒนาต่อให้เป็นแบบฉบับของตัวเอง<span id="more-1365"></span></p>
<p>ขั้นแรกในการเขียนก็ต้องใส่ tag script บริเวณของ tag head ของ html จากนั้นเราก็เขียน javascript ตามโค้ดตัวอย่างข้างล่างนี้ครับ</p>
<pre class="brush: html">
&lt;html&gt;
&lt;head&gt;
	&lt;title&gt; Thaicoding : Example JQuery &lt;/title&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.7.2.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
		$(document).ready(function(){
			alert(&#039;Thaicoding.net&#039;);

		});

	function buttonclick(){

		var message = $(&quot;#username&quot;).val();
		$(&quot;.message&quot;).html(message);
	}
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;input type=&quot;text&quot; id=&quot;username&quot; /&gt;
	&lt;div class=&quot;message&quot;&gt;&lt;/div&gt;
	&lt;button id=&quot;mybutton&quot; onclick=&quot;buttonclick();&quot;&gt;Click&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>จะเห็นว่า jquery เวลาจะอาจถึง tag ที่มี class จะใช้ $(“.ชื่อคลาส”)  ส่วน ID ก็จะใช้ $(“#ชื่อid”)  เพื่ออาจ element ที่เราต้องการส่วน $(document).ready นั้นจะเป็นการเรียกใช้งานหรือทำงานโค้ดบ้างอย่างตอนหน้าเพจถูกโหลด ของดีของ Jquery คือเราสามารถใส่ function ใน ส่วน event ต่างๆเพิ่มเข้านี้ ก็เป็นัตวอย่างง่ายๆนะครับสำหรับคนที่เริ่มต้นจะเขียน JQuery</p>

	Tags: <a href="http://www.thaicoding.net/tag/jquery/" title="jquery" rel="tag">jquery</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%95%e0%b8%b1%e0%b8%a7%e0%b8%ad%e0%b8%a2%e0%b9%88%e0%b8%b2%e0%b8%87-jquery/" title="ตัวอย่าง jquery" rel="tag">ตัวอย่าง jquery</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%ab%e0%b8%b1%e0%b8%94-jquery/" title="หัด jquery" rel="tag">หัด jquery</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-jquery/" title="เริ่มต้นหัดเขียน JQuery" rel="tag">เริ่มต้นหัดเขียน JQuery</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b8%95%e0%b9%89%e0%b8%99%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php framework CodeIgniter การใช้งาน MVCเบื้องต้น</title>
		<link>http://www.thaicoding.net/php-framework-codeigniter-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-mvc%e0%b9%80%e0%b8%9a%e0%b8%b7%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%95%e0%b9%89%e0%b8%99/</link>
		<comments>http://www.thaicoding.net/php-framework-codeigniter-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-mvc%e0%b9%80%e0%b8%9a%e0%b8%b7%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%95%e0%b9%89%e0%b8%99/#comments</comments>
		<pubDate>Sat, 12 May 2012 23:23:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[mvc คือ]]></category>
		<category><![CDATA[php framework]]></category>
		<category><![CDATA[php script]]></category>
		<category><![CDATA[ภาษา php]]></category>
		<category><![CDATA[สอน php]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1358</guid>
		<description><![CDATA[Tweet php framework CodeIgniter นั้นเป็น framework ที่ออกแบบมาเพื่อให้ใช้งานแบบ mvc model นั้นก็คือจะแยกเป็น 3 ส่วนที่จะรับผิดชอบในการแต่ละส่วนไปแบ่งออกเป็น M คือ model จะเป็น class ที่ทำหน้าที่ติดต่อฐานข้อมูลซึ่งเราจะเขียนเป็นคลาสที่มีคุณสมบัติและข้อมูลใกล้เคียงกับตารางในฐานข้อมูลที่เราต้องการข้อมูล ต่อมา V View คือส่วนที่จะรับผิดชอบแค่การแสดงผลในส่วนที่จะให้ผู้ใช้เห็นเท่านั้น ต่อมาสุดท้ายคือ C Controller จะเป็นตัวควบคุมว่าผู้ใช้ได้ทำอะไรลงไปในการใช้งานจะดึงข้อมูลจาก model หรือแสดงผลจาก view เป็นต้น codeigiter นั้นจะแบ่งสามส่วนนี้อยู่ใน folder application ซึ่งมันก็จะแยกออกเป็น 3  folder อีกคือ โดยให้เราสร้างไฟล์ใหม่ใน 3 folder นี้ตามส่วนที่เราต้องการจะสร้าง โดยถ้าเป็น model จะ extends มาจาก CI_Model แต่ถ้าเป็น controller ให้ extends มาจาก CI_Controller ส่วน [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2Fphp-framework-codeigniter-%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-mvc%25e0%25b9%2580%25e0%25b8%259a%25e0%25b8%25b7%25e0%25b9%2589%25e0%25b8%25ad%25e0%25b8%2587%25e0%25b8%2595%25e0%25b9%2589%25e0%25b8%2599%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/php-framework-codeigniter-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-mvc%e0%b9%80%e0%b8%9a%e0%b8%b7%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%95%e0%b9%89%e0%b8%99/" data-count="vertical" data-via="" data-lang="de" data-text="php framework CodeIgniter การใช้งาน MVCเบื้องต้น &raquo; Thai Coding #Co [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>php framework CodeIgniter นั้นเป็น framework ที่ออกแบบมาเพื่อให้ใช้งานแบบ mvc model นั้นก็คือจะแยกเป็น 3 ส่วนที่จะรับผิดชอบในการแต่ละส่วนไปแบ่งออกเป็น M คือ model จะเป็น class ที่ทำหน้าที่ติดต่อฐานข้อมูลซึ่งเราจะเขียนเป็นคลาสที่มีคุณสมบัติและข้อมูลใกล้เคียงกับตารางในฐานข้อมูลที่เราต้องการข้อมูล ต่อมา V View คือส่วนที่จะรับผิดชอบแค่การแสดงผลในส่วนที่จะให้ผู้ใช้เห็นเท่านั้น ต่อมาสุดท้ายคือ C Controller จะเป็นตัวควบคุมว่าผู้ใช้ได้ทำอะไรลงไปในการใช้งานจะดึงข้อมูลจาก model หรือแสดงผลจาก view เป็นต้น</p>
<p>codeigiter นั้นจะแบ่งสามส่วนนี้อยู่ใน folder application ซึ่งมันก็จะแยกออกเป็น 3  folder อีกคือ<span id="more-1358"></span></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/11.jpg"><img class="alignnone size-full wp-image-1359" title="php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/11.jpg" alt="php framework CodeIgniter" width="746" height="379" /></a></p>
<p>โดยให้เราสร้างไฟล์ใหม่ใน 3 folder นี้ตามส่วนที่เราต้องการจะสร้าง โดยถ้าเป็น model จะ extends มาจาก CI_Model แต่ถ้าเป็น controller ให้ extends มาจาก CI_Controller ส่วน View นั้นก็ไม่ต้องมีการ extends ใดๆมันเป็นแค่ไฟล์ php ที่มีการใช้ tag html และ script ต่างๆเพื่อแสดงผลเท่านั้นเอง ที่นี้เรามาเริ่มกันดีกว่า จากครั้งก่อนในบทความที่แล้ว <a title="การติดตั้งเริ่มใช้งาน php framework CodeIgniter" href="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/" target="_blank"><strong>การติดตั้งเริ่มใช้งาน php framework CodeIgniter</strong></a> เราได้ทำการสร้างไฟล์ main.php ในส่วนของ controller แล้วเราก็จะแก้ไขให้มันทำการเรียกใช้ไฟล์ model กับ view โดยให้เราสร้างไฟล์ model ใน folder models มีชื่อไฟล์ว่า message_model.php โดยมี code ดังนี้</p>
<pre class="brush: php">
&lt;?php

class Message_Model extends CI_Model
{
private $message;

public function getMessage(){
return $this-&gt;message;
}

public function setMessage($newmessage){
$this-&gt;message = $newmessage;
}
}
?&gt;
</pre>
<p>ต่อมาส่วนของไฟล์ view ก็จะสร้างไฟล์ที่ชื่อว่า viewpage.php มีโค้ดดังนี้</p>
<pre class="brush: php">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;View Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php echo $displayMessage; ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>สุดท้ายคือส่วนของ controller ที่มีการแก้ไขคือไฟล์ main.php</p>
<pre class="brush: php">
&lt;?php
class Main extends CI_Controller
{
public function index()
{
$this-&gt;load-&gt;model(&#039;message_model&#039;);
$this-&gt;message_model-&gt;setMessage(&quot;Thaicoding.net&quot;);

$data[&#039;displayMessage&#039;] = $this-&gt;message_model-&gt;getMessage();

$this-&gt;load-&gt;view(&#039;viewpage&#039;,$data);
}
}

?&gt;
</pre>
<p>เมื่อลองเปิด url http://localhost/code/index.php/main ก็จะได้ผลลัพธ์ดังรูปครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/21.jpg"><img class="alignnone size-full wp-image-1360" title="ใช้งาน php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/21.jpg" alt="ใช้งาน php framework CodeIgniter" width="677" height="273" /> </a></p>

	Tags: <a href="http://www.thaicoding.net/tag/codeigniter/" title="CodeIgniter" rel="tag">CodeIgniter</a>, <a href="http://www.thaicoding.net/tag/mvc/" title="mvc" rel="tag">mvc</a>, <a href="http://www.thaicoding.net/tag/mvc-%e0%b8%84%e0%b8%b7%e0%b8%ad/" title="mvc คือ" rel="tag">mvc คือ</a>, <a href="http://www.thaicoding.net/tag/php-framework/" title="php framework" rel="tag">php framework</a>, <a href="http://www.thaicoding.net/tag/php-script/" title="php script" rel="tag">php script</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%a0%e0%b8%b2%e0%b8%a9%e0%b8%b2-php/" title="ภาษา php" rel="tag">ภาษา php</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-php/" title="สอน php" rel="tag">สอน php</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/php-framework-codeigniter-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-mvc%e0%b9%80%e0%b8%9a%e0%b8%b7%e0%b9%89%e0%b8%ad%e0%b8%87%e0%b8%95%e0%b9%89%e0%b8%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การติดตั้งเริ่มใช้งาน php framework CodeIgniter</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/#comments</comments>
		<pubDate>Sat, 12 May 2012 23:13:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[การติดตั้งเริ่มใช้งาน CodeIgniter]]></category>
		<category><![CDATA[การติดตั้งเริ่มใช้งาน php framework]]></category>
		<category><![CDATA[ลง CodeIgniter]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1352</guid>
		<description><![CDATA[Tweet CodeIgniter นั้นเป็น framework ที่ใช้ในการพัฒนาเว็บโดยใช้ภาษา php ซึ่งคำว่า framework นั้นก็คือกรอบของงานเพื่อไม่ให้เราพัฒนาออกนอกลู่นอกทาง หรือว่าลงทะเลไป และมันมีประโยชน์ในการร่วมพัฒนาหลายคน โดยขั้นตอนในการติดตั้งนั้นเริ่มแรกให้ทำการ download จากทางเว็บ http://codeigniter.com/ เมื่อโหลดเสร็จแล้วให้ทำการแตกไฟล์ zip โดยผมแตกไฟล์แล้วทำการเปลี่ยนชื่อ folder เป็น code ซึ่งจะมีโครงสร้างดังรูป หลังจากนั้นให้เรานำไปวางบน web server หรือ server จำลองในเครื่องก็แล้วแต่ เมื่อลองพิมพ์ url เพื่อเข้าไปดูโค้ดที่เราเอาไปไว้บน web server แล้วก็จะเห็นเป็นแบบในรูป ซึ่ง url ของผมจะเป็น http://localhost/code/ ซึ่งก็แสดงว่า web server ของเราไม่น่าจะมีปัญหา ต่อมาจะเป็นการกำหนดว่าให้ controller ไหนเป็น controller เริ่มต้นของเว็บเราซึ่งตัว codeigniter นั้นมันเป็น framework ที่รองรับการเขียนเว็บหรือพัฒนาเว็บ แบบ mvc อยู่แล้วโดยเราสามารถกำหนด controller [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%2595%25e0%25b8%25b4%25e0%25b8%2594%25e0%25b8%2595%25e0%25b8%25b1%25e0%25b9%2589%25e0%25b8%2587%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-php-framew%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/" data-count="vertical" data-via="" data-lang="de" data-text="การติดตั้งเริ่มใช้งาน php framework CodeIgniter &raquo; Thai Codin [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/codeigniter-lg.gif"><img class="alignnone size-full wp-image-1354" title="เริ่มใช้งาน php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/codeigniter-lg.gif" alt="เริ่มใช้งาน php framework CodeIgniter" width="300" height="301" /></a></p>
<p><strong>CodeIgniter</strong> นั้นเป็น framework ที่ใช้ในการพัฒนาเว็บโดยใช้ภาษา php ซึ่งคำว่า framework นั้นก็คือกรอบของงานเพื่อไม่ให้เราพัฒนาออกนอกลู่นอกทาง หรือว่าลงทะเลไป และมันมีประโยชน์ในการร่วมพัฒนาหลายคน โดยขั้นตอนในการติดตั้งนั้นเริ่มแรกให้ทำการ download จากทางเว็บ http://codeigniter.com/ เมื่อโหลดเสร็จแล้วให้ทำการแตกไฟล์ zip โดยผมแตกไฟล์แล้วทำการเปลี่ยนชื่อ folder เป็น code ซึ่งจะมีโครงสร้างดังรูป หลังจากนั้นให้เรานำไปวางบน web server หรือ server จำลองในเครื่องก็แล้วแต่<span id="more-1352"></span></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/1.jpg"><img class="alignnone size-full wp-image-1353" title="เริ่มใช้งาน php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/1.jpg" alt="เริ่มใช้งาน php framework CodeIgniter" width="950" height="280" /></a></p>
<p>เมื่อลองพิมพ์ url เพื่อเข้าไปดูโค้ดที่เราเอาไปไว้บน web server แล้วก็จะเห็นเป็นแบบในรูป ซึ่ง url ของผมจะเป็น http://localhost/code/ ซึ่งก็แสดงว่า web server ของเราไม่น่าจะมีปัญหา</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/2-300x143.jpg"><img class="alignnone  wp-image-1355" title="เริ่มใช้งาน php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/2-300x143.jpg" alt="เริ่มใช้งาน php framework CodeIgniter" width="471" height="224" /></a></p>
<p>ต่อมาจะเป็นการกำหนดว่าให้ controller ไหนเป็น controller เริ่มต้นของเว็บเราซึ่งตัว codeigniter นั้นมันเป็น framework ที่รองรับการเขียนเว็บหรือพัฒนาเว็บ แบบ mvc อยู่แล้วโดยเราสามารถกำหนด controller เริ่มต้นจากไฟล์ใน application\config\routes.php  โดยสังเกตบรรทัด</p>
<pre class="brush: php">
$route[&#039;default_controller&#039;] = &quot;welcome&quot;;
</pre>
<p>โดยชื่อ welcome จะเป็นไฟล์ controller เริ่มต้นโดยให้เราใส่ชื่อไฟล์แต่ไม่ต้องมีนามสกุล .php ต่อมาเราก็จะลองสร้างไฟล์ controller ขึ้นมาสักอัน โดยโครงสร้าง mvc ของ codeigniter นั้นจะเป็นในรูปแบบ folder ซึ่งจะอยู่ใน folder application โดยจะเป็น folder models, controllers, views ตามลำดับนั้นคือถ้าเราจะเพิ่ม controller ก็ให้ไปสร้างไฟล์ใน folder controller นั้นเอง โดยผมจะสร้างไฟล์ที่ชื่อว่า main.php โดยมีโค้ดดังนี้</p>
<pre class="brush: php">
&lt;?php
class Main extends CI_Controller
{
public function index()
{
echo &quot;thaicoding.net&quot;;
}
}

?&gt;</pre>
<p>สังเกตว่าเราจะเขียนเป็น class โดยมีการสืบทอดมาจาก CI_Controller เพื่อเป็นการบอกว่ามันเป็น class ที่ทำหน้าที่ controller ในแบบของ framework ตัวนี้นั้นเอง จากนั้นให้เปลี่ยนค่า config ในไฟล์ routes.php จาก welcome มาเป็นคำว่า main ดู</p>
<pre class="brush: php">
$route[&#039;default_controller&#039;] = &quot;main&quot;;
</pre>
<p>จะเห็นว่ามันได้เปลี่ยนไปใช้งาน controller main เป็น controller เริ่มต้นแแล้ว และอีกอย่างมันจะมองว่า function index เป็นฟังก์ชันแรกในการทำงานอีกด้วย ส่วนการตั้งค่าต่างๆนั้นก็มีอีกอยู่ในหลายไฟล์สามารถลองหาข้อมูลหรือดูจาก document ในหน้าเว็บของมันก็ได้ ส่วนการกำหนดการเชื่อมต่อฐานข้อมูลนั้นจะอยู่ใน file database.php ก็จะมีการกำหนด username, password ในการเข้าฐานข้อมูลและ ip หรือชื่อของ server database นั้นเอง</p>
<p>framework ตัวนี้ถือว่าดีหรือว่าที่เค้าพูดกันคือ lightweight หรือว่าเบาสะดวกนั้นเองคือในการอัพขึ้น server เราแค่แก้ค่า config นิดหน่อยแล้วมันก็สามารถทำงานได้แล้วและยืดหยึนให้เราพัฒนาตามแบบของเรา แต่ข้อเสียที่สู้ frame work อื่นได้ก็คือการที่มันไม่มีตัว generate class ในการติดต่อแก้ไขข้อมูลจาก database เหมือน frame work หลายๆตัวที่สามารถทำได้</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2012/05/3.jpg"><img class="alignnone size-full wp-image-1356" title="เริ่มใช้งาน php framework CodeIgniter" src="http://www.thaicoding.net/wp-content/uploads/2012/05/3.jpg" alt="เริ่มใช้งาน php framework CodeIgniter" width="780" height="262" /></a></p>

	Tags: <a href="http://www.thaicoding.net/tag/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-codeignite/" title="การติดตั้งเริ่มใช้งาน CodeIgniter" rel="tag">การติดตั้งเริ่มใช้งาน CodeIgniter</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/" title="การติดตั้งเริ่มใช้งาน php framework" rel="tag">การติดตั้งเริ่มใช้งาน php framework</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%a5%e0%b8%87-codeigniter/" title="ลง CodeIgniter" rel="tag">ลง CodeIgniter</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%95%e0%b8%b4%e0%b8%94%e0%b8%95%e0%b8%b1%e0%b9%89%e0%b8%87%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-php-framew/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>แนะนำ Starling Framework – The Open Source Game Engine For Flash</title>
		<link>http://www.thaicoding.net/%e0%b9%81%e0%b8%99%e0%b8%b0%e0%b8%99%e0%b8%b3-starling-framework-the-open-source-game-engine-for-flash/</link>
		<comments>http://www.thaicoding.net/%e0%b9%81%e0%b8%99%e0%b8%b0%e0%b8%99%e0%b8%b3-starling-framework-the-open-source-game-engine-for-flash/#comments</comments>
		<pubDate>Sat, 12 May 2012 22:54:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[flash game engine]]></category>
		<category><![CDATA[Open Source Game Engine For Flash]]></category>
		<category><![CDATA[หัดเขียนเกมส์ flash]]></category>
		<category><![CDATA[แนะนำ Starling Framework]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1347</guid>
		<description><![CDATA[Tweet ช่วงนี้ผมได้ลองเล่นลองเขียน game flash ผมจึงลองค้นหา flash game engine ดูก็พบ Starling Framework ซึ่งเป็นเหมือ Framework เพื่อให้เราไปต่อยอด เท่าที่ผมลองเขียนมาสักเล็กน้อยนั้น ขอบอกว่าถ้าใครกำลังบอกว่า game engine ของ flash ที่จะเขียนโค้ดเหมือน game ในรูปแบบ PC แล้วละก็ตัวนี้เลย เพราะมันมีการแบ่งเป็นคลาสเพื่อเรียกในการสร้าง object คำนวณ event ที่จะเกิดขึ้นในแต่ละฉากทำให้เรามองภาพในการพัฒนาเกมส์ได้ง่ายขึ้น ต่างจากการใช้ adobe flash กับ action script 2 อย่างในการพัฒนาที่ต้องสร้าง frame แล้วก็ใส่ script ในแต่ frame แต่ตัว Starling Framework นั้นทำให้เรารู้สึกเหมือนพัฒนาเกมส์โดยการเขียนโค้ดและพัฒนาเกมส์ในรูปแบบทั่วไปที่ทำภาพ แล้วก็เขียนโค้ดเพื่อกำหนดเหตุการณ์ แต่ได้ภาพสวยเหมือน flash และอยู่ใ platform flash แต่ ตัวนี้นั้นจะรันบน [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2581%25e0%25b8%2599%25e0%25b8%25b0%25e0%25b8%2599%25e0%25b8%25b3-starling-framework-the-open-source-game-engine-for-flash%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%81%e0%b8%99%e0%b8%b0%e0%b8%99%e0%b8%b3-starling-framework-the-open-source-game-engine-for-flash/" data-count="vertical" data-via="" data-lang="de" data-text="แนะนำ Starling Framework – The Open Source Game Engine For Flash &raquo; Thai Coding #flash game [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ช่วงนี้ผมได้ลองเล่นลองเขียน game flash ผมจึงลองค้นหา flash game engine ดูก็พบ Starling Framework ซึ่งเป็นเหมือ Framework เพื่อให้เราไปต่อยอด เท่าที่ผมลองเขียนมาสักเล็กน้อยนั้น ขอบอกว่าถ้าใครกำลังบอกว่า game engine ของ flash ที่จะเขียนโค้ดเหมือน game ในรูปแบบ PC แล้วละก็ตัวนี้เลย เพราะมันมีการแบ่งเป็นคลาสเพื่อเรียกในการสร้าง object คำนวณ event ที่จะเกิดขึ้นในแต่ละฉากทำให้เรามองภาพในการพัฒนาเกมส์ได้ง่ายขึ้น ต่างจากการใช้ adobe flash กับ action script 2 อย่างในการพัฒนาที่ต้องสร้าง frame แล้วก็ใส่ script ในแต่ frame แต่ตัว Starling Framework นั้นทำให้เรารู้สึกเหมือนพัฒนาเกมส์โดยการเขียนโค้ดและพัฒนาเกมส์ในรูปแบบทั่วไปที่ทำภาพ แล้วก็เขียนโค้ดเพื่อกำหนดเหตุการณ์ แต่ได้ภาพสวยเหมือน flash และอยู่ใ platform flash แต่ ตัวนี้นั้นจะรันบน flash player 11 นะครับเพราะฉะนั้นเครื่องไม้เครื่องมือในการพัฒนานั้นก็ต้องอัพเดตนิดหน่อย ส่วนตัวผมนั้นใช้ adobe flash builder 4.5 แต่มันก็ต้องทำให้รัน flash player 11 ซึ่งวิธี่เซ็ตค่าของผมนั้นมันค่อยข้างที่จะมั่ว เลยไม่ได้เอามาเขียนในบทความก็ต้องขออภัยด้วยนะครับ ส่วนอีกเรื่องที่เกี่ยวกับ starling framework นั้นก็คือเกมส์ดังระบบโลกอย่าง angry bird นั้นก็ใช้ตัวนี้ในการที่จะทำเกมส์บน plateform flash นะครับ</p>
<p><iframe width="480" height="274" src="http://www.youtube.com/embed/yOtnRSaoK-c" frameborder="0" allowfullscreen></iframe></p>
<p>&nbsp;</p>

	Tags: <a href="http://www.thaicoding.net/tag/flash-game-engine/" title="flash game engine" rel="tag">flash game engine</a>, <a href="http://www.thaicoding.net/tag/open-source-game-engine-for-flash/" title="Open Source Game Engine For Flash" rel="tag">Open Source Game Engine For Flash</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%ab%e0%b8%b1%e0%b8%94%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c-flash/" title="หัดเขียนเกมส์ flash" rel="tag">หัดเขียนเกมส์ flash</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%81%e0%b8%99%e0%b8%b0%e0%b8%99%e0%b8%b3-starling-framework/" title="แนะนำ Starling Framework" rel="tag">แนะนำ Starling Framework</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%81%e0%b8%99%e0%b8%b0%e0%b8%99%e0%b8%b3-starling-framework-the-open-source-game-engine-for-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เขียน Android การใช้งาน Single TouchScreen</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 06:38:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Programming]]></category>
		<category><![CDATA[Single TouchScreen]]></category>
		<category><![CDATA[จอสัมผัส]]></category>
		<category><![CDATA[มือถือ android]]></category>
		<category><![CDATA[เขียน android]]></category>
		<category><![CDATA[เขียนโปรแกรม android]]></category>
		<category><![CDATA[โปรแกรม android]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1316</guid>
		<description><![CDATA[Tweet ในมือถือ android หรือว่าพวก tablet นั้นความสามารถที่ต่างจากมือถือรุ่นเก่านั้น มีอยู่อย่างหนึ่งคือ หน้าจอแบบสัมผัสหรือที่เรียกว่า TouchScreen นั้นเอง แต่การ touch screen นั้นก็มีแบ่งออก 2 แบบคือ single touch screen กับ multi touch screen ซึ่งวันนี้ผมจะเอาตัวอย่างการใช้งานแบบ single touch screen มาให้ดูก่อน โดยครั้งนี้ผมจะใช้ api android 2.3.3 ซึ่งก็ลองอัพเวอร์ชั่นดูบ้างว่าโค้ดมีปัญหาอะไรรึเปล่าเพราะสังเกตว่ามือถือที่ออกมาหลังๆๆจะไล่ออก 2.3 กันซะส่วนใหญ่ยิ่งรุ่น top แพงๆๆก็ไป 4.0 ละ โดยผมได้สร้างโปรเจ็คที่ชื่อ THTouchScreen โดยใช้ api 2.3.3 มี min SDK Version 10 ครับโดยสร้างตามรูปเลยครับ เมื่อสร้างเสร็จเราก็เริ่มลงโค้ดกันเลยครับโดยการใช้งาน Touch Screen นั้นต้องทำการ implement [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-android-%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-single-touchscreen%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/" data-count="vertical" data-via="" data-lang="de" data-text="เขียน Android การใช้งาน Single TouchScreen &raquo; Thai Coding #Single TouchScre [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ในมือถือ android หรือว่าพวก tablet นั้นความสามารถที่ต่างจากมือถือรุ่นเก่านั้น มีอยู่อย่างหนึ่งคือ หน้าจอแบบสัมผัสหรือที่เรียกว่า TouchScreen นั้นเอง แต่การ touch screen นั้นก็มีแบ่งออก 2 แบบคือ single touch screen กับ multi touch screen ซึ่งวันนี้ผมจะเอาตัวอย่างการใช้งานแบบ single touch screen มาให้ดูก่อน โดยครั้งนี้ผมจะใช้ api android 2.3.3 ซึ่งก็ลองอัพเวอร์ชั่นดูบ้างว่าโค้ดมีปัญหาอะไรรึเปล่าเพราะสังเกตว่ามือถือที่ออกมาหลังๆๆจะไล่ออก 2.3 กันซะส่วนใหญ่ยิ่งรุ่น top แพงๆๆก็ไป 4.0 ละ โดยผมได้สร้างโปรเจ็คที่ชื่อ THTouchScreen โดยใช้ api 2.3.3 มี min SDK Version 10 ครับโดยสร้างตามรูปเลยครับ</p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/1.jpg" /></p>
<p><span id="more-1316"></span></p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/2.jpg" /></p>
<p>เมื่อสร้างเสร็จเราก็เริ่มลงโค้ดกันเลยครับโดยการใช้งาน Touch Screen นั้นต้องทำการ implement OnTouchListener ซึ่งต้องทำการ import android.view.View.OnTouchListener; เข้ามา โดยตัวอย่างนี้จะมีการสร้าง TextView ขึ้นมาตัวหนึ่งเพื่อแสดงผลการ Touch Screen ที่เกิดขึ้น โดยใช้ String Builder เป็นตัวเก็บข้อมูลก่อนไปกำหนดค่าให้ TextView โดย String Builder ก็เป็นคลาสตัวช่วยในการใช้งานของ String อันหนึ่ง</p>
<p>โค้ดทั้งหมดครับ</p>
<pre class="brush: java">
package com.thaicoding.THTouchScreen;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;

public class THTouchScreen extends Activity implements OnTouchListener {
	StringBuilder builder = new StringBuilder();
	TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textView = new TextView(this);
        textView.setText(&quot;Touch and drag (one finger)&quot;);
        textView.setOnTouchListener(this);
        setContentView(textView);
    }

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		builder.setLength(0);

		switch(event.getAction()){
		case MotionEvent.ACTION_DOWN:
			builder.append(&quot;down, &quot;);
			break;
		case MotionEvent.ACTION_MOVE:
			builder.append(&quot;move, &quot;);
			break;

		case MotionEvent.ACTION_CANCEL:
			builder.append(&quot;cancel, &quot;);
			break;
		case MotionEvent.ACTION_UP:
			builder.append(&quot;up, &quot;);
			break;
		}
		builder.append(event.getX());
		builder.append(&quot;,&quot;);
		builder.append(event.getY());
		String text = builder.toString();

		Log.d(&quot;THTouchTest&quot;, text);
		textView.setText(text);
		return true;
	}

}
</pre>
<p>เมื่อพิมพ์โค้ดเสร็จแล้วก็ลองรันดูครับแต่อย่าลืมถ้าคุณเลือก version ตามผมก็ต้องสร้าง emulation ตัวที่มี version ตรงกันนะครับ</p>
<p><img alt="" src="http://www.thaicoding.net/wp-content/uploads/2012/01/3.jpg" /></p>
<p>ผลลัพธ์การรันจะเห็นว่าจะมีการแสดงสถานะและตำแหน่งของจุดที่เราไปสัมผัสโดยในตัวอย่างนี้เป็นแบบ Single Touch Screen ซึ่งจะตรวจจับแค่จุดเดียวเท่านั้น ในสถานนะของ Touch Screen นั้นก็ประกอบด้วย Down คือการที่เรากดลงไปบนหน้าจอ , Up คือ การที่เอานิ้วออกจากหน้าจอ, Move คือการที่เราเอานิ้วไปสัมผัสบนหน้าจอแล้วเคลื่อนที่ , Cancel จะเป็นการยกเลิกใช้หน้าจอสัมผัส ซึ่งจากโค้ดตัวอย่างจะเห็นว่าใน method OnTouchListenerนั้นจะใช้ event.getAction() เพื่อหาว่าสถานะปัจจุบันของหน้าจอสัมผัสนั้นคืออะไรแล้วทำการเก็บข้อมูลเพื่อไปกำหนดค่าให้ TextView แล้วแสดงผลต่อไปส่วนตำแหน่งของจุดที่เราสัมผัสนั้นก็จะเก็บเป็นตำแหน่ง x, y ซึ่งใช้คำสั่ง event.getX() และ event.getY() โดยที่ event นั้นจะเป็นตัวแปรของ MotionEvent ครับ</p>
<p>นี้ก็เป็นตัวอย่างการใช้งาน Single TouchScreen ครับซึ่งเป็นโค้ดอย่างง่ายลองไล่ดูโค้ดนะครับเพื่อความเขาใจมากขึ้น และเนื่องในวันนี้เป็นวันปีใหม่ 2555 ขอให้ทุกท่านจงประสบแต่ความสำเร็จและความสุขนะครับจาก thaicoding.net</p>
<p><a href="http://www.mediafire.com/?x49bn1q44sgd4kp" rel="nofollow" target="_blank">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/single-touchscreen/" title="Single TouchScreen" rel="tag">Single TouchScreen</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%88%e0%b8%ad%e0%b8%aa%e0%b8%b1%e0%b8%a1%e0%b8%9c%e0%b8%b1%e0%b8%aa/" title="จอสัมผัส" rel="tag">จอสัมผัส</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%a1%e0%b8%b7%e0%b8%ad%e0%b8%96%e0%b8%b7%e0%b8%ad-android/" title="มือถือ android" rel="tag">มือถือ android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android/" title="เขียน android" rel="tag">เขียน android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="เขียนโปรแกรม android" rel="tag">เขียนโปรแกรม android</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%82%e0%b8%9b%e0%b8%a3%e0%b9%81%e0%b8%81%e0%b8%a3%e0%b8%a1-android/" title="โปรแกรม android" rel="tag">โปรแกรม android</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-android-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-single-touchscreen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 15:32:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Mobile Programming]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1266</guid>
		<description><![CDATA[Tweet การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น ในการพัฒนา android app นั้นเมื่อโปรแกรมมีการทำงานที่ซับซ้อนนั้น หลักการพื้นฐานของ oop ก็น่าจะเป็นการสร้าง class เพื่อที่จะสร้าง object ที่ทำงานต่างกันไป วันนี้หลังจากหายไปนานไม่ได้เขียนบทความเลย เอาตัวอย่างการสร้าง Active List เมื่อ เลือก list แล้วก็จะไปเรียกใช้งาน class ต่างๆที่มีอยู่ครับเราไปดูกันเลย หลังจากที่สร้างโปรเจ็คเสร็จแล้วให้เราทำการแก้ไขไฟล์หลัก ActiveList.java ให้ทำการ extends มาจาก ListActivity เพื่อที่เราจะทำการหน้าตาแบบ list ได้ โดยมีโค้ดดังนี้ package com.thaicoding.activelist; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%25aa%25e0%25b8%25a3%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2587-activelist-%25e0%25b9%2581%25e0%25b8%25a5%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2581%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/" data-count="vertical" data-via="" data-lang="de" data-text="การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น &raquo; [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>การสร้าง ActiveList แล้วเรียกใช้งาน class อื่น</strong></p>
<p>ในการพัฒนา android app นั้นเมื่อโปรแกรมมีการทำงานที่ซับซ้อนนั้น หลักการพื้นฐานของ oop ก็น่าจะเป็นการสร้าง class เพื่อที่จะสร้าง object ที่ทำงานต่างกันไป วันนี้หลังจากหายไปนานไม่ได้เขียนบทความเลย เอาตัวอย่างการสร้าง Active List เมื่อ เลือก list แล้วก็จะไปเรียกใช้งาน class ต่างๆที่มีอยู่ครับเราไปดูกันเลย</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/1.jpg"><img class="alignnone size-full wp-image-1268" title="หัดเขียน android " src="http://www.thaicoding.net/wp-content/uploads/2011/12/1.jpg" alt="หัดเขียน android " width="544" height="370" /></a></p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/2.jpg"><img class="alignnone size-full wp-image-1269" title="หัดเขียน android" src="http://www.thaicoding.net/wp-content/uploads/2011/12/2.jpg" alt="หัดเขียน android" width="544" height="477" /></a></p>
<p>หลังจากที่สร้างโปรเจ็คเสร็จแล้วให้เราทำการแก้ไขไฟล์หลัก ActiveList.java ให้ทำการ extends มาจาก ListActivity<br />
<span id="more-1266"></span><br />
เพื่อที่เราจะทำการหน้าตาแบบ list ได้ โดยมีโค้ดดังนี้</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ActiveList extends ListActivity {
    /** Called when the activity is first created. */
	String menu[] = {&quot;Helloword&quot;, &quot;Thaicoding&quot;};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                android.R.layout.simple_list_item_1, menu));
    }
}
</pre>
<p>จากนั้นลองรันดูจะได้หน้าต่างแบบนี้</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/3.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/3.jpg" alt="" title="3" width="797" height="566" class="alignnone size-full wp-image-1275" /></a></p>
<p>ซึ่งเมนูเราสร้างมาจาก String array ที่ชื่อว่า menu นั้นเองส่วนรูปแบบ style นั้นก็จะกำหนดโดย android.R.layout.<em>simple_list_item_</em><em>1 </em>ซึ่งลองใช้แบบต่างๆดูได้ครับ ต่อมาเราจะมาสร้าง class ตามชื่อเมนูครับมีคลาสชื่อว่า? Helloword, Thaicoding</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/12/4.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/4.jpg" alt="" title="4" width="755" height="439" class="alignnone size-full wp-image-1276" /></a></p>
<p>โดยทั้ง 2 คลาสไม่มีอะไรมาให้มัน extends มาจาก? Activity โดยไม่มีการทำงานอะไรมากเพิ่งแค่สร้าง TextView จากนั้นก็จะแสดงผลออกทางหน้าจอซึ่งต่างกันเฉพาะคำเท่านั้น</p>
<p>โค้ดทั้ง 2 คลาส</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class Thaicoding extends Activity {

	TextView textView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView = new TextView(this);
        textView.setText(&quot;Thaicoding.net&quot;);
        setContentView(textView);
    }
}

package com.thaicoding.activelist;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class Helloword extends Activity {
	TextView textView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        textView = new TextView(this);
        textView.setText(&quot;HelloWord&quot;);
        setContentView(textView);
    }
}
</pre>
<p>เมื่อสร้างคลาสทั้ง 2 แล้วเราก็มากำหนด action ให้กับคลาสหลักให้ทำการเพิ่ม onListItemClick โดยมีโค้ดทั้งหมดดังนี้</p>
<pre class="brush: java">
package com.thaicoding.activelist;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ActiveList extends ListActivity {
    /** Called when the activity is first created. */
	String menu[] = {&quot;Helloword&quot;, &quot;Thaicoding&quot;};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter&lt;String&gt;(this,
                android.R.layout.simple_list_item_1, menu));
    }

    @Override
    protected void onListItemClick(ListView list, View view, int position,long id)
    {
        super.onListItemClick(list, view, position, id);
        String testName = menu[position];
        try {
            Class clazz = Class
                    .forName(&quot;com.thaicoding.activelist.&quot; + testName);
            Log.d(testName, testName);
            Intent intent = new Intent(this, clazz);
            startActivity(intent);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
</pre>
<p>หลักจากที่เราเขียนโค้ดเสร็จแล้วก็กำหนดสิทธิการรันของ class ในไฟล์ AndroidManifest.xml โดยเพิ่ม tag ใหม่จะได้ดังนี้</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.thaicoding.activelist&quot;
      android:versionCode=&quot;1&quot;
      android:versionName=&quot;1.0&quot;&gt;
    &lt;uses-sdk android:minSdkVersion=&quot;8&quot; /&gt;

    &lt;application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;&gt;
        &lt;activity android:name=&quot;.ActiveList&quot;
                  android:label=&quot;@string/app_name&quot;&gt;
            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity android:label=&quot;Helloword Test&quot;
		          android:name=&quot;.Helloword&quot;
			      android:configChanges=&quot;keyboard|keyboardHidden|orientation&quot; /&gt;
        &lt;activity android:label=&quot;Thaicoding Test&quot;
		          android:name=&quot;.Thaicoding&quot;
			      android:configChanges=&quot;keyboard|keyboardHidden|orientation&quot; /&gt;

    &lt;/application&gt;
&lt;/manifest&gt;
</pre>
<p>เมื่อเสร็จแล้วลองรันแล้วเลือกดูครับมันก็จะได้หน้าตาประมาณนี้ครับ</p>
<p>&nbsp;</p>
<p>หลักการสำคัญให้สังเกต onListItemClick ให้ดีครับจะมีการใช้งาน</p>
<p><span style="text-decoration: underline;">Class</span> clazz = Class.<em>forName</em>(&#8220;com.thaicoding.activelist.&#8221; + testName);</p>
<p>ซึ่ง testName นั้นจะเป็นชื่อ class ที่อยู่ในตัวแปรเมนูนั้นเอง ซึ่งในการใช้งานแบบนี้เราต้องดูเรื่องของ package ของภาษาจาวาให้ดีนะครับ หวังว่าจากตัวอย่างนี้จะทำให้หลายคนเอาไปประยุกต์ใช้งานได้นะครับ<br />
<a href="http://www.thaicoding.net/wp-content/uploads/2011/12/31.jpg"><img src="http://www.thaicoding.net/wp-content/uploads/2011/12/31.jpg" alt="" title="3" width="797" height="566" class="alignnone size-full wp-image-1281" /></a><br />
&nbsp;</p>
<p><a href="http://www.mediafire.com/?dvrlod4d51k67kv">Download SourceCode</a></p>
No tags for this post.]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87-activelist-%e0%b9%81%e0%b8%a5%e0%b9%89%e0%b8%a7%e0%b9%80%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%81%e0%b9%83%e0%b8%8a%e0%b9%89/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การสร้างสี่เหลี่ยมด้วย action script 3.0</title>
		<link>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/</link>
		<comments>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 16:29:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[action script 3.0 หัด action script]]></category>
		<category><![CDATA[สอน action script]]></category>
		<category><![CDATA[สี่เหลี่ยม]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1259</guid>
		<description><![CDATA[Tweet หลังจากที่ adobe ประกาศว่าจะยกเลิกการพัฒนา flash player บนมือถือเล่นเอาคนที่อยู่ในวงการ flash คิดหนักกันพอสมควรมามันจะเป็นอย่างไรกันต่อไป แต่อย่างไรผมก็จะเขียนบทความต่อไปละกัน ครั้งนี้จะเป็นการสร้างสี่เหลี่ยมโดยใช้ action script ครับเรามาเริ่มกันเลยดีกว่า ขั้นแรกเราก็สร้างไฟล์ fla ที่เป็น action script 3.0 ก่อนครับ จากนั้นเมื่อเราสร้างไฟล์เสร็จแล้วให้ทำการคลิกที่ timeline แล้วก็คลิกขวาแบบในรูปเพื่อทำการเขียน action script จากนั้นก็เขียนโค้ดตามนี้ครับ import flash.display.MovieClip; var mc:MovieClip = new MovieClip(); mc.graphics.beginFill(0xFF0000); mc.graphics.drawRect(0,0,120,120); mc.graphics.endFill(); addChild(mc); เมื่อเขียนเสร็จก็ลองกด ctl+enter เพื่อทำการ test movie ดูครับจะเห็นว่ามีการสร้างสี่หลี่ยมสีแดงเกิดขึ้นครับ &#160; การทำงานของโค้ดก็คือ เรามีการสร้าง movie clip ขึ้นมา 1 ตัวเพราะการสร้างสีเหลี่ยมนั้นต้องอาศัย movie clip เป็นตัวสร้างเพราะ [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b8%25aa%25e0%25b8%25a3%25e0%25b9%2589%25e0%25b8%25b2%25e0%25b8%2587%25e0%25b8%25aa%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b9%2580%25e0%25b8%25ab%25e0%25b8%25a5%25e0%25b8%25b5%25e0%25b9%2588%25e0%25b8%25a2%25e0%25b8%25a1%25e0%25b8%2594%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b8%25a2-a%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/" data-count="vertical" data-via="" data-lang="de" data-text="การสร้างสี่เหลี่ยมด้วย action script 3.0 &raquo; Thai Coding #ac [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>หลังจากที่ adobe ประกาศว่าจะยกเลิกการพัฒนา flash player บนมือถือเล่นเอาคนที่อยู่ในวงการ flash คิดหนักกันพอสมควรมามันจะเป็นอย่างไรกันต่อไป แต่อย่างไรผมก็จะเขียนบทความต่อไปละกัน ครั้งนี้จะเป็นการสร้างสี่เหลี่ยมโดยใช้ action script ครับเรามาเริ่มกันเลยดีกว่า ขั้นแรกเราก็สร้างไฟล์ fla ที่เป็น action script 3.0 ก่อนครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/11.jpg"><img class="alignnone size-full wp-image-1260" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/11.jpg" alt="หัด action script" width="528" height="381" /></a></p>
<p><span id="more-1259"></span>จากนั้นเมื่อเราสร้างไฟล์เสร็จแล้วให้ทำการคลิกที่ timeline แล้วก็คลิกขวาแบบในรูปเพื่อทำการเขียน action script</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/21.jpg"><img class="alignnone size-full wp-image-1261" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/21.jpg" alt="หัด action script" width="489" height="454" /></a></p>
<p>จากนั้นก็เขียนโค้ดตามนี้ครับ</p>
<pre class="brush: as3">

import flash.display.MovieClip;

var mc:MovieClip = new MovieClip();

mc.graphics.beginFill(0xFF0000);

mc.graphics.drawRect(0,0,120,120);

mc.graphics.endFill();

addChild(mc);
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/31.jpg"><img class="alignnone size-full wp-image-1262" title="หัด action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/31.jpg" alt="หัด action script" width="456" height="389" /></a></p>
<p>เมื่อเขียนเสร็จก็ลองกด ctl+enter เพื่อทำการ test movie ดูครับจะเห็นว่ามีการสร้างสี่หลี่ยมสีแดงเกิดขึ้นครับ</p>
<p>&nbsp;</p>
<p>การทำงานของโค้ดก็คือ เรามีการสร้าง movie clip ขึ้นมา 1 ตัวเพราะการสร้างสีเหลี่ยมนั้นต้องอาศัย movie clip เป็นตัวสร้างเพราะ movie clip นั้นมันจะเป็นตัว graphics ที่สามารถสร้างรูปร่างต่างๆ รวมไปถึงการแสดงภาพจากไฟล์ภาพด้วย เมื่อเราสร้าง movie clip ขึ้นมาแล้วจากนั้นเราก็เริ่มกำหนดสีให้มันด้วย method beginFill ซึ่งต้องใส่ค่าให้มัน โดยผมกำหนดสีเป็นสีแดงโดยการกำหนดสีนั้นต้องใส่เป็นเลขฐาน 16 ซึ่งเป็นค่าของสีครับจากนั้นเราก็สั่งให้มันทำการวาดสีเหลี่ยมโดยใช้ method drawRect เมื่อเราทำการวาดรูปต่างๆเสร็จแล้วเราก็ควรจบด้วย method endFill เพื่อเป็นการบอกว่าจบการวาดหรือกำหนดรูปร่างของ movie clip ครับ เมื่อเราทำการสร้างและกำหนดรูปร่างให้ movie clip แล้วเราก็ทำให้มันแสดงบนผลลัพธ์ของ stage โดยใช้คำสั่ง addChild() ครับ</p>
<p><a href="http://www.mediafire.com/?i6b67ppv326f4x2">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/action-script-3-0-%e0%b8%ab%e0%b8%b1%e0%b8%94-action-script/" title="action script 3.0 หัด action script" rel="tag">action script 3.0 หัด action script</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-action-script/" title="สอน action script" rel="tag">สอน action script</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1/" title="สี่เหลี่ยม" rel="tag">สี่เหลี่ยม</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%aa%e0%b8%a3%e0%b9%89%e0%b8%b2%e0%b8%87%e0%b8%aa%e0%b8%b5%e0%b9%88%e0%b9%80%e0%b8%ab%e0%b8%a5%e0%b8%b5%e0%b9%88%e0%b8%a2%e0%b8%a1%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Action Script 3.0 การใช้งาน Timer</title>
		<link>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/</link>
		<comments>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 16:04:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[movie clip]]></category>
		<category><![CDATA[การใช้งาน Timer]]></category>
		<category><![CDATA[สอน ActionScript]]></category>
		<category><![CDATA[เริ่มเขียน actionscript]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1251</guid>
		<description><![CDATA[Tweet ในการเขียน action script นั้นเป็นการกำหนดเหตุการณ์และควบคุมเหตุการณ์ที่เกิดขึ้นในโปรแกรม ดังนั้นสิ่งหนึ่งที่ขาดไม่ได้ก็น่าจะเป็น timer เพราะมันสามารถทำสร้างหรือคงบคุมการทำงานตามเวลาที่เรากำหนดได้ ซึ่งมีประโยชน์มาก เรามาดูตัวอย่างการใช้ timer ใน action script กันเลย ขั้นแรกเราก็ทำการสร้างไฟล์ flash ตามรูปครับ จากนั้นไปในส่วน timeline เพื่อเปิด หน้าต่างเขียน actionขึ้นมาจากนั้นก็เขียนโค้ดตามนี้ครับ import flash.utils.Timer; import flash.events.TimerEvent; import flash.events.Event; var timeLine:Timer = new Timer(500); var mc:MovieClip = new MovieClip(); addChild(mc); var linex:int = 10; var liney:int = 10; timeLine.addEventListener(TimerEvent.TIMER, drawLine); timeLine.start(); function drawLine(e:Event) { trace(&#34;drawline&#34;); [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2Faction-script-3-0-%25e0%25b8%2581%25e0%25b8%25b2%25e0%25b8%25a3%25e0%25b9%2583%25e0%25b8%258a%25e0%25b9%2589%25e0%25b8%2587%25e0%25b8%25b2%25e0%25b8%2599-timer%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/" data-count="vertical" data-via="" data-lang="de" data-text="Action Script 3.0 การใช้งาน Timer &raquo; Thai Coding #ActionScript #movie clip #การ [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>ในการเขียน action script นั้นเป็นการกำหนดเหตุการณ์และควบคุมเหตุการณ์ที่เกิดขึ้นในโปรแกรม ดังนั้นสิ่งหนึ่งที่ขาดไม่ได้ก็น่าจะเป็น timer เพราะมันสามารถทำสร้างหรือคงบคุมการทำงานตามเวลาที่เรากำหนดได้ ซึ่งมีประโยชน์มาก</p>
<p>เรามาดูตัวอย่างการใช้ timer ใน action script กันเลย ขั้นแรกเราก็ทำการสร้างไฟล์ flash ตามรูปครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/1.jpg"><img class="alignnone size-full wp-image-1252" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/1.jpg" alt="action script" width="490" height="354" /></a></p>
<p><span id="more-1251"></span></p>
<p>จากนั้นไปในส่วน timeline เพื่อเปิด หน้าต่างเขียน actionขึ้นมาจากนั้นก็เขียนโค้ดตามนี้ครับ</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/2.jpg"><img class="alignnone size-full wp-image-1253" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/2.jpg" alt="action script" width="394" height="449" /></a></p>
<pre class="brush: as3">

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.events.Event;

var timeLine:Timer = new Timer(500);

var mc:MovieClip = new MovieClip();

addChild(mc);

var linex:int = 10;

var liney:int = 10;

timeLine.addEventListener(TimerEvent.TIMER, drawLine);

timeLine.start();

function drawLine(e:Event)

{

trace(&quot;drawline&quot;);

mc.graphics.lineStyle(2, 0x990000, .75);

mc.graphics.moveTo(linex, liney);

linex = linex + 10;

liney = liney + 10;

mc.graphics.lineTo(linex,liney);

}
</pre>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/11/3.jpg"><img class="alignnone size-full wp-image-1254" title="action script" src="http://www.thaicoding.net/wp-content/uploads/2011/11/3.jpg" alt="action script" width="494" height="403" /></a></p>
<p>เมื่อกด ctrl + enter ก็ได้ผลลัพธ์ดังรูปโดยมันจะทำการวาดเส้นตรงตามค่า x, y เพิ่มขึ้นทุกๆ 500 ms ขั้นตอนในการทำงานของโค้ดเริ่มแรกเราต้องทำการ import package ที่เกี่ยวข้องกับ timer เข้ามาจากนั้นให้เราทำการสร้าง timer ขึ้นมา 1 ตัวโดยเรากำหนดเวลารอบโดยกำหนดไปใน constructor ตอนสร้าง object timer จากนั้นมีการสร้างตัวแปรแบบ movie clip ที่ชื่อว่า mc เพื่อทำการวาดรูปกราฟิกต่างๆ และมีการประกาศตัวแปรเพื่อเก็บตำแหน่ง x และ y จากนั้นเราก็ทำการ add movie clip mc ไปยัง stage โดยใช้คำสั่ง addChild จากนั้นเราก็ทำการใช้ event listener ให้กับ timer เพื่อให้ตัวแปร timeline จัดการเหตุการณ์ที่เกิดขึ้นโดยในการกำหนด addEventListener นั้นก็จะทำเมื่อ timer ครบทุกๆรอบนั้นคือครบทุกๆ 500 ms โดยจะให้ทำงานใน function drawLine โดยภายใน function นี้ก็จะมีการวาดเส้นตรงโดยให้ทำการ move ไปยังตำแหน่ง x และ y จากนั้นก็เพิ่มค่า x และ y แล้วทำการวาดเส้นตรงจากจุดที่มนอยู่ไปยังจุดใหม่ซึ่งเป็นจุดที่ค่า x และ y เพิ่มค่าไปแล้ว</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/?2lask16dglnj32t">Download Source</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/actionscript/" title="ActionScript" rel="tag">ActionScript</a>, <a href="http://www.thaicoding.net/tag/movie-clip/" title="movie clip" rel="tag">movie clip</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/" title="การใช้งาน Timer" rel="tag">การใช้งาน Timer</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-actionscript/" title="สอน ActionScript" rel="tag">สอน ActionScript</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript/" title="เริ่มเขียน actionscript" rel="tag">เริ่มเขียน actionscript</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/action-script-3-0-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-timer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เขียนเกมส์ยามว่าง flash game fireball v1.0</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 16:07:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ทั่วไป]]></category>
		<category><![CDATA[action script]]></category>
		<category><![CDATA[fireball game]]></category>
		<category><![CDATA[flash game fireball]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1247</guid>
		<description><![CDATA[Tweet หลังจากที่ผมศึกษา actionscript มาสักพักก็เลยลองเขียนเกมส์ดูก็ปรากฎว่ามันสนุกดีเลย ว่าจะพัฒนาไปเรื่อยตามความรู้ที่มี นั้นก็คือถ้ามีความรู้เพิ่มขึ้นก็จะพัฒนาให้มันน่าเล่นมากกว่านี้และดีกว่านี้ครับ &#160; นี้เป็นวีดีโอที่ผมอัดไว้ เสียดายมันไม่มีเสียงเพราะ encode เสียงเครื่องผมมีปัญหาเวลาอัดแล้วอัพขึ้น youtube เลยมีปัญหาเรื่องเสียงครับ v1.0 นี้มีอะไรบ้าง หน้าตัวละครเปลี่ยนหน้าได้เวลาตีลูกบอล เสียงประกอบเวลาตีลูกบอลและเก็บดาว มีหน้า intro, game over และสามารถเล่นซ้ำได้ มีการแสดงผลคะแนน ส่วนรายละเอียดการเล่นก็คลิกที่เวลาตัวละครโดนลูกบอลเพื่อตีไปฝั่งตรงข้าม ถ้าลูกบอลเด่งไปยังเส้นหลังของคู่ต่อสู้เราก็จได้คะแนนใครได้ ห้าคะแนนก่อนชนะ ส่วนดาวนั้นจะเป็น item ทำให้ลูกที่เราตีไปไกลขึ้นซึ่งจะต้องเก็บให้มากๆๆ เพราะทุกครั้งที่เก็บได้ระยะทางการตีบอลจะเพิ่มขึ้นด้วย ส่วนใครอยากลองเล่นดูก็เลยได้ที่ลิงค์นี้ ครับ เล่นเกมส์ Tags: action script, fireball game, flash game fireball]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599%25e0%25b9%2580%25e0%25b8%2581%25e0%25b8%25a1%25e0%25b8%25aa%25e0%25b9%258c%25e0%25b8%25a2%25e0%25b8%25b2%25e0%25b8%25a1%25e0%25b8%25a7%25e0%25b9%2588%25e0%25b8%25b2%25e0%25b8%2587-flash-game-fireball-v1-0%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/" data-count="vertical" data-via="" data-lang="de" data-text="เขียนเกมส์ยามว่าง flash game fireball v1.0 &raquo; Thai Coding #action scr [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p>หลังจากที่ผมศึกษา actionscript มาสักพักก็เลยลองเขียนเกมส์ดูก็ปรากฎว่ามันสนุกดีเลย ว่าจะพัฒนาไปเรื่อยตามความรู้ที่มี นั้นก็คือถ้ามีความรู้เพิ่มขึ้นก็จะพัฒนาให้มันน่าเล่นมากกว่านี้และดีกว่านี้ครับ<br />
<object width="420" height="315" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/GamyAcF-8I4?version=3&amp;hl=en_US" /><param name="allowfullscreen" value="true" /><embed width="420" height="315" type="application/x-shockwave-flash" src="http://www.youtube.com/v/GamyAcF-8I4?version=3&amp;hl=en_US" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<p>&nbsp;</p>
<p>นี้เป็นวีดีโอที่ผมอัดไว้ เสียดายมันไม่มีเสียงเพราะ encode เสียงเครื่องผมมีปัญหาเวลาอัดแล้วอัพขึ้น youtube เลยมีปัญหาเรื่องเสียงครับ</p>
<p>v1.0 นี้มีอะไรบ้าง</p>
<ul>
<li>หน้าตัวละครเปลี่ยนหน้าได้เวลาตีลูกบอล</li>
<li>เสียงประกอบเวลาตีลูกบอลและเก็บดาว</li>
<li>มีหน้า intro, game over และสามารถเล่นซ้ำได้</li>
<li>มีการแสดงผลคะแนน</li>
</ul>
<p>ส่วนรายละเอียดการเล่นก็คลิกที่เวลาตัวละครโดนลูกบอลเพื่อตีไปฝั่งตรงข้าม ถ้าลูกบอลเด่งไปยังเส้นหลังของคู่ต่อสู้เราก็จได้คะแนนใครได้ ห้าคะแนนก่อนชนะ ส่วนดาวนั้นจะเป็น item ทำให้ลูกที่เราตีไปไกลขึ้นซึ่งจะต้องเก็บให้มากๆๆ เพราะทุกครั้งที่เก็บได้ระยะทางการตีบอลจะเพิ่มขึ้นด้วย</p>
<p>ส่วนใครอยากลองเล่นดูก็เลยได้ที่ลิงค์นี้ ครับ<a title="เล่นเกมส์ fireball" href="http://thaicoding.net/games/fireballv1/game.html"> เล่นเกมส์</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/action-script/" title="action script" rel="tag">action script</a>, <a href="http://www.thaicoding.net/tag/fireball-game/" title="fireball game" rel="tag">fireball game</a>, <a href="http://www.thaicoding.net/tag/flash-game-fireball/" title="flash game fireball" rel="tag">flash game fireball</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99%e0%b9%80%e0%b8%81%e0%b8%a1%e0%b8%aa%e0%b9%8c%e0%b8%a2%e0%b8%b2%e0%b8%a1%e0%b8%a7%e0%b9%88%e0%b8%b2%e0%b8%87-flash-game-fireball-v1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เริ่มเขียน actionscript ด้วย adobe flash cs 5.5</title>
		<link>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/</link>
		<comments>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 14:28:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[adobe flash cs 5.5]]></category>
		<category><![CDATA[สอน ActionScript]]></category>
		<category><![CDATA[เริ่มเขียน actionscript]]></category>

		<guid isPermaLink="false">http://www.thaicoding.net/?p=1223</guid>
		<description><![CDATA[Tweet เริ่มเขียน actionscript ด้วย adobe flash cs 5.5 วันนี้ผมเขียนบทความสำหรับผู้ที่เริ่มจะหัดเขียน actionscript หรือกำลังสนใจ ผมจะเขียนบทความที่เกี่ยวกับเขียน actionscript version 3.0 นะครับ โดยเราจำเป็นที่จะต้องหาโปรแกรม adobe flash cs 5.0 หรือ 5.5 ก็ได้ตามแต่ที่ท่านจะหามาลงในเครื่องได้นะครับ ขั้นแรกเราก็เปิดโปรแกรม flash มาจากนั้นเลือก new file แล้วมันจะมีหน้าต่างให้เลือกชนิดของไฟล์ที่เราจะสร้างโดย ผมเลือกเป็น ActionScript 3.0 เมื่อเราสร้างไฟล์เสร็จแล้วให้คลิกที่ tab timeline เพื่อจะไปยังหน้าต่าง script ซึ่งในการเขียน actionscript นั้นมันก็เขียนได้หลายรูปแบบ ทั้งเขียนบน stage เลย หรือจะแยกเป็นไฟล์คลาสหรือว่าจะเขียน script ใน movie clip ซึ่งในตัวอย่างนี้ผมจะเขียนบน stage ซึ่ง stage คืออะไรมันก็คือ stage [...]]]></description>
			<content:encoded><![CDATA[<div class="wp_twitter_button" style="float: right; margin-left: 10px;">
					<a href="http://twitter.com/share?counturl=http%3A%2F%2Fwww.thaicoding.net%2F%25e0%25b9%2580%25e0%25b8%25a3%25e0%25b8%25b4%25e0%25b9%2588%25e0%25b8%25a1%25e0%25b9%2580%25e0%25b8%2582%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%2599-actionscript-%25e0%25b8%2594%25e0%25b9%2589%25e0%25b8%25a7%25e0%25b8%25a2-adobe-flash-cs-5-5%2F" class="twitter-share-button" data-url="http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/" data-count="vertical" data-via="" data-lang="de" data-text="เริ่มเขียน actionscript ด้วย adobe flash cs 5.5 &raquo; Thai Coding #ActionScrip [...]">Tweet</a><br />
					<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
				</div>
<p><strong>เริ่มเขียน actionscript ด้วย adobe flash cs 5.5</strong></p>
<p>วันนี้ผมเขียนบทความสำหรับผู้ที่เริ่มจะหัดเขียน actionscript หรือกำลังสนใจ ผมจะเขียนบทความที่เกี่ยวกับเขียน actionscript version 3.0 นะครับ โดยเราจำเป็นที่จะต้องหาโปรแกรม adobe flash cs 5.0 หรือ 5.5 ก็ได้ตามแต่ที่ท่านจะหามาลงในเครื่องได้นะครับ ขั้นแรกเราก็เปิดโปรแกรม flash มาจากนั้นเลือก new file แล้วมันจะมีหน้าต่างให้เลือกชนิดของไฟล์ที่เราจะสร้างโดย ผมเลือกเป็น ActionScript 3.0</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/1.jpg"><img class="alignnone size-full wp-image-1229" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/1.jpg" alt="actionscript" width="503" height="362" /></a></p>
<p><span id="more-1223"></span>เมื่อเราสร้างไฟล์เสร็จแล้วให้คลิกที่ tab timeline เพื่อจะไปยังหน้าต่าง script ซึ่งในการเขียน actionscript นั้นมันก็เขียนได้หลายรูปแบบ ทั้งเขียนบน stage เลย หรือจะแยกเป็นไฟล์คลาสหรือว่าจะเขียน script ใน movie clip ซึ่งในตัวอย่างนี้ผมจะเขียนบน stage ซึ่ง stage คืออะไรมันก็คือ stage ในการแสดงผลของ flash ซึ่งจะแบ่งเป็น flame ตามที่เราต้องการซึ่งมันคล้ายๆกับโปรแกรมตัดต่อหนัง ที่มันจะมีวิดีโอหลักที่เราต้องใส่ effect ในวินาทีต่างๆนั้นเอง stage ก็เหมือนกันที่เราใส่เหตุการณ์ต่างๆ เอาละเรามาเขียน action script ?โดยให้ที่ timeline แล้วคลิกขวาที่เฟรมเหมือนในรูปจากนั้นก็เขียนโค้ดครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/2.jpg"><img class="alignnone size-full wp-image-1230" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/2.jpg" alt="actionscript" width="511" height="498" /></a></p>
<p>&nbsp;</p>
<pre class="brush: as3">
import flash.text.TextField;

var textmessage:TextField = new TextField();

textmessage.text = &quot;Thaicoding.net&quot;;

addChild(textmessage);

trace(&quot;Thaicoding.net&quot;);
</pre>
<p>เมื่อเราเขียนโค้ดเสร็จแล้วให้ลองรันโปรแกรมดูโดยกด ctr+enter ครับแล้วจะได้ผลลัพธ์ดังรูป</p>
<p><a href="http://www.thaicoding.net/wp-content/uploads/2011/10/3.jpg"><img class="alignnone size-full wp-image-1231" title="actionscript" src="http://www.thaicoding.net/wp-content/uploads/2011/10/3.jpg" alt="actionscript" width="443" height="575" /></a></p>
<p>&nbsp;</p>
<p>โดยโปรแกรมนี้มันได้ทำการสร้าง TextField ขึ้นมา จากนั้นกำหนดให้มันมีข้อความว่า Thaicoding.net จากนั้นเราก็ทำให้มันไปอยู่ใน stage โดยใช้คำสั่ง addChild() นั้นเองซึ่งใน action script นี้หากเราจะต้องการสร้างหรือใช้ control ตัวใดเราต้องทำการ import library ของ control ตัวนั้นเข้ามา แต่ส่วนมาโปรแกรม adobe flash มันจะทำการ import อัตโนมัติให้อยู่แล้วถ้าคุณไม่ไปปรับค่าอะไร ส่วนคำสั่ง trace นั้นมันใช้แสดงข้อความออกทางหน้าต่าง output ซึ่งมันมีประโยชน์ในการ debug โปรแกรมอย่างมากครับ</p>
<p>&nbsp;</p>
<p><a href="http://www.mediafire.com/?i6z3646ic4359gh">Download SourceCode</a></p>

	Tags: <a href="http://www.thaicoding.net/tag/actionscript/" title="ActionScript" rel="tag">ActionScript</a>, <a href="http://www.thaicoding.net/tag/adobe-flash-cs-5-5/" title="adobe flash cs 5.5" rel="tag">adobe flash cs 5.5</a>, <a href="http://www.thaicoding.net/tag/%e0%b8%aa%e0%b8%ad%e0%b8%99-actionscript/" title="สอน ActionScript" rel="tag">สอน ActionScript</a>, <a href="http://www.thaicoding.net/tag/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript/" title="เริ่มเขียน actionscript" rel="tag">เริ่มเขียน actionscript</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.thaicoding.net/%e0%b9%80%e0%b8%a3%e0%b8%b4%e0%b9%88%e0%b8%a1%e0%b9%80%e0%b8%82%e0%b8%b5%e0%b8%a2%e0%b8%99-actionscript-%e0%b8%94%e0%b9%89%e0%b8%a7%e0%b8%a2-adobe-flash-cs-5-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

