<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OMAR FALEH</title>
	<atom:link href="http://blog.morscad.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.morscad.com</link>
	<description>This is the blog of Omar Faleh. a Montreal-based Senior Flash Architect and web developer.</description>
	<lastBuildDate>Tue, 09 Jun 2009 02:31:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>wordpress flash API &#8211; sample code &#8211; Part 2</title>
		<link>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-2/</link>
		<comments>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-2/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 02:31:21 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/?p=51</guid>
		<description><![CDATA[This post is part two of the AMF/PHP connector class that I started in a previous thread talking about the PHP part
now.. we go to flash. The first class is the DataConnector which establishes the connection to the AMF/PHP connector and calls the function
we declare a variable called callTitle which is assigned based on which [...]]]></description>
			<content:encoded><![CDATA[<p>This post is part two of the<a href="http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-1/"> AMF/PHP connector class</a> that I started in a previous thread talking about the PHP part</p>
<p>now.. we go to flash. The first class is the DataConnector which establishes the connection to the AMF/PHP connector and calls the function<br />
we declare a variable called callTitle which is assigned based on which function we&#8217;re calling. this variable is then used to decide what action to do in the event listener.
</p>
<pre>
package data
{
	import events.Communicator;

	import flash.events.*;
	import flash.net.NetConnection;
	import flash.net.Responder;

	public class DataConnector extends EventDispatcher
	{

		private var gateway			:String ;
		private var callTitle		        :String = "";
		private var connection		:NetConnection;
		private var responder		:Responder;

		public function DataConnector()
		{

			gateway	= "./connectors/gateway.php";

			responder = new Responder(onResult, onFault);
			connection = new NetConnection;
			connection.connect(gateway);
		}

		public function <strong>getCategoryList</strong>(parentCatName:String = ""):void
		{
			callTitle = "getCategoryList";
			parentCategory = parentCatName;
			connection.call("functions.getCategoryList", responder , parentCatName);
		}
		public function <strong>getCategoryPosts</strong>(_catName:String = ""):void
		{
			callTitle = "getCategoryPosts";
			catName = _catName;
			connection.call("functions.getCategoryPosts", responder , catName);
		}

		public function <strong>getPostList</strong>():void
		{
			callTitle = "getPostList";
			connection.call("functions.getPostList", responder);
		}

		public function <strong>getPost</strong>(id:String):void
		{
			callTitle = "getPost";
			postID = id;
			connection.call("functions.getPost", responder , postID);
		}

		private function <strong>onResult</strong>(result:Object):void
		{
			switch (callTitle)
			{
			 	case "getCategoryList":
			 		result = result as Array;
			 		var _cat:Array = new Array();
			 		for (var i:int=0; i &lt;result.length; i++)
					{
						var _obj:Object = new Object();
						_obj.id 	= result[i].id ;
						_obj.title 	= result[i].title ;
						_obj.desc	= result[i].description;
						cat.push(obj)
					}
					// now do something with that array
			 	break;

			 	case "getPostList":
			 	       result = result as Array;
			 		var _cat:Array = new Array();
			 		for (var i:int=0; i&lt;result.length; i++)
					{
						var _obj:Object = new Object();
						_obj.id 	= result[i].id ;
						_obj.title 	= result[i].title ;
						cat.push(obj)
					}
					// now do something with that array
			 	break;

			 	case "getCategoryPosts":
			 	       result = result as Array;
			 		var _cat:Array = new Array();
			 		for (var i:int=0; i&lt;result.length; i++)
					{
						var _obj:Object = new Object();
						_obj.index= result[i].index ;
						_obj.id 	= result[i].id ;
						_obj.title 	= result[i].title ;
						cat.push(obj)
					}
					// now do something with that array
			 	break;

			 	case "getPost":
			 		result = result as Object;
					// do something with the object
					// like trace(result.post.title) , trace(result.post.content) , trace(result.post.date)
					// and:
					// for (var i:int=0; i&lt; result.meta.length; i++)
					// {
					//       trace(result.meta[i].index , " : " , result.meta[i].value);
					// }
			 	break;

			}
		}

		private function onFault(fault:Object):void
		{
			trace(String(fault.description));
		}
	}
}
</pre>
<p>This class can now be called from the parent class (Main for example) in the following fashion:</p>
<pre>
package
{
	import data.DataConnector;
	import flash.display.Sprite;
	import flash.events.*;

	public class Main extends Sprite
	{
		private var _dataConnector <img src='http://blog.morscad.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ataConnector;

               public function Main()
		{
			_dataConnector = new DataConnector();
			_dataConnector.getCategoryList("cat1");
		}
         }
}
</pre>
<p>the way I usually do its is follow this sequence:<br />
Main -> DataConnector -> call Function<br />
DataConnector ->receive Call result and handle Data<br />
DataConnector -> Dispatch Event with the handled Data<br />
Main -> receive the event in an event listener -> use the data.</p>
<p>but again, this sequence is very dependant on the structure of your classes and projects.. so now you&#8217;re on your own&#8230; </p>
<p>hope this was helpful enough</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>wordpress flash API &#8211; sample code &#8211; Part 1</title>
		<link>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-1/</link>
		<comments>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-1/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 01:56:37 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/?p=47</guid>
		<description><![CDATA[so after some expermintations, I could finally get around to posting my findings.. available for people to grab should they wish to.
a big credit is due to Tim Wilson on his library which was the basis of all the work I have done in here. I only changed the return types of the functions to [...]]]></description>
			<content:encoded><![CDATA[<p>so after some expermintations, I could finally get around to posting my findings.. available for people to grab should they wish to.</p>
<p>a big credit is due to <a href="http://tvwonline.net/lab/pressconnect/">Tim Wilson</a> on his library which was the basis of all the work I have done in here. I only changed the return types of the functions to be of custom data types instead of XML.</p>
<p>steps of reproduction:<br />
1- download the AMFPHP package from <a href="http://sourceforge.net/project/showfiles.php?group_id=72483#files">http://sourceforge.net/project/showfiles.php?group_id=72483#files</a></p>
<p>2- unzip the package in your flash export folder (WWW for example, or DEPLOY, or whatever you call it).. put all the AMF files inside a folder and name it as you wish (I am going to call it <strong>connectors</strong> for example</p>
<p>3- in services/DatabaseRequest.php fill in your appropriate username/password/db name and hostname</p>
<p>4-go to services/functions.php and write your functions there.. I am using these functions:</p>
<pre>
function <strong>getPostList</strong>()
{
	$dbc = new DatabaseRequest();
	$db_query = $dbc->call("SELECT * FROM wp_posts WHERE post_status='publish' AND post_type !='page' ORDER BY ID DESC");		

	$posts = array();
	$i =0;

	while ($fields = mysql_fetch_array($db_query))
	{
		$posts[$i] = array(id=>$fields['ID'] , title => $fields['post_title']);
		$i ++;
	}

	return $posts;
}
</pre>
<p>and</p>
<pre>
function <strong>getCategoryList</strong>($parentCategorySlug)
{ 

	$dbc = new DatabaseRequest();

	$query = "SELECT wp_terms.slug, wp_terms.name, wp_term_taxonomy.description FROM wp_terms, wp_term_taxonomy WHERE wp_terms.term_id = wp_term_taxonomy.term_id AND wp_term_taxonomy.taxonomy = 'category'".
				(($parentCategorySlug != "") ? "AND wp_term_taxonomy.parent IN ( SELECT term_id FROM wp_terms WHERE wp_terms.slug LIKE '".$parentCategorySlug."')" : "") ;

	$db_query = $dbc->call($query);        

	$arr = array();
	$i=0;

	while ($fields = mysql_fetch_array($db_query))
	{
		$arr[$i] = array(title =>$fields['name'] , id => $fields['slug'] , description=>$fields['description']);
		$i ++;
	}
	return $arr;
}
</pre>
<p>and</p>
<pre>
function <strong>getCategoryPosts</strong>($categorySlug)
{
	$dbc = new DatabaseRequest();
	$db_query = $dbc->call("SELECT * FROM wp_posts
							LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id )
							LEFT JOIN wp_term_taxonomy ON ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id )
              				WHERE wp_posts.post_status = 'publish' AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id in
							(SELECT term_id FROM wp_terms WHERE wp_terms.slug LIKE '".$categorySlug."')" );

	$posts = array();
	$i =0;

	while ($fields = mysql_fetch_array($db_query))
	{
		$indexQuery = "SELECT meta_value FROM wp_postmeta  WHERE post_id =".$fields['ID']." AND meta_key LIKE 'index'";
		$db_query1 = $dbc->call($indexQuery );
		$index = mysql_fetch_array($db_query1);

		$posts[$i] = array(index => $index[0] , id => $fields['ID'] , title =>$fields['post_title']);
		$i++;
	}
	return $posts;
}
</pre>
<p>and </p>
<pre>
function <strong>getPost</strong>($postID)
{

	$dbc = new DatabaseRequest();
       $query ="
		SELECT * FROM wp_posts	WHERE wp_posts.ID=".$postID." AND wp_posts.post_status = 'publish'";

	$db_query = $dbc->call($query);

	$fields = mysql_fetch_array($db_query);
	$post = $fields[0];
	$arr=array();

	if(count($fields) == 1)
	{
		createFailMessage('Post Not Found');
	}
	else
	{
	$post = array(	id=> $fields['ID'] ,
				title=>$fields['post_title'] ,
				content => $fields['post_content'] ,
				date=> $fields['post_modified_gmt']
				 );

	// Get any Custom Fields for this Post.
	$additionalFields = $dbc->call("SELECT * FROM wp_postmeta WHERE post_id='".$fields['ID']."';");
	$extrFields = array();
	$j=0;
	while ($customField = mysql_fetch_array($additionalFields))
	{
		$extrFields[$j] = array(
				index => $customField['meta_key'],
				value => $customField['meta_value']
			);
		$j++;
	}

	$result = array(post => $post , meta =>$extrFields);

	return $result;
}
</pre>
<p>the beauty of AMF/PHP is that you can get returns in the form of objects, arrays, multidimensional arrays, and objects that has properties that are a mix of arrays and regular data types.. </p>
<p>so now, we have all the PHP functions that need to be called in order to get data from the Database&#8230; notice that in the <strong>getPost</strong> function, I am also returning the meta fields associated with the post, based on that post ID.</p>
<p>the flash part of that communication will be in part 2 of this post</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-sample-code-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>papervision 3D optimization tip #1</title>
		<link>http://blog.morscad.com/uncategorized/papervision-3d-optimisation-tip-1/</link>
		<comments>http://blog.morscad.com/uncategorized/papervision-3d-optimisation-tip-1/#comments</comments>
		<pubDate>Fri, 29 May 2009 15:35:12 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/?p=42</guid>
		<description><![CDATA[I am not a big papervision fan, and I don&#8217;t usually hide it.
PV3D is interesting and versatile, and allows great flexibility in developing great websites and apps, however it&#8217;s always a pain to optimize, and I always end up spending 40% of my development time dealing with memory leaks, optimization techniques, objects that don&#8217;t really [...]]]></description>
			<content:encoded><![CDATA[<p>I am not a big papervision fan, and I don&#8217;t usually hide it.</p>
<p>PV3D is interesting and versatile, and allows great flexibility in developing great websites and apps, however it&#8217;s always a pain to optimize, and I always end up spending 40% of my development time dealing with memory leaks, optimization techniques, objects that don&#8217;t really get removed from stage, events that don&#8217;t get fired.. etc&#8230; and now that I moved to flex development and have a profiler running on my applications, I see the incredible amount of junk that remain alive in the stage after 3d objects are removed.</p>
<p>so I started a quest to look for optimization techniques on the net, and bank them to get a reference for later projects.. here is the first one, courtesy of Seb Lee-Delisle </p>
<p><a href="http://interactivehug.com/2008/04/21/john-iacoviello-papervision3d-optimization-tips/#comment-463", target="_blank">http://interactivehug.com/2008/04/21/john-iacoviello-papervision3d-optimization-tips/#comment-463 </a></p>
<blockquote><p>if you set your bitmap sizes to exponents of two, ie, 64, 128, 256, 512 etc. that way the built-in mipmapping in the FlashPlayer will enable much faster and smoother bitmap scaling and manipulation.</p>
<p>So a bitmap sized 512 x 512 will work a lot better than one that is 500 x 500</p>
</blockquote>
<p>this is really interesting, we never actually take those things into consideration when we develop our code as we get the files from designers. will do some benchmarking and get back on that topic</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/uncategorized/papervision-3d-optimisation-tip-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wordpress flash API &#8211; pre production</title>
		<link>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-pre-production/</link>
		<comments>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-pre-production/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 17:06:39 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/?p=38</guid>
		<description><![CDATA[I am in my 3rd week down the ugly road of redesigning my pathetic 5 year old, HTML only website now with broken databases)
as any other flash programmer would do, we try to use everything we know in remaking our website, which eventually leaves us stuck not doing anything cos we try to integrate everything [...]]]></description>
			<content:encoded><![CDATA[<p>I am in my 3rd week down the ugly road of redesigning my pathetic 5 year old, HTML only website now with broken databases)</p>
<p>as any other flash programmer would do, we try to use everything we know in remaking our website, which eventually leaves us stuck not doing anything cos we try to integrate everything at the same time</p>
<p>so I decided to go with the Backend CMS option (not that I have regularly updated content or anything) but more for the search engine optimisation reasons. so I decided to go with the natural solution of using wordpress as a backend, and connecto to its database using something&#8230;. and that &#8220;something&#8221; became a whole week work of research..</p>
<p>turns out that, as popular wordpress is, there is no out-of-the-box solution (open source of course) that you can use to connect to it.<br />
the closest  found was <a href="http://timwilson.net.au/flash/">Tim Wilson</a>&#8217;s <a href="http://tvwonline.net/lab/pressconnect/" , "_blank">Press Connect </a>. which provides a very nice connection, only the only way I found to use it was through AS2 with the XML.sendAndLoad() interface.. and that of course does not work if you are planning to use AS3</p>
<p>so I decided to take the plunge and write my own connectors, basing my self on Tim Wilson&#8217;s code, and use AMFPHP to be the middle man. production started officially last thursday, and I am hoping that by the end of the weekend I will have most of my connectors ready for use.. and will probably share it on my blog for those who need some help doing what I am trying to do..</p>
<p>so, stay tuned&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/actionscript-30/wordpress-flash-api-pre-production/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller</title>
		<link>http://blog.morscad.com/code-snippets/argumenterror-error-2025-the-supplied-displayobject-must-be-a-child-of-the-caller/</link>
		<comments>http://blog.morscad.com/code-snippets/argumenterror-error-2025-the-supplied-displayobject-must-be-a-child-of-the-caller/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:52:55 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/code-snippets/argumenterror-error-2025-the-supplied-displayobject-must-be-a-child-of-the-caller/</guid>
		<description><![CDATA[one of those little things that are not clearely documented or explained anywhere on the Adobe flash documentation..
I was calling a function to load an image and add it to stage, and everytime I called that image, I was getting this error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
after 2 [...]]]></description>
			<content:encoded><![CDATA[<p>one of those little things that are not clearely documented or explained anywhere on the Adobe flash documentation..<br />
I was calling a function to load an image and add it to stage, and everytime I called that image, I was getting this error:</p>
<p><b>ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller</b></p>
<p>after 2 hours of trials and errors and 1 hour of web search, I finally found the answer below.</p>
<p>within this code:</p>
<pre>package{
	import flash.display.DisplayObject;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.net.URLRequest;
public class img extends Sprite
{
	private var loader:Loader = new Loader();
	...
	..
	public function loadBgImage():void
	{
		var randDate:Date = new Date();
		if (holder.getChildByName("bgImg"))
		{
			if (holder.contains(holder.getChildByName("bgImg")))
				holder.removeChild(holder.getChildByName("bgImg"))
		}
		var request:URLRequest = new URLRequest("images/bg.jpg?randPath="+randDate.getTime());
		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
		loader.load(request);
	}
	public function completeHandler(e:Event):void
	{

		var bm:Bitmap = e.target.contentas Bitmap;
		bm.smoothing = true;
		var sp:Sprite = new Sprite();
		sp.addChild(bm);
		sp.name = "bgImg";
		holder.addChild(sp);
	}
}</pre>
<p>it works fine the first time.. however, while in runtime, if you try to call loadBgImage() again, you will get this error:</p>
<pre>
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
</pre>
<p>and after lots of research, it turns out that this occurs when the Loader is declared as a global variable in the class (i.e: when we don&#8217;t say :var loader:Loader = new Loader() every time we call the function) and the load() function is called again after the first load</p>
<p>when the COMPLETE event is fired, if we add the  loader to stage as a e.target.content, then we are actually adding the only instance of that loader (Loader is a DisplayObject after all)<br />
so, if we try to remove it in the load function and remove it before calling the function again:</p>
<pre>holder.removeChild(holder.getChildByName("bgImg"))</pre>
<p>then we are actually removing the only instance of that loader, so when we try to call it again onloader.load(), the instance is not found..</p>
<p>Thanks to the fine gentelmen at Actionscript.or, this discussion solved my problem:<br />
<a href="http://www.actionscript.org/forums/archive/index.php3/t-138634.html" , "_blank">http://www.actionscript.org/forums/archive/index.php3/t-138634.html </a></p>
<p>so, the best way to do this is:<br />
1- cast the content to a display Object, and unload the loader, and then add the newly created display Object to the stage : see below</p>
<pre>

public function completeHandler(e:Event):void
{
	var theImage:DisplayObject = e.target.content;
	loader.unload()
	var bm:Bitmap = theImage as Bitmap;
	bm.smoothing = true;
	var sp:Sprite = new Sprite();
	sp.addChild(bm);
	sp.name = "bgImg";
	holder.addChild(sp);
}
</pre>
<p>or, the second way to do this is:<br />
2- get the bitmap data of that loaded content, make a clone, instantiate a new bitmap based on that bitmap data, and add that one to stage like this:</p>
<pre>

public function completeHandler(e:Event):void
{

	var bm:Bitmap = new Bitmap(((e.target.content as Bitmap).bitmapData as BitmapData).clone());
	bm.smoothing = true;
	var sp:Sprite = new Sprite();
	sp.addChild(bm);
	sp.name = "bgImg";
	holder.addChild(sp);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/argumenterror-error-2025-the-supplied-displayobject-must-be-a-child-of-the-caller/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bulk Loader and SWF Caching issues</title>
		<link>http://blog.morscad.com/code-snippets/bulk-loader-and-swf-caching-issues/</link>
		<comments>http://blog.morscad.com/code-snippets/bulk-loader-and-swf-caching-issues/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 19:18:12 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/code-snippets/bulk-loader-and-swf-caching-issues/</guid>
		<description><![CDATA[while working with bulk loader on a big project recently, we were hit by one problem that took me a while to solve.
the problem was basically this: if you load an swf with bulkloader, everything looks fine and well..
unload it, try to load it again and it won&#8217;t load.. simply becase it is already in [...]]]></description>
			<content:encoded><![CDATA[<p>while working with bulk loader on a big project recently, we were hit by one problem that took me a while to solve.<br />
the problem was basically this: if you load an swf with bulkloader, everything looks fine and well..<br />
unload it, try to load it again and it won&#8217;t load.. simply becase it is already in the cache of the browser , so the COMPLETE event was never firedthe second time.</p>
<p>I tried to set the {forceCache:false} in the case of loading an swf and that didn&#8217;t work also (it added a random string number after the name of the swf, and the  container flash won&#8217;t load the swf at all in that case)</p>
<p>so.. here is the result of a full day of investigation</p>
<pre>if (loader.hasItem(this.id[0] , true))
{
	loader.remove(this.id[0]);
}
loader.add(this.bg[0], { id:this.id[0]} );	</pre>
<p>this way, the onComplete event will get fired after loading the swf for the second time, even though it&#8217;s already loaded and present in the cache</p>
<p>simple.. yet not documented properly</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/bulk-loader-and-swf-caching-issues/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Double Buffering for smooth netstream FLV playback</title>
		<link>http://blog.morscad.com/code-snippets/double-buffering-for-smooth-netstream-flv-playback/</link>
		<comments>http://blog.morscad.com/code-snippets/double-buffering-for-smooth-netstream-flv-playback/#comments</comments>
		<pubDate>Wed, 28 May 2008 19:36:42 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/code-snippets/double-buffering-for-smooth-netstream-flv-playback/</guid>
		<description><![CDATA[This post is to highlight the double buffering technique (also known as dynamic buffering) that &#8220;should&#8221; make video streaming in flash alot smoother without having to prebuffer anything.
This technique works on progressive video download as well as streaming:

var startBufferLength:Number= 2; //keep this in the range 2-4+
var xpandedBufferLength:Number = 15;  //arbitrarily highnc = new NetConnection();
nc.connect(null);
ns [...]]]></description>
			<content:encoded><![CDATA[<p>This post is to highlight the double buffering technique (also known as dynamic buffering) that &#8220;should&#8221; make video streaming in flash alot smoother without having to prebuffer anything.</p>
<p>This technique works on progressive video download as well as streaming:</p>
<pre>
var startBufferLength:Number= 2; //keep this in the range 2-4+
var xpandedBufferLength:Number = 15;  //arbitrarily highnc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.setBufferTime(3);
ns.autoPlay = false;
ns.onStatus = Delegate.create(this, handleVideoStatus);//(if this was AS3 the syntax will be:
//ns.addEventListener(NetStatusEvent.NET_STATUS, handleVideoStatus);

// if this was Actionscript 3, this following line would be:
// private function handleStatus(event:NetStatusEvent):void 

function handleVideoStatus(infoObject:Object)
{

	switch (infoObject.code) {
		case "NetConnection.Connect.Success":

		break;

		case "NetStream.Buffer.Full":
			ns.bufferTime = xpandedBufferLength;
		break;

		case "NetStream.Buffer.Empty":
			ns.bufferTime = startBufferLength;
		break;

		case "NetStream.Play.Start":
			// the video has started playing, do something here
		break;

		case "NetStream.Play.Stop" :
			// the video has stopped playing (finished)
		break;

	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/double-buffering-for-smooth-netstream-flv-playback/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Reading from and writing to shared object</title>
		<link>http://blog.morscad.com/code-snippets/reading-from-and-writing-to-shared-object/</link>
		<comments>http://blog.morscad.com/code-snippets/reading-from-and-writing-to-shared-object/#comments</comments>
		<pubDate>Wed, 28 May 2008 18:36:59 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/code-snippets/reading-from-and-writing-to-shared-object/2008/05/28/</guid>
		<description><![CDATA[Reading the shared object:

var my_so:SharedObject = SharedObject.getLocal("SomeName");
var trackingDate:Date = my_so.data.theDate
writing to a shared object:

var my_so:SharedObject = SharedObject.getLocal("SomeName");
var _date = new Date();
my_so.data.theDate = _date;
my_so.flush(10000);
and clearing a shared object (erasing its content)

var my_so:SharedObject = SharedObject.getLocal("SomeName");
my_so.clear();
]]></description>
			<content:encoded><![CDATA[<p>Reading the shared object:</p>
<pre>
var my_so:SharedObject = SharedObject.getLocal("SomeName");
var trackingDate:Date = my_so.data.theDate</pre>
<p>writing to a shared object:</p>
<pre>
var my_so:SharedObject = SharedObject.getLocal("SomeName");
var _date = new Date();
my_so.data.theDate = _date;
my_so.flush(10000);</pre>
<p>and clearing a shared object (erasing its content)</p>
<pre>
var my_so:SharedObject = SharedObject.getLocal("SomeName");
my_so.clear();</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/reading-from-and-writing-to-shared-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loader flash calls a function from the loaded flash</title>
		<link>http://blog.morscad.com/code-snippets/loader-flash-calls-a-function-from-the-loaded-flash/</link>
		<comments>http://blog.morscad.com/code-snippets/loader-flash-calls-a-function-from-the-loaded-flash/#comments</comments>
		<pubDate>Wed, 28 May 2008 18:27:00 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/code-snippets/loader-flash-calls-a-function-from-the-loaded-flash/2008/05/28/</guid>
		<description><![CDATA[let&#8217;s imagine this scenario:
A.swf loads B.swf
after load is completed,A.swf needs to execute a function in B.swf called runCommands() for example.. here is the code for that (this is the code inside A.swf):

import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.*;
import flash.net.URLRequest;

...

var loaderRequest:URLRequest = new URLRequest("B.swf");
var movieLoader:Loader = new Loader();
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
movieLoader.load(loaderRequest)....

function completeHandler(_event:Event)
{

	var _loaderInfo:LoaderInfo = _event.target as LoaderInfo;
	var loadedObject:Object = _loaderInfo.content;
	loadedObject.runCommands()
}
]]></description>
			<content:encoded><![CDATA[<p>let&#8217;s imagine this scenario:<br />
A.swf loads B.swf<br />
after load is completed,A.swf needs to execute a function in B.swf called runCommands() for example.. here is the code for that (this is the code inside A.swf):</p>
<pre>
import flash.display.Loader;
import flash.display.<span class="searchhilite">LoaderInfo</span>;
import flash.events.*;
import flash.net.URLRequest;

...

var loaderRequest:URLRequest = new URLRequest("B.swf");
var movieLoader:Loader = new Loader();
movieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
movieLoader.load(loaderRequest)....

function completeHandler(_event:Event)
{

	var _loaderInfo:LoaderInfo = _event.target as LoaderInfo;
	var loadedObject:Object = _loaderInfo.content;
	loadedObject.runCommands()
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/loader-flash-calls-a-function-from-the-loaded-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Events</title>
		<link>http://blog.morscad.com/code-snippets/26/</link>
		<comments>http://blog.morscad.com/code-snippets/26/#comments</comments>
		<pubDate>Mon, 03 Dec 2007 00:13:20 +0000</pubDate>
		<dc:creator>Omar Faleh</dc:creator>
				<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://blog.morscad.com/uncategorized/26/2007/12/02/</guid>
		<description><![CDATA[Creating custom events in AS3 is really easy, and very powerful. example:
lets say that there is a custom event that should be fired when a &#8220;Tween Lite&#8221; animation is done playing. we start by creating the custom event :

package  {
	import flash.events.*;

	public class FinishedEvent extends Event{

		private var trackingValue:String;
		public static var DO_SOMETHING= "do_something"

		public function FinishedEvent(type:String , [...]]]></description>
			<content:encoded><![CDATA[<p>Creating custom events in AS3 is really easy, and very powerful. example:</p>
<p>lets say that there is a custom event that should be fired when a &#8220;<a href="http://blog.greensock.com/tweenliteas3" target="_blank">Tween Lite</a>&#8221; animation is done playing. we start by creating the custom event :</p>
<pre>
package  {
	import flash.events.*;

	public class FinishedEvent extends Event{

		private var trackingValue:String;
		public static var DO_SOMETHING= "do_something"

		public function FinishedEvent(type:String , someValue:String) {
 			super(type);
			trackingValue = someValue;

		}

		public function getDispatcherName()
 		{
 			return  trackingValue;
 		}
	}
}</pre>
<p><span id="more-26"></span><br />
now, somewhere in the code, we have these lines:</p>
<pre>

public class someClass extends MovieClip
 	{
	....

	....

	TweenLite.to(   _someMovieClip,
			1 ,         // duration
			{
				x:100,
 				y:100,
	 			ease:Quadratic.easeInOut
 			} ,
 			0 ,            // delay
 			finishedFunction        // function to be
						//called on finish animation

 		);

	public function  finishedFunction()
 	{

		// the Finished event constructor can have an optional value
		// that we can pass to it for identification
		dispatchEvent(new FinishedEvent(FinishedEvent.DO_SOMETHING ,
						_someMovieClip.name));

	}

...

....

}</pre>
<p>now somewhere else in the code, in some other class (or possibly in the same class):</p>
<pre>........

var _someObject:someClass = new someClass();

.....

.....

_someObject.addEventListener(FinishedEvent.DO_SOMETHING , callBackFunction);

public function callBackFunction(_event:FinishedEvent)
{
	trace(_event.getDispatcherName() )
}</pre>
<p>This way, if we have several objects animating with a tween lite call , we can identify which one is finished animating with:</p>
<pre>_event.getDispatcherName()</pre>
<p>and do something by detecting the name and calling the appropriate functions if we know the name of the object that we want to track</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.morscad.com/code-snippets/26/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
