tag:blogger.com,1999:blog-43135550148040232192024-02-06T19:51:35.831-08:00Flash CS5 AS3 tutorials By Abed Allateef QaisiAbed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-4313555014804023219.post-61783968510004086102011-04-26T11:52:00.000-07:002011-04-26T11:57:07.043-07:00Create facebook Iframe Application Using flash AS3 API ( Updated Version ).<div dir="ltr" style="text-align: left;" trbidi="on"><div style="text-align: left;"></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;">please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;">After I have received a lot of requests to update the old tutorial on how to create simple flash application, I decided to create new simpler tutorial with a snap shots of all the steps to accomplish this task, so please if you have any question please posted on my above facebook page ;)</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;">please be aware to follow below steps because any mistake may give you an error .</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;">so as many of you know already know the first step is to create facebook new application from the developer application as you can see in the picture below :</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; text-align: left;"><br />
</div><ul style="text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSShp_kVjqNeinuO1B-ll8sWXMmN_W5XnqhixuTnEiR-Sl3c7BIicIt2d8cKuvr9DbQs18LtBtki5x4AbW5HfFu61u7ay2cr26SoV4wxN5v7nT8NTbsECteXZEo6oINPWO6hdJ4utJt8UR/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-left: 1em;"> </a>
<li>when you click setup new application you need to choose your application name and agree the facebook terms ( I choose <span class="Apple-style-span" style="color: #0b5394;">abedtutorial</span>) .</li>
</ul>in the new updated api the <span class="Apple-style-span" style="color: #0b5394;">application ID</span> is the only parameter<span class="Apple-style-span" style="color: #0b5394;"> </span>you only need to know in order to connect to facebook.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpUfULJmBWJQxgrjObwE3hZMzdLGLw_reU8uo8AKpw_FpZauH14HNfqlL84quWmt_4b2mLKg338EGhoRbumOwrEvi_YK3hEE1brMZXbZofWXEEqUxR0xtSODUXFbo2SG9S9hJVWXMtEZ4Y/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="263" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpUfULJmBWJQxgrjObwE3hZMzdLGLw_reU8uo8AKpw_FpZauH14HNfqlL84quWmt_4b2mLKg338EGhoRbumOwrEvi_YK3hEE1brMZXbZofWXEEqUxR0xtSODUXFbo2SG9S9hJVWXMtEZ4Y/s400/1.png" width="400" /></a></div><div><br />
<ul style="text-align: left;"><li>now click the setting and go to the website tap and fill the site url with your application folder URL so for me i fill it with : <span class="Apple-style-span" style="color: #0b5394;">http://amazingwork.com/abedtutorial/</span> so i hosted my files inside amazingtalk folder and in the site-domain just fill it with your domain : <span class="Apple-style-span" style="color: #0b5394;">amazingwork.com</span> .</li>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3SbVm-ipbdLlxRAgbRSDdtl35QWTGZ4iKYqjeFpbM9dyniRTmO_k4doXl6e30S5KamOGQbsk8dLV7dclMzunGpuqHPfbmTIjz_mWYQqIHEdvxADB2cMIzOfXjmDQMBv_6bK9iBH7ecGg1/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="116" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3SbVm-ipbdLlxRAgbRSDdtl35QWTGZ4iKYqjeFpbM9dyniRTmO_k4doXl6e30S5KamOGQbsk8dLV7dclMzunGpuqHPfbmTIjz_mWYQqIHEdvxADB2cMIzOfXjmDQMBv_6bK9iBH7ecGg1/s400/Untitled.png" width="400" /></a></div><li>then click the facebook integration tap and now you need to fill the convas url and this is the main URL for your application and every body will access your application thru this URL so for our example I fill it with <span class="Apple-style-span" style="color: #0b5394;">abedtutorial</span>, and then choose <span class="Apple-style-span" style="color: #0b5394;">Auto-resize</span> in the iframe size .</li>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMGouTA64mb1Bmyy9XL65EbL0xRvvMQYn7u48-hqGVJ6TrS3rftuOdUNSHbiE90WxeJKSVmJObK2iymfvLV0MCpB-4Qkt65Q5nf4LSkzgqd6095CfAZxHoeyY2D7SzDxLh8alfHXfZKrh/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPMGouTA64mb1Bmyy9XL65EbL0xRvvMQYn7u48-hqGVJ6TrS3rftuOdUNSHbiE90WxeJKSVmJObK2iymfvLV0MCpB-4Qkt65Q5nf4LSkzgqd6095CfAZxHoeyY2D7SzDxLh8alfHXfZKrh/s400/2.png" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><li>finally, click the advance tab and fill it as you can in the image below :</li>
</ul><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ42WUzsdEZbJsdT_O7JCzz-37keK_ubmVjJ3LjumxSGnFkS6cF53PKQO8hYvzwStVl9e2FKLJlCqCvsIUHqIaTGy4-GniugSTQOPak7tWjkJtbRqXN0QYZFC6ATBdRFwgmZlgz5mxje9f/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="218" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiQ42WUzsdEZbJsdT_O7JCzz-37keK_ubmVjJ3LjumxSGnFkS6cF53PKQO8hYvzwStVl9e2FKLJlCqCvsIUHqIaTGy4-GniugSTQOPak7tWjkJtbRqXN0QYZFC6ATBdRFwgmZlgz5mxje9f/s400/3.png" width="400" /></a></div><div><br />
</div><div style="text-align: left;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">at this stage we finish creating our application setting ;) now we will start Writing our code to connect with facebook.</div></div><div style="text-align: left;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div></div><div style="text-align: left;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">so since facebook and adobe updated their API, in this tutorial i will add all the libraries you need along with the whole source codes files.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">finally, you need to make below changes with your application parameters to make it work :</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><ul style="text-align: left;"><li>in the Net->FacebookUserConnector.as : change the below appid with your App id.</li>
<ul><li>private var appId:String = "179085902140993";</li>
</ul><li>in the index.aspx just replace below variables with your app paramters</li>
<ul><li></li>
<li> var APP_ID = "179085902140993";</li>
<li> var REDIRECT_URI = "http://apps.facebook.com/abedtutorial/";</li>
</ul></ul><br />
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">by changing above two points you can now get User Information from facebook using flash as you can find in the online demo :</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><a href="http://apps.facebook.com/abedtutorial/">http://apps.facebook.com/abedtutorial/</a></div></div><div style="text-align: left;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">so by this you finish all itis need to connect to facebook :)</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">----------------------------------------------------------------------</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: inherit;">you can download all you need by follow this link below :</span></div><div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><a href="http://amazingwork.com/abedtutorial/abedtutorial.rar">Source Files</a></span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-tab-span" style="white-space: pre;"><br />
</span></div></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: xx-small;"><br />
</span></div></div><div style="text-align: left;"><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div></div><div style="text-align: left;"></div><div style="text-align: left;"></div></div></div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com11tag:blogger.com,1999:blog-4313555014804023219.post-17148642402638912092011-04-13T23:14:00.000-07:002011-04-13T23:14:51.430-07:00Read twitter feeds using as3<div dir="ltr" style="text-align: left;" trbidi="on">if you ever tried to read twitter news directly using flash you will find that you will receive a security error cause flash have a sand box security which mean that twitter should add a cross domain file on their server.<br />
<br />
in order to make work you need to create php file that load twitter news and send the result back to the flash as xml as below :<br />
<br />
<ul style="text-align: left;"><li>create new php file and name it twitter.php and then copy&paste below code :</li>
</ul><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"><?php<br />
/*Get Content from Twitter<br />
*/<br />
<br />
function get_content($url)<br />
{<br />
$ch = curl_init();<br />
<br />
curl_setopt ($ch, CURLOPT_URL, $url);<br />
curl_setopt ($ch, CURLOPT_HEADER, 0);<br />
<br />
ob_start();<br />
<br />
curl_exec ($ch);<br />
curl_close ($ch);<br />
$string = ob_get_contents();<br />
<br />
ob_end_clean();<br />
<br />
return $string;<br />
}<br />
<br />
#usage:<br />
$content = get_content ("http://twitter.com/statuses/user_timeline.xml?screen_name=your twitter name");<br />
echo $content;</span> </div><br />
<ul style="text-align: left;"><li>now in your flash create new class name Twitter.as and this class can be called from anywhere in your flash and then parse the result xml</li>
</ul><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;">package </span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;">{<br />
<br />
import flash.net.*;<br />
import flash.events.EventDispatcher;<br />
import flash.events.Event;<br />
import EventType.EventType;<br />
public class Twitter extends EventDispatcher </span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;">{<br />
<br />
private static var instant = null ; <br />
private var twitterAddress:String = "twitter.php" ;<br />
public var xmlTweets:XML = null;<br />
public function Twitter() <br />
{<br />
<br />
}<br />
public static function GetInstant():Twitter<br />
{<br />
if(instant==null)<br />
instant = new Twitter();<br />
return instant;<br />
}<br />
public function GetLatestNews()<br />
{<br />
<br />
var twitterLoader:URLLoader = new URLLoader(); <br />
twitterLoader.load(new URLRequest(twitterAddress));<br />
twitterLoader.addEventListener(Event.COMPLETE, ProcessTweets); <br />
<br />
}<br />
private function ProcessTweets(e:Event):void <br />
{ <br />
xmlTweets = new XML(e.target.data);<br />
dispatchEvent(new Event("TweetsLoaded"));<br />
}</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> }<br />
<br />
}</span><br />
<ul style="text-align: left;"><li>the final step now is to call the twitter class from ur flash and retrieve the result:</li>
</ul><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;">var twitter:Twitter = Twitter.GetInstant();</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"> twitter.addEventListener("TweetsLoaded",TweetsLoaded);</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"> twitter.GetLatestNews();</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"><br />
</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"> function TweetsLoaded(e:Event)</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"> {</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;">var twitter:Twitter = Twitter.GetInstant();</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;"> xmlTweets = twitter.xmlTweets; </span></div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: x-small;">}</span></div><br />
<br />
<br />
Enjoy :) <br />
<br />
<br />
<br />
</div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0tag:blogger.com,1999:blog-4313555014804023219.post-35829289223887562432011-03-25T08:05:00.000-07:002011-03-25T08:05:41.582-07:00Passing parameters to event handlers in AS3<div dir="ltr" style="text-align: left;" trbidi="on">After along research I found a simple way where you can simply passing parameters to event hanlder.<br />
<br />
in order to do this you need to extend the event class and create new custom class that will handle the parameters arguments as below :<br />
<br />
<br />
<ul style="text-align: left;"><li>create new class and name it EventType.as </li>
</ul><div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">package </span>{</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// Import class</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">import flash.events.Event;</span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// EventType</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public class</span> EventType <span class="Apple-style-span" style="color: #3d85c6;">extends Even</span>t {</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// Properties</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public var</span> arg:<span class="Apple-style-span" style="color: #0b5394;">*</span>;</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>// Constructor</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public function </span>EventType(type:<span class="Apple-style-span" style="color: #0b5394;">String</span>, bubbles:<span class="Apple-style-span" style="color: #0b5394;">Boolean</span> = false, cancelable:<span class="Apple-style-span" style="color: #0b5394;">Boolean</span> = false, ... a:<span class="Apple-style-span" style="color: #0b5394;">*</span>) {</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">super</span>(type, bubbles, cancelable);</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>arg = a;</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// Override clone</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">override public function</span> clone():<span class="Apple-style-span" style="color: #0b5394;">Event</span>{</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">return new</span> EventType(type, bubbles, cancelable, arg);</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>};</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></div></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">now all you need is to dispatch new event using </span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">EventType instead of event as below :</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">dispatchEvent</span>(<span class="Apple-style-span" style="color: #0b5394;">new </span>EventType("TestHandler",<span class="Apple-style-span" style="color: #0b5394;">false</span>,<span class="Apple-style-span" style="color: #0b5394;">false</span>,"Test :)"))</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><div><span class="Apple-style-span" style="color: #0b5394;">private function</span> TestHandler(e:EventType)<span class="Apple-style-span" style="color: #0b5394;">:void</span></div><div>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>trace( e.arg[0]);<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div>}</div></span></div><div><br />
</div><div>hope it save your time :)</div></div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0tag:blogger.com,1999:blog-4313555014804023219.post-52267685764876397272011-01-12T22:52:00.000-08:002011-01-12T22:52:30.575-08:00Integrate FaceBook Chat Using AS3 and FaceBook fqlQuery and sending messages using facebook post Stream URL.<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a></div><div><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFqgmtj2A2Ym_1FIMTYWHVyB7w77U1GBb4WErYZIB2PUNYHo1d-BSa_nfTQyKpGVCiTMTDrfb2Ck4wq5BCQ4D5NWK3d8706kcZNs_G5ZNZOawY0fEAvwGR12FS4dK6LQ9-0vIQZt6rsxqd/s1600/Chat.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFqgmtj2A2Ym_1FIMTYWHVyB7w77U1GBb4WErYZIB2PUNYHo1d-BSa_nfTQyKpGVCiTMTDrfb2Ck4wq5BCQ4D5NWK3d8706kcZNs_G5ZNZOawY0fEAvwGR12FS4dK6LQ9-0vIQZt6rsxqd/s1600/Chat.png" /></a></div><div><br />
</div><div>First of all you need to read my post on how to create new facebook application using AS3 by follow below link:</div><div><a href="http://as3flashcs5.blogspot.com/2010/12/create-facebook-iframe-application.html">http://as3flashcs5.blogspot.com/2010/12/create-facebook-iframe-application.html</a></div><div><br />
</div><div>in this tutorial I will show you two Integration point with facebook API:</div><div><ul><li>getting Friend Status .</li>
<li>Sending Messages to you friend chat box.</li>
</ul><div>To get your friends status you need to make sure that friends_online_presence and user_online_presence Permissions have been applied to facebook uiserver.php for your application as below sample :</div></div><div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">var PermURL = "http://www.facebook.com/connect/uiserver.php?app_id=181390918539668&next=http://amazingwork.com/fbexampletest/index.html&display=page&locale=en_US&perms=friends_online_presence,publish_stream,user_online_presence&return_session=0&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request"</span></div></div><div>now in order to get your friends status, you need to get the online_presence field from facebook User table using fqlQuery as below :</div><div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Facebook.fqlQuery("SELECT uid, online_presence FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = --please fill here the uer Id who you need to get his friends status--) ",LoadOnlineUsers)</span></div></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><div>private function LoadOnlineUsers(response:Object, fail:Object)</div><div>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("-->"+fail)</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>var OnlineString =""</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>var OnlineUsers:Array = new Array()</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>for (var key:Object in response)</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>var oUsersOnlineClass:UsersOnlineClass= new UsersOnlineClass();</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>oUsersOnlineClass.UserID=response[key]["uid"]</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>oUsersOnlineClass.Status=response[key]["online_presence"]</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>OnlineUsers.push(oUsersOnlineClass)</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div>}</div><div><div>package </div><div>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>public class UsersOnlineClass</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>private var sUserID:String = "";</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>private var sStatus:String = "";<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>//Item Constructor</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>public function UsersOnlineClass()</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>{</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>}<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>//-----------------------------<span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>public function get UserID():String {</div><div> return sUserID;</div><div> }</div><div> </div><div> public function set UserID(x:String):void {</div><div> sUserID = x; </div><div> }</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>//-----------------------------</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span></div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>public function get Status():String {</div><div> return sStatus;</div><div> }</div><div> </div><div> public function set Status(x:String):void {</div><div> sStatus = x; </div><div> }</div><div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div><div>}</div></div></span></div><div>as you can in the above code that I have get my frineds online status ( active, offline, null)and store them along with their Ids in an array to use it anywhere in my application .</div><div>-----------------------------------------------------------------------------</div><div>sending a new chat message from our AS3 application :</div><div><br />
</div><div>this is that hard part where you need to follow precisely below steps :</div><div><ul><li> the first step is to use facebook sending messages URL :</li>
<ul><li><span class="Apple-style-span" style="color: #0b5394; font-size: x-small;">var url:String = "http://www.facebook.com/ajax/chat/send.php?__a=1";</span></li>
</ul><li>the second step is to create URL post variable to send them to the above URL :</li>
<ul><li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">var request:URLRequest = new URLRequest(url);</span></li>
</ul></ul><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span> var requestVars:URLVariables = new URLVariables();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> requestVars.msg_text = "Message Text";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> requestVars.to = "friend ID";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> requestVars.msg_id = "Random Message ID";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> requestVars.client_time = new Date().getTime().toString();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> requestVars.post_form_id = "you can find this field by viewing facebook source page";and for me i am trying now to get this field in adynamic way using javascript function and pass it to flash ( no success until now cuase i am using Iframe :( "</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><div> request.data = requestVars;</div><div> request.method = URLRequestMethod.POST;</div></span></div><div><ul><li>now to send these variables to the facebook message center URL we need to use URL Loader :</li>
<ul><li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">var urlLoader:URLLoader = new URLLoader();</span></li>
</ul></ul><ul></ul><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>urlLoader = new URLLoader();</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>urlLoader.dataFormat = URLLoaderDataFormat.TEXT;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"></span> urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true);<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;">urlLoader.load(request);</span></span></div><div><ul><li>all u need now is to handle the result data and decoded the data using JSON serialization to an object</li>
<ul><li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">function loaderCompleteHandler(e:Event):void {</span></li>
</ul></ul><ul><ul></ul></ul><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> var sResult:String = e.target.data as String</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> sResult= sResult.replace("for (;;);","")</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> var Res = JSON.decode(d,false)</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> trace(Res)}</span><span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<ul><ul></ul></ul>I hope this tutorial will help you to enrich your applications,</div><div>for any question regarding this tutorial, please visit <a href="http://www.facebook.com/pages/Flash-Community/176320862386436">http://www.facebook.com/pages/Flash-Community/176320862386436</a>.</div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com4tag:blogger.com,1999:blog-4313555014804023219.post-51270135534638021082010-12-27T01:28:00.000-08:002010-12-30T06:06:44.296-08:00Singleton Pattern using flash AS3 .please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a><br />
<br />
The Singleton pattern is used for projects where you want to create classes that can only ever have one instance, I think usually you can use this pattern in the case you have a manager-type of class that will manage other classes objects and it can be access from anywhere in your project, or you can use it when you dont want to create more than one instant like for example that you have a style manager for the whole application and you have one style for this application .<br />
<br />
<br />
First of all,<br />
you need to find a way to limit the number of instances a class can create to one. The obvious approach would be to have a property that keeps track of the number of instances a class has. Doing that, you’ll soon come across a practical problem: how can you keep count of the number of instances a class has, when class properties are defined on the class instance and not shared throughout the class?<br />
<br />
To do this please have a look to the following Singleton Class :<br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">package </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public class</span> Singleton {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> private static var</span> instance:<span class="Apple-style-span" style="color: #0b5394;">Singleton</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">private static var</span> allowInstance:<span class="Apple-style-span" style="color: #0b5394;">Boolean </span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public function</span> Singleton() {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">if</span>(!allowInstance) {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">throw new Error</span>("Error: use Singleton.getInstance() instead of new keyword");</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">public static function</span> getInstance():Singleton {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> if</span>(</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">instance</span><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> == <span class="Apple-style-span" style="color: #0b5394;">null</span>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> allowInstance = <span class="Apple-style-span" style="color: #0b5394;">true</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> instance = <span class="Apple-style-span" style="color: #0b5394;">new </span>Singleton();</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> allowInstance = <span class="Apple-style-span" style="color: #0b5394;">false</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">return </span>instance;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">public function</span> doSomething():void {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">trace</span>("doing something");</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<br />
<br />
The preceding code uses a public method named getInstance to return a new instance of the Singleton class. Because it is called from within the class itself, the instantiation isn’t blocked by the private scope attribute of the class. Now, you might be wondering how we’ll be able to trigger that getInstance method, as we can’t create any new instance of the class to call it on. That’s where the static keyword comes in again. Any methods that are defined as static can be called by simply using the class name, in this case Singleton.getInstance().<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var </span>mySingleton:Singleton = Singleton.getInstance();</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">mySingleton.doSomething();</span><br />
<br />
to see a singleton in a practical users manager example please download below source code ;<br />
<br />
<a href="http://amazingwork.com/BloggTutorial/SingletonPattern/SingletonPattern.rar">Source Code </a><br />
<a href="http://amazingwork.com/BloggTutorial/SingletonPattern/SingletonPattern.html">Online Demo</a><br />
<br />
for any question please feel free to post it or mail me at abed_q@hotmail.com<br />
<br />
Cheers.Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0tag:blogger.com,1999:blog-4313555014804023219.post-65348548932548766762010-12-26T06:57:00.000-08:002010-12-30T06:06:58.400-08:00Command Design Pattern using flash AS3 .<span class="Apple-style-span" style="font-family: inherit;">please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a></span><br />
<br />
<span class="Apple-style-span" style="font-family: inherit;"> in this Tutorial you will understand what is the fundimental of command patterns, definition, and how can you implement it in flash AS3.</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">Fundametntals : </span><br />
<br />
<ul><li>command patterns fall in to behavioral categories which help up to change the behavioral of project without altering the same structure of your project.</li>
<li>Command Patterns allows a request or action to exist as an object as we use it in manycases to save an action in a class .</li>
</ul><br />
<span class="Apple-style-span" style="font-family: inherit;">let suppose that we have menu in flash with the folloing actions :</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">* File * Execute * Exit</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">so usually when we want to write a code to execute some actions we </span>usually<span class="Apple-style-span" style="font-family: inherit;"> writing a methode with if conditions</span><span class="Apple-style-span" style="font-family: inherit;">:</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">private function</span> Execute(<span class="Apple-style-span" style="color: #0b5394;">string</span> strAction)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">if</span>(strAction <span class="Apple-style-span" style="color: #0b5394;">==</span> "File")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">trace</span>("File")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">else if</span>(strAction <span class="Apple-style-span" style="color: #0b5394;">==</span> "Execute")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-style-span" style="color: #0b5394;">trace</span>("Execute")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> else if</span>(strAction <span class="Apple-style-span" style="color: #0b5394;">==</span> "Exit")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> {</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-style-span" style="color: #0b5394;">trace</span>("Exit")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
and as you can notice we have a lot of if conditions, so in the future if we want to add more actions then we need to add more if conditions and itis a miss up code ;)<br />
<br />
now in command patterns what we simply do is housing these command or actions in simple classes and we need to make sure to implement them using a common interface :<br />
<br />
for the File action class we create a ClsExecuteFile class and implement the IExecute interface :<br />
<br />
IExecute.as<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">package </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public interface</span> IExecute { </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">function </span>Execute():<span class="Apple-style-span" style="color: #0b5394;">void</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">function </span>get_strCommand():<span class="Apple-style-span" style="color: #0b5394;">String</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">function </span>set_strCommand(<span class="Apple-style-span" style="color: #0b5394;">x:String</span>):<span class="Apple-style-span" style="color: #0b5394;">void </span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span><br />
<br />
ClsExecuteFile.as<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">package </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">public class</span> ClsExecuteFile <span class="Apple-style-span" style="color: #351c75;">implements </span>IExecute{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public var</span> sStrCommand:<span class="Apple-style-span" style="color: #0b5394;">String </span>= "File"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public function</span> Execute():<span class="Apple-style-span" style="color: #0b5394;">void</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">trace</span>("File")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public function </span>get_strCommand():<span class="Apple-style-span" style="color: #0b5394;">String</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">return </span>sStrCommand</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public function</span> set_strCommand(<span class="Apple-style-span" style="color: #0b5394;">x:String</span>):<span class="Apple-style-span" style="color: #0b5394;">void </span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sStrCommand = <span class="Apple-style-span" style="color: #0b5394;">x</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<br />
first think you need to know about above code that we cant declare a public property in the interface this is why i declare manually getter and setter .<br />
<br />
the other thing we declare this variable the strCommand to identify what object we need to pull when any action occur.<br />
<br />
so in order to invoke these methods we need to create an invoker class which will save all the action objects in a container list and then based on which action is trigger we will return the object that is related to match action class .<br />
<br />
ClsInvoker.as<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">package </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">public clas</span>s ClsInvoker { </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">private var</span> oObjectsList:<span class="Apple-style-span" style="color: #0b5394;">Array = new Array()</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;"> public function</span> ClsInvoker()</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oObjectsList = <span class="Apple-style-span" style="color: #0b5394;">new Array()</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oObjectsList.<span class="Apple-style-span" style="color: #0b5394;">push</span>(<span class="Apple-style-span" style="color: #0b5394;">new</span> ClsExecuteFile())</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">public function</span> getCommand(strCommand:<span class="Apple-style-span" style="color: #0b5394;">String</span>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #3d85c6;">for</span>(<span class="Apple-style-span" style="color: #0b5394;">var </span>i=0;i<oObjectsList.<span class="Apple-style-span" style="color: #0b5394;">length</span>;i++)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>oIExtecute:IExecute = oObjectsList[i] <span class="Apple-style-span" style="color: #0b5394;">as</span> IExecute</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">if</span>(oIExtecute.get_strCommand() == strCommand )</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">return </span>oIExtecute;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>r<span class="Apple-style-span" style="color: #0b5394;">eturn null;</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
finally in order to execute any action we we first create object of the invoker class and then depend on the action we get the object and then simply execute it :<br />
<br />
main execution code :<br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var </span>oClsInvoker:<span class="Apple-style-span" style="color: #0b5394;">ClsInvoker</span> = <span class="Apple-style-span" style="color: #0b5394;">new </span>ClsInvoker()</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var </span>oIexecute:IExecute = oClsInvoker.getCommand("File")</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oIexecute.Execute();</span><br />
<br />
and as you can find there is no if condition only simple three line of code and depend on the action we simply pass the action string to the invoker object.<br />
<br />
in the future if you want to add new action you need to create a new action class then host its object in the invoker class container list and change the strCommand string to identify this object.<br />
<br />
u can use this command when you want to save the action behavior like for example when we want to create undo, redo actions .<br />
<br />
I hope this was very simple and helpful, for any questions or request just post it or email me at abed_q@hotmail.com<br />
<br />
<a href="http://amazingwork.com/BloggTutorial/CommandPatterns/CommandPatterns.rar">Source Code</a>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0tag:blogger.com,1999:blog-4313555014804023219.post-12165665695901656352010-12-10T09:24:00.000-08:002010-12-30T06:07:11.242-08:00Connect Flash CS5 AS3 with web service Using flex Library.please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a><br />
<br />
I am always confused on why Adobe embed the webservice component in flash AS2 versions and remove it from flash AS3 versions, and i guess they did this in order to promote flex or flash builder ;)<br />
<br />
but after a deep research i found away that you can use the flex library in flash itself and connect to your web service as you can do by the end of this tutorial .<br />
<br />
first of all you need to link to the flex webservices library from flash cs5 where you can find it in the below link :<br />
<br />
C:\Program Files (x86)\Adobe\Adobe Flash Builder 4\sdks\4.1.0\frameworks\libs<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihszz1jx7nlRvaQGDDfhjPwNCjgxZZRwoYd7BjCJHgBCg4OZ_3xGYV2u2G1Z57k-IWNtdIftBoDf0kh9ZaqdGFQYmDvurpc6E_CHZHwuQ_F3G5l4ApZUgfO5UOyrumPYIFjlP7zcwn5_jI/s1600/webservice.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihszz1jx7nlRvaQGDDfhjPwNCjgxZZRwoYd7BjCJHgBCg4OZ_3xGYV2u2G1Z57k-IWNtdIftBoDf0kh9ZaqdGFQYmDvurpc6E_CHZHwuQ_F3G5l4ApZUgfO5UOyrumPYIFjlP7zcwn5_jI/s320/webservice.png" width="320" /></a></div><br />
you can download the library by follow the link in the end of this tutorial.<br />
<br />
in this tuorial i will show you how you can create web service solution using .net 2008, so from the start page go and select create new project --> select asp.net wev service application.<br />
<br />
then in the service1.asmx we will create a simple function that return a string value we need to read in flash cs5.<br />
<br />
<br />
[<span class="Apple-style-span" style="color: #0b5394;">WebMethod</span>]<br />
<span class="Apple-style-span" style="color: #0b5394;"> public string</span> GetName()<br />
{<br />
<span class="Apple-style-span" style="color: #0b5394;">return </span>"Abed Allateef Qaisi";<br />
}<br />
<br />
then when you run your application you can find the link in the address bar as:<br />
<a href="http://localhost:55166/Service1.asmx">http://localhost:55166/Service1.asmx</a><br />
<br />
now all we need is to call our web service function and trace the output .<br />
<br />
in your flash document you need first to import web services namespaces :<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">import </span>mx.rpc.soap.*;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">import</span> mx.rpc.events.*;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">import </span>mx.rpc.AbstractOperation;</span><br />
<br />
then when you need to call the web service you need to initialize the object then load the WSDL call, after the event Load is trigger then you can call any method from this web service :<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var </span>uNameWebService:<span class="Apple-style-span" style="color: #0b5394;">WebService</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var </span>serviceOperation:<span class="Apple-style-span" style="color: #0b5394;">AbstractOperation</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">CallService_btn.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">MouseEvent.CLICK</span>, InitWebService);</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>InitWebService(event:<span class="Apple-style-span" style="color: #0b5394;">MouseEvent</span>):<span class="Apple-style-span" style="color: #0b5394;">void</span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Result_txt.text = "INIT"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>uNameWebService = new WebService();</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>uNameWebService.<span class="Apple-style-span" style="color: #0b5394;">loadWSDL</span>("http://localhost:55166/Service1.asmx?WSDL");</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>uNameWebService.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">LoadEvent.LOAD</span>, BuildServiceRequest);</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>BuildServiceRequest(evt:<span class="Apple-style-span" style="color: #0b5394;">LoadEvent</span>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Result_txt.<span class="Apple-style-span" style="color: #0b5394;">text </span>= "START"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>serviceOperation = uNameWebService.<span class="Apple-style-span" style="color: #0b5394;">getOperation</span>("GetName");<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>serviceOperation.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">FaultEvent.FAULT</span>, DisplayError);</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>serviceOperation.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">ResultEvent.RESULT</span>, DisplayResult);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>serviceOperation.<span class="Apple-style-span" style="color: #0b5394;">send</span>();</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>DisplayError(evt:<span class="Apple-style-span" style="color: #0b5394;">FaultEvent</span>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">trace</span>("error");</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>DisplayResult(evt:<span class="Apple-style-span" style="color: #0b5394;">ResultEvent</span>)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>UserName:<span class="Apple-style-span" style="color: #0b5394;">String</span> = evt.<span class="Apple-style-span" style="color: #0b5394;">result </span>as <span class="Apple-style-span" style="color: #0b5394;">String</span>;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Result_txt.<span class="Apple-style-span" style="color: #0b5394;">text </span>= UserName;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<br />
---------------------------------------------<br />
<br />
<a href="http://amazingwork.com/BloggTutorial/WebServices/Net2005WebService.rar">.NET Source Files</a><br />
<a href="http://amazingwork.com/BloggTutorial/WebServices/WebServices.rar">Code & Library Source Files </a><br />
<br />
I welcome any questions u have .Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com4tag:blogger.com,1999:blog-4313555014804023219.post-90510606656245333072010-12-10T02:19:00.000-08:002010-12-30T06:07:24.789-08:00Display Variables Access Scope using timeline objects.please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a><br />
<br />
In AS2 it was very easy to access any variables from Parents and Childs using _parent or _root .<br />
<br />
but after the enhancement that happened to the AS3 the change the way you can access variables from different scops using the timeline Movies or even thru a classes.<br />
<br />
****access variables using time line Movies.<br />
<br />
to understand how you can access a parent variables from child or vise-versa you need to create new AS3 document and then create Circle Movie and name it "shapes_mc" then inside this Movie Create another square and Movie and name it "square_mc". so finally create a dynamic text name it "name_txt" then converted to movie and name it "textContainer_mc" as in the picture below:<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyTGmZQbch4DdM6gO_RBLLuzfNW5NKGnv-cRD3t5GjqeWIyd6fDHuA0LeXwFrIxE8EcsCyApKQ9_tvQuQ8HmFl6GiS6_eMxWwb5cpd0MtYmQbz1RMQ3sRQK99JvYJdjsnOtmK05sBC8UIu/s1600/DisplayStructure.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyTGmZQbch4DdM6gO_RBLLuzfNW5NKGnv-cRD3t5GjqeWIyd6fDHuA0LeXwFrIxE8EcsCyApKQ9_tvQuQ8HmFl6GiS6_eMxWwb5cpd0MtYmQbz1RMQ3sRQK99JvYJdjsnOtmK05sBC8UIu/s320/DisplayStructure.png" width="320" /></a></div>so now on the stage create new variable in farm1 :<br />
var Scope1 = "Scope1"<br />
in the shapes_mc create another variables :<br />
var Scope2 = "Scope2"<br />
in the Square Movie create variable<br />
var Scope3 = "Scope3"<br />
<br />
* now I will show you how you can access these variables from different Movies by creating a buttons in each scope and in when the user click will trace the other variables from button scope.<br />
<br />
<br />
<ul><li>Stage Button Code :</li>
</ul><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">stage_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">function TraceScopeHandler(e)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Stage Variable --> " + Scope1)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Shapes Variable --> " + shapes_mc.Scope2)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("square Variable --> " + shapes_mc.square_mc.Scope3)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Text Variable --> " + textContainer_mc.name_txt.text)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<ul><li>shapes Button Code :</li>
</ul><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">import flash.display.MovieClip;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">var Scope2 = "Scope2"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">shapes_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">function TraceScopeHandler(e)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var oStage:MovieClip = parent as MovieClip</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Stage Variable --> " + oStage.Scope1)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Shapes Variable --> " + Scope2)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("square Variable --> " + square_mc.Scope3)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Text Variable --> " + oStage.textContainer_mc.name_txt.text)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<ul><li>square button code:</li>
</ul><div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">import flash.display.MovieClip;</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">square_btn.addEventListener(MouseEvent.MOUSE_DOWN,TraceScopeHandler)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">function TraceScopeHandler(e)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var oShapes:MovieClip = parent as MovieClip</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>var oStage:MovieClip = oShapes.parent as MovieClip</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> </span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Stage Variable --> " + oStage.Scope1)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Shapes Variable --> " + oShapes.Scope2)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("square Variable --> " + Scope3)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>trace("Text Variable --> " + oStage.textContainer_mc.name_txt.text)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></div></div><br />
<br />
----------------------------------<br />
<div></div><br />
<a href="http://www.amazingwork.com/BloggTutorial/VariablesScopes/DisplayObjects.fla">Source Code </a>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com11tag:blogger.com,1999:blog-4313555014804023219.post-60500445088190373372010-12-08T04:00:00.000-08:002011-04-26T11:55:25.361-07:00Create facebook Iframe Application Using flash AS3 API.<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="color: red; font-family: Arial, Helvetica, sans-serif; font-size: large;">A new Updated tutorial have been added,please follow this link below .</span><br />
<br />
<a href="http://as3flashcs5.blogspot.com/2011/04/create-facebook-iframe-application.html">http://as3flashcs5.blogspot.com/2011/04/create-facebook-iframe-application.html</a><br />
<br />
please like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a><br />
<br />
After along research on how I can use flash instead of flex to create facebook application by using the new facebook graph API, I finally create a simple class to connect flash with facebook and i am happy to share it with you.<br />
<br />
please be aware to follow below steps because any mistake may give you an error .<br />
<br />
so as many of you know already know the first step is to create facebook new application from the developer application as you can see in the picture below :<br />
<br />
<ul><li>when you click setup new application you need to choose your application name and agree the facebook terms ( I choose <span class="Apple-style-span" style="color: #0b5394;">facetalk</span>) .</li>
<li>after your application is created you must know the most important parameters in order to connect with facebook ( API key, application ID, application secret ) .</li>
<li>now click the setting and go to the website tap and fill the site url with your application folder URL so for me i fill it with : <span class="Apple-style-span" style="color: #0b5394;">http://amazingwork.com/amazingtalk/</span> so i hosted my files inside amazingtalk folder and in the site-domain just fill it with your domain : <span class="Apple-style-span" style="color: #0b5394;">amazingwork.com</span> .</li>
<li>then click the facebook integration tap and now you need to fill the convas url and this is the main URL for your application and every body will access your application thru this URL so for our example I fill it with <span class="Apple-style-span" style="color: #0b5394;">amazingtalk </span>becuase <span class="Apple-style-span" style="color: #0b5394;">facetalk </span>is already taken, and in the convas Type please be sure to select Iframe because your application is not related to facebook compiler, u can use any java script , you are not forced to used FBL tags ). finally choose <span class="Apple-style-span" style="color: #0b5394;">Auto-resize</span> in the iframe size .</li>
</ul><div>at this stage we finish creating our application setting ;) now we will start Writing our code to connect with facebook.</div><div><br />
</div><div>as i found in my research that facebook keep upgrading their code and release new versions of API to allow users to connect with the facebook, so in this tutorial we will connect with facebook using the graph API which the latest version of facebook API.</div><div><br />
</div><div>so since we will use Flash AS3 to connect with facebook you need for sure to install the graph API as3 libraries to connect with facebook, so please click this link below to download this graph API.</div><div><br />
</div><div><a href="http://amazingwork.com/bloggtutorial/FaceBook/GraphAPI.rar">Graph API</a></div><div><br />
</div><div>after you installed the graph ApI, go to flash cs5 and create new flash AS3, then go to <span class="Apple-style-span" style="color: #0b5394;">file-->action script setting</span>, then as you can find in the picture below click the + sign and choose the <span class="Apple-style-span" style="color: #0b5394;">GraphAPI Web_1_0.sw</span>c as you can find in the .rar file .</div><div><br />
</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSHxD0W0RN6RlDvKvEuM-vKMYprPOjO4_8KPtoF3SGntBiLq9PrBUJYQU0lI8lQW9WWSgQHPJsZnpK8v65hoeEro0jyxZVUCfH416oFqNOIkytX3OldztEy_TD4gw-5wVkt_joXM1Tvyh/s1600/Action+script+library.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="237" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFSHxD0W0RN6RlDvKvEuM-vKMYprPOjO4_8KPtoF3SGntBiLq9PrBUJYQU0lI8lQW9WWSgQHPJsZnpK8v65hoeEro0jyxZVUCfH416oFqNOIkytX3OldztEy_TD4gw-5wVkt_joXM1Tvyh/s320/Action+script+library.png" width="320" /></a></div><div>now flash will recognize all the facebook classes .</div><div><br />
</div><div>P.S: if you need to create a desktop version please be aware to download the desktop version from google code :</div><div><a href="http://code.google.com/p/facebook-actionscript-api/">http://code.google.com/p/facebook-actionscript-api/</a></div><div>this will help you to test your API in offline mode before converted to the web version.</div><div>also you can download the whole documentation from the google code aslo.</div><div><br />
</div><div>now to make it easy for u i have created simple single tone class that handle the connection with facebook thru flash itself also u can use a java script to handle the connection :<br />
<br />
you can find the code of this class in the source files link in the bottom of this tutorial, so to use this class you need only to copy and paste it in your .fla folder, and then from any place you need to use this class functionality you can write this code :<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">var</span> oFaceBookConnector:FaceBookConnector = FaceBookConnector.GetFaceBook(Trace_txt);</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oFaceBookConnector.APKey = "b1762000d69544ebef65396dfe4a297a"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oFaceBookConnector.APPID = "181390918539668"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oFaceBookConnector.ReDirectURL ="http://amazingwork.com/fbexampletest/index.html"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oFaceBookConnector.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>("Connected",onFaceBookConnectHandler)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">oFaceBookConnector.Connect()</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>onFaceBookConnectHandler(e)</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Trace_txt.<span class="Apple-style-span" style="color: #0b5394;">text</span> = "Connected"</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>UserID_txt.<span class="Apple-style-span" style="color: #0b5394;">text </span>= oFaceBookConnector.UserInfo.UserID</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span><br />
<br />
<span class="Apple-style-span" style="font-family: inherit;">the Trace_txt is only for testing purpose and you can remove it when you finish your testing.</span><br />
<span class="Apple-style-span" style="font-family: inherit;">so as you can notice first of all i get the instant of the facebook object , then i set the importent properties i need to connect to facebook ( APkey, APPID, redirect URL - i use this url to set the permition for the first time user connect to my application)</span><br />
<span class="Apple-style-span" style="font-family: inherit;">also i created a custom event to know when my application successfully connected to the facebook .</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">after we publish the swf then you need to establish the connection using facebook Javascript graph API, and this can happens using any server pages ( PHP,ASP.net) or even an HTML page .</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">so after you publish the SWF and HTML page you need to modify the HTML page to connect with facebook.</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">first of all copy this code in your header tag :</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><<span class="Apple-style-span" style="color: #0b5394;">script type</span>="text/javascript" <span class="Apple-style-span" style="color: #0b5394;">src</span>="http://connect.facebook.net/en_US/all.js"></<span class="Apple-style-span" style="color: #0b5394;">script</span>></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><<span class="Apple-style-span" style="color: #0b5394;">script</span> <span class="Apple-style-span" style="color: #0b5394;">type</span>="text/javascript"></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">function </span>SetPermissions(ReDirectURL) { </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> <span class="Apple-style-span" style="color: #0b5394;">top.location.href</span> = ReDirectURL;</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> </span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> }</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"></<span class="Apple-style-span" style="color: #0b5394;">script</span>></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">in the body tag and before your SWF object you need to reference to the facebook java script bridge :</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><<span class="Apple-style-span" style="color: #0b5394;">script type</span>="text/javascript" <span class="Apple-style-span" style="color: #0b5394;">src</span>="FBJSBridge.js"></<span class="Apple-style-span" style="color: #0b5394;">script</span>></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">so by this you finish all itis need to connect to facebook :)</span><br />
<span class="Apple-style-span" style="font-family: inherit;">----------------------------------------------------------------------</span><br />
<span class="Apple-style-span" style="font-family: inherit;">you can download all you need by follow this link below :</span><br />
<div><br />
</div><br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><a href="http://amazingwork.com/fbexampletest/FaceBookConnector.rar">Source Files</a></span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><a href="http://apps.facebook.com/fbexampletest/">Online Demo</a></span><br />
<br />
if you have any question please feel free to contact me : abed_q@hotmail.com<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> </span><br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<div><span class="Apple-tab-span" style="white-space: pre;"><br />
</span></div><br />
<br />
<br />
<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: xx-small;"><br />
</span></div><div><br />
</div><div><br />
</div></div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com18tag:blogger.com,1999:blog-4313555014804023219.post-58364959294209060122010-12-07T01:33:00.000-08:002010-12-30T06:07:54.309-08:00Create Solid Color Picker Class using flash AS3<div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small;">please like and post your questions : </span><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: small;"><a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a></span></span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div class="separator" style="clear: both; text-align: left;"><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">in this tutorial you will learn how to create solid color picker from scratch using external class .</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0gtMpsplqCmHLhFPv2baVmjJ__7FnFrLo8rEm70VPR65cdhojZA-AY4FI-aGf62XCBXO_gCm7NEDfyfdoUsuH0r2UZ7DMu3BQ27TcjkrNmatiK65I4PV45NCZu_Xv2kHKCQGCU9z8TB21/s1600/SolidColorPickerResult.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0gtMpsplqCmHLhFPv2baVmjJ__7FnFrLo8rEm70VPR65cdhojZA-AY4FI-aGf62XCBXO_gCm7NEDfyfdoUsuH0r2UZ7DMu3BQ27TcjkrNmatiK65I4PV45NCZu_Xv2kHKCQGCU9z8TB21/s1600/SolidColorPickerResult.png" /></a></div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">in order to complete this tutorial you need to understand the following : </span><br />
<br />
<ul><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Mouse.hide(): Hide the Mouse cursor when rollover the color boxes because we will use custom cursor.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">graphics: graphic object is a powerful classes to draw primitive shapes with different styles in any display object.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">dispatchEvent(): we will create custom event dispatcher so we can know when the user select color box.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">extends: if we have an external class and we need to use it as a display object then we need to extend it from a movieclip or a sprite classes.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">transform.colorTransform: in order to change the color of any movie clip, you need to use color transform to apply new colors.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">mouseEnabled: some time we need to disable the mouse event on some object, and that is very helpful when you have nested movieclips and some of them are only used for graphics.</span></li>
<li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Sprite:a new amazing type in AS3 when you want to create display object without need for a timeline classes. </span></li>
</ul><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"></span><br />
<div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">create new movie clip on the stage and name it PacketContainer_mc then inside this movie create another movie and name it SelectedColor_mc and we will use this movie to show the current selected color.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">then in the first frame on the stage copy and paste below code :</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">PacketContainer_mc.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">MouseEvent.MOUSE_DOWN</span>,ShowSolidColor)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>ShowSolidColor(e)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>oSolidColorPicker = <span class="Apple-style-span" style="color: #0b5394;">new </span>SolidColorPicker(PacketContainer_mc,EyeDropper_mc,10)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oSolidColorPicker.<span class="Apple-style-span" style="color: #0b5394;">x</span> =PacketContainer_mc.<span class="Apple-style-span" style="color: #0b5394;">x</span> + PacketContainer_mc.<span class="Apple-style-span" style="color: #0b5394;">width</span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oSolidColorPicker.<span class="Apple-style-span" style="color: #0b5394;">y</span> = PacketContainer_mc.<span class="Apple-style-span" style="color: #0b5394;">y</span>+PacketContainer_mc.<span class="Apple-style-span" style="color: #0b5394;">height</span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oSolidColorPicker.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>("onColorSelected",onColorSelected)<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">addChild</span>(oSolidColorPicker)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-style-span" style="color: #0b5394;">function </span>onColorSelected(e)</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">{</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>oColorTransform = PacketContainer_mc.SelectedColor_mc.<span class="Apple-style-span" style="color: #0b5394;">transform.colorTransform;</span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>oColorTransform.color = e.currentTarget.SelectedColor;</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>PacketContainer_mc.SelectedColor_mc.<span class="Apple-style-span" style="color: #0b5394;">transform.colorTransform</span> = oColorTransform;<span class="Apple-tab-span" style="white-space: pre;"> </span></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">}</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">as you can notice when the user click the packet container movie we create new instant of our color picker class and pass following parameters</span></div><div><ol><li><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> PacketContainer_mc : some time you need to know which object refrence call this class.</span></li>
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">
<li>EyeDropper_mc : our new custom cursor, you can find it in the library.</li>
<li>10 : the size of each box in the color picker container matrix.</li>
</span></ol><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">so when the user click any box in the matrix we fire up custom event and call the onColorSelected function where we apply the new color to the selected Color Movie .</span></div></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">before build color picker class you need to know that each color we represent by 6 hexa decimal </span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">characters and to build the huge number of boxes we need an easy way, so i found the most of the boxes colors are derived from the following numbers:</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"> ("00", "33", "66", "99", "CC", "FF");</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">so by having a combinations of the above number we can actually get 216 color for example </span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">003366,003399,0033cc,336699,...,....</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">and the rest of the boxes is a default color boxes like the black,red,green,....and these colors we need to pass it manually 000000,00ff00,ff0000 and they are only 12.</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">so now all we need is to draw these boxes and the deafulat color boxes, and add the rollover event listener on each box and draw an outline white boarder and show the custom cursor .</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">-----------------------------------------------------------------</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><a href="http://amazingwork.com/BloggTutorial/SolidColorPicker/SolidColorPicker.html">Online Demo </a></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><a href="http://amazingwork.com/BloggTutorial/SolidColorPicker/SolidColorPicker.rar">Source Code</a></span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;">please if you have any question about the code just contact me on abed_q@hotmail.com</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div><span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div></div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com1tag:blogger.com,1999:blog-4313555014804023219.post-44689560369250958542010-12-06T21:41:00.001-08:002010-12-30T06:08:09.223-08:00Create Animated amazing Shapes using flash AS3<span class="Apple-style-span" style="color: #0b5394; font-size: x-small;"><span class="Apple-style-span" style="color: black; font-size: small;">please like and post your questions : </span><span class="Apple-style-span" style="color: black; font-size: small;"><a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a></span></span><br />
<span class="Apple-style-span" style="color: #0b5394; font-size: x-small;"><br />
</span><br />
<span class="Apple-style-span" style="color: #0b5394; font-size: x-small;">in this tutorial you will learn how to create amazing circular animated shapes as in the picture below :</span><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC4fplF0VE5otALeO4spWfzO2KlGsMk3ie2awz1t52DEB9-IV_7x9lATwBvEaI51S-uXfXd5H4vjdt2HA5h9z48DXvG3ADv99Yyw1S_8RfqsJnOz9SOYWIHtQiF-SGFq2bc9QpjaiaWIft/s1600/Output.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="color: #0b5394;"><img border="0" height="127" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC4fplF0VE5otALeO4spWfzO2KlGsMk3ie2awz1t52DEB9-IV_7x9lATwBvEaI51S-uXfXd5H4vjdt2HA5h9z48DXvG3ADv99Yyw1S_8RfqsJnOz9SOYWIHtQiF-SGFq2bc9QpjaiaWIft/s400/Output.png" width="400" /></span></a></div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">we will use the following AS3 build in functions and properties :</span><br />
<br />
<ul><li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">stage.stageWidth : this property is allow you to get the width of the stage ( and itis really helpful when you need to center the object or on resize events.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">stage.stageHeight : the same is stageWidth but we get the height of the stage instead of the width.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">MouseEvent : in AS3 when you need to fire a press event you need to use MouseEvent.MOUSE_DOWN along with the event listener and pass the mouse event as parameter to the caller function, and this is really a cool enhancement because you can now know the firing event and even the target which fire this event by using e.currentTarget.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Math.floor(Number): we use this when you want to get an integer value with the minimum value for example when you have a number with the range from 0.111 to .99999 the value will be always 0.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">Math.random(): get a float number between 0 and 1 .</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">setInterval( function, delay ): we will use the set interval to create the animation effect because i can call the same function every time defined by the delay number counted by milli second.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">clearInterval: when you want to stop calling this function.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">rotation : when you want to rotate the object, but please be aware the the object rotate based on its orientation point.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">gotoAndStop.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">addChild(child) : you will use addChild maybe in every application because now in AS3 you deal with stage movies as an array of display objects and it os really an amazing enhancement because now you have a lot of build in function to deal with these display objects. </span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">container.removeChild(Child) : to remove a specific display object from the container and in our case from the stage.</span></li>
<li><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">getChildByName(name): return a child using itis name.</span></li>
</ul><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;">so you need to start by create new as3 document, and then create new movie clip and name it Shape_mc and in this movie clip you need to create two layers, the first one will contain only a stop action and the over will contains several frames and in each frame you will draw a simple shape as you like .</span></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkbAu3pIoREmrA1Lrr6pAqOIvIVyTEZTGcYco4yGUfmonz89kX8zZKz3-sXQEZvEp8BfHQ7OfOTZUHGEkIZvUUsrheRzp_XPSmYKXMu9YHPNOP5di60oS-YyogAKfqttxOv0rclRVXbKEN/s1600/shapeframes.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span class="Apple-style-span" style="color: #0b5394;"><img border="0" height="297" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkbAu3pIoREmrA1Lrr6pAqOIvIVyTEZTGcYco4yGUfmonz89kX8zZKz3-sXQEZvEp8BfHQ7OfOTZUHGEkIZvUUsrheRzp_XPSmYKXMu9YHPNOP5di60oS-YyogAKfqttxOv0rclRVXbKEN/s320/shapeframes.png" width="320" /></span></a></div><div><span class="Apple-style-span" style="color: #0b5394; font-family: Arial, Helvetica, sans-serif; font-size: x-small;"><br />
</span></div><br />
<span class="Apple-style-span" style="color: #0b5394;">then you can remove the Shape_mc from the stage and linkage it to be used by action script at run time, then return to stage and add a new button from the component panel and then select the first firm in the stage to write the main code :</span><br />
<span class="Apple-style-span" style="color: #0b5394;"><br />
</span><br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">import flash.display.MovieClip;</span><br />
<span class="Apple-style-span" style="color: #0b5394;">import flash.events.MouseEvent;</span><br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">var </span>nStaticAngleMargin<span class="Apple-style-span" style="color: #0b5394;">:int</span> = 5<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nContainerXpos:<span class="Apple-style-span" style="color: #0b5394;">Number</span> = <span class="Apple-style-span" style="color: #0b5394;">stage.stageWidth </span>/ 2<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nContainerYpos<span class="Apple-style-span" style="background-color: white; color: #0b5394;">:Number </span>= s<span class="Apple-style-span" style="color: #0b5394;">tage.stageHeight</span> / 2 + 25<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nCallerDelay<span class="Apple-style-span" style="color: #0b5394;">:int</span>= 100<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nMaxAngle<span class="Apple-style-span" style="color: #0b5394;">:int</span> = 360;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>Container_mc:<span class="Apple-style-span" style="color: #0b5394;">MovieClip</span>;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nShapeInterval;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nAngleMargin<span class="Apple-style-span" style="color: #0b5394;">:int</span> = 0;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nFrameNumber<span class="Apple-style-span" style="color: #0b5394;">:int</span> = 1;<br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">function </span>ReDrawNewShape(e:<span class="Apple-style-span" style="color: #0b5394;">MouseEvent</span>)<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">if</span>(<span class="Apple-style-span" style="color: #0b5394;">getChildByName</span>("Container_mc")!=<span class="Apple-style-span" style="color: #0b5394;">null</span>)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">removeChild</span>(<span class="Apple-style-span" style="color: #0b5394;">getChildByName</span>("Container_mc"))<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc = new <span class="Apple-style-span" style="color: #0b5394;">MovieClip</span>()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc.<span class="Apple-style-span" style="color: #0b5394;">name</span> = "Container_mc"<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc.<span class="Apple-style-span" style="color: #0b5394;">x</span> = nContainerXpos<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc.<span class="Apple-style-span" style="color: #0b5394;">y</span> = nContainerYpos<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>nFrameNumber =<span class="Apple-style-span" style="color: #0b5394;">Math.floor</span>(<span class="Apple-style-span" style="color: #0b5394;">Math.random</span>()*100%5)+1<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">addChild</span>(Container_mc)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">clearInterval</span>(nShapeInterval)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>nAngleMargin = 0<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>nShapeInterval = <span class="Apple-style-span" style="color: #0b5394;">setInterval</span>(DrawShape,nCallerDelay)<br />
}<br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">function </span>DrawShape()<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">if</span>(nAngleMargin>nMaxAngle)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">clearInterval</span>(nShapeInterval)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">else</span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>oShape_mc = <span class="Apple-style-span" style="color: #0b5394;">new</span> Shape_mc()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>oShape_mc.<span class="Apple-style-span" style="color: #0b5394;">rotation </span>= nAngleMargin<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>nAngleMargin += nStaticAngleMargin<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>oShape_mc.<span class="Apple-style-span" style="color: #0b5394;">gotoAndStop</span>(nFrameNumber)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc.<span class="Apple-style-span" style="color: #0b5394;">addChild</span>(oShape_mc)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
}<br />
<br />
Play_btn.<span class="Apple-style-span" style="color: #0b5394;">addEventListener</span>(<span class="Apple-style-span" style="color: #0b5394;">MouseEvent.MOUSE_DOWN</span>,ReDrawNewShape)<br />
<br />
------------------------------<br />
<a href="http://amazingwork.com/bloggtutorial/animatedshapes/animatedshapes.html">Online Demo</a><br />
<a href="http://www.amazingwork.com/bloggtutorial/animatedshapes/animatedshapes.fla">Source files</a><br />
<br />
for further questions please contact me on : abed_q@hotmail.com.<br />
<br />
<div><br />
</div>Abed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0tag:blogger.com,1999:blog-4313555014804023219.post-45395482807958033092010-12-05T23:30:00.000-08:002010-12-30T06:08:23.580-08:00Create Grid view Using AS3 By Abed Allateef Qaisiplease like and post your questions : <a href="http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436">http://www.facebook.com/pages/FlashCS5-Tutorials/176320862386436</a><br />
<br />
any developer can face many times a need to view a content in multiple raws and columns and he always ends with a huge bunch of codes ;)<br />
<br />
in this tutorial you will learn how easily you can build a a grid view for your puzzle game using a light amount of codes.<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxLJGGiHpBhgBptIXox3FUIdRoNrdk2eRepqOC978a8sBDngFKu-v1qD4v8FdjpvA3mAv8DBkR1Os4fOrEX3WsbD8__O4DuTCftyFSFVBohrKwZwnTb_dQjCnllYJqLm9sNhSYU1tT6ugN/s1600/result.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxLJGGiHpBhgBptIXox3FUIdRoNrdk2eRepqOC978a8sBDngFKu-v1qD4v8FdjpvA3mAv8DBkR1Os4fOrEX3WsbD8__O4DuTCftyFSFVBohrKwZwnTb_dQjCnllYJqLm9sNhSYU1tT6ugN/s1600/result.png" /></a></div><br />
first of all for any Grid view we need to know how many columns and raws we need to view and also the width, and height margins between the contents objects.<br />
<br />
so create new flash file with AS3, then go to the first frame in your document or use the document class and define the following variables as we mention above:<br />
<br />
var nNumberOfColumns:int = 4;<br />
var nNumberOfRows:int = 4;<br />
var nHorizontalMargine:Number = 20; // in pixels<br />
var nVerticalMargine:Number = 20;<br />
var nContainerXpos:Number=0;<br />
var nContainerYpos:Number=0;<br />
<br />
after you defined the main variables, go to flash and create Block Movie Clip and name it Block_mc and create a dynamic text box and name it txtBlockNumber, after that we need to linkage the block movie by check the export for actionscript as you can notice in below image.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-mfkyHfcfz_2s9anc05EOQnRhuSEe0XasT0JI0OA0JhmrKPCTPfS5BZhqkD-ZuzZzohaAcTLezD1cNGPSO8ARQrGdP4lQvbNoo6GH2Y9mECYPegmPK4iZDv_UujLiCDnZnn55xfm3wqGh/s1600/Linkage+object+block.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-mfkyHfcfz_2s9anc05EOQnRhuSEe0XasT0JI0OA0JhmrKPCTPfS5BZhqkD-ZuzZzohaAcTLezD1cNGPSO8ARQrGdP4lQvbNoo6GH2Y9mECYPegmPK4iZDv_UujLiCDnZnn55xfm3wqGh/s400/Linkage+object+block.png" width="400" /></a></div><br />
so now all we need is to write the main code, the trick is simple we need to use math signs ( % , / ) to control the grid view, the % control the number of columns and / control the number of raws.<br />
<br />
The main code :<br />
<br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">import flash.display.Sprite;</span><br />
<span class="Apple-style-span" style="color: #0b5394;">import flash.display.MovieClip;</span><br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">var </span>nNumberOfColumns:<span class="Apple-style-span" style="color: #0b5394;">int</span> = 4;<br />
<span class="Apple-style-span" style="color: #0b5394;">var </span>nNumberOfRows:<span class="Apple-style-span" style="color: #0b5394;">int</span> = 4;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nHorizontalMargine:<span class="Apple-style-span" style="color: #0b5394;">Number</span> = 10;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nVerticalMargine:<span class="Apple-style-span" style="color: #0b5394;">Number</span> = 10;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nContainerXpos:<span class="Apple-style-span" style="color: #0b5394;">Number</span>=0;<br />
<span class="Apple-style-span" style="color: #0b5394;">var</span><span class="Apple-style-span" style="color: #0b5394;"> </span>nContainerYpos:<span class="Apple-style-span" style="color: #0b5394;">Number</span>=0;<br />
<br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">var </span>Container_mc:<span class="Apple-style-span" style="color: #0b5394;">Sprite </span>= <span class="Apple-style-span" style="color: #0b5394;">new Sprite()</span><br />
Container_mc.<span class="Apple-style-span" style="color: #0b5394;">x</span>=nContainerXpos<br />
Container_mc.<span class="Apple-style-span" style="color: #0b5394;">y</span>=nContainerYpos<br />
<span class="Apple-style-span" style="color: #0b5394;">addChild</span>(Container_mc)<br />
<br />
<span class="Apple-style-span" style="color: #0b5394;">var </span>nPuzzleBlocks:<span class="Apple-style-span" style="color: #0b5394;">int</span> = nNumberOfColumns*nNumberOfRows<br />
<span class="Apple-style-span" style="color: #0b5394;">for</span>( <span class="Apple-style-span" style="color: #0b5394;">var </span>i = 0; i < nPuzzleBlocks ; i++)<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-style-span" style="color: #0b5394;">var </span>oBlock_mc:<span class="Apple-style-span" style="color: #0b5394;">MovieClip</span> = <span class="Apple-style-span" style="color: #0b5394;">new</span> Block_mc()<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>oBlock_mc.txtBlockNumber.text = i+1 ;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>oBlock_mc.<span class="Apple-style-span" style="color: #0b5394;">x</span> = (i % nNumberOfColumns ) * (oBlock_mc.<span class="Apple-style-span" style="color: #0b5394;">height</span> + nHorizontalMargine)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>oBlock_mc.<span class="Apple-style-span" style="color: #0b5394;">y</span> = <span class="Apple-style-span" style="color: #0b5394;">Math.floor</span>(i / nNumberOfColumns ) * (oBlock_mc.<span class="Apple-style-span" style="color: #0b5394;">width</span> + nVerticalMargine)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Container_mc.<span class="Apple-style-span" style="color: #0b5394;">addChild</span>(oBlock_mc)<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
<br />
------------------------------------<br />
<a href="http://amazingwork.com/BloggTutorial/MatrixView/MatrixView.fla">Source Code</a><br />
<br />
for further question just contact me on abed_q@hotmail.comAbed Allateef Qaisihttp://www.blogger.com/profile/13121771868730969959noreply@blogger.com0