<?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>Aboutme - blog &#187; Actionscript 2.0</title>
	<atom:link href="http://blog.aboutme.be/category/actionscript-20/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.aboutme.be</link>
	<description></description>
	<lastBuildDate>Sun, 21 Feb 2010 15:47:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CakeSWXPHP &#8211; updated to SWX 2.0 beta 1</title>
		<link>http://blog.aboutme.be/2008/12/23/cakeswxphp-updated-to-swx-20-beta-1/</link>
		<comments>http://blog.aboutme.be/2008/12/23/cakeswxphp-updated-to-swx-20-beta-1/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 23:24:07 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Actionscript 3.0]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[cakeswxphp]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/?p=90</guid>
		<description><![CDATA[The first beta of the new version of SWX was released yesterday. This new version brings AS3 and Flash Player 10 support. I decided to update CakeSWXPHP, to support this new version of SWX. You can download a new version, from my CakeSWXPHP page.
]]></description>
			<content:encoded><![CDATA[<p>The first beta of the <a href="http://swxformat.org/192">new version of SWX was released yesterday</a>. This new version brings AS3 and Flash Player 10 support. I decided to update CakeSWXPHP, to support this new version of SWX. You can <a href="http://blog.aboutme.be/cakeswxphp/">download a new version, from my CakeSWXPHP page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2008/12/23/cakeswxphp-updated-to-swx-20-beta-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWX explorer with code generation</title>
		<link>http://blog.aboutme.be/2007/10/14/swx-explorer-with-code-generation/</link>
		<comments>http://blog.aboutme.be/2007/10/14/swx-explorer-with-code-generation/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 12:04:56 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/10/14/swx-explorer-with-code-generation/</guid>
		<description><![CDATA[I took the time today to add a simple code generator to the SWX service explorer. Right now, it spits out inline AS2 code for your service methods. I&#8217;ll add AS2 class generation and ARP code generation in the near future&#8230;
Download the source code
or
Try it online
Enjoy!
]]></description>
			<content:encoded><![CDATA[<p>I took the time today to add a simple code generator to the SWX service explorer. Right now, it spits out inline AS2 code for your service methods. I&#8217;ll add AS2 class generation and ARP code generation in the near future&#8230;</p>
<p><a href='http://blog.aboutme.be/wp-content/uploads/2007/10/swx_explorer_codegenerator_01.zip' title=''>Download the source code</a><br />
or<br />
<a href="http://labs.aboutme.be/swx/php/explorer/">Try it online</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/10/14/swx-explorer-with-code-generation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>flash remoting with SWX and CakePHP</title>
		<link>http://blog.aboutme.be/2007/09/30/flash-remoting-with-swx-and-cakephp/</link>
		<comments>http://blog.aboutme.be/2007/09/30/flash-remoting-with-swx-and-cakephp/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 01:56:25 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[cakeswxphp]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/09/30/flash-remoting-with-swx-and-cakephp/</guid>
		<description><![CDATA[So, you want to learn how to create a sexy blog in flash, creating posts, comments, database storage, &#8230;? Are you afraid of spending hours writing complex queries, parsing XML data or writing loads of php files? Don&#8217;t be, and see the power of cakephp and SWX combined. CakePHP being a rapid development framework for [...]]]></description>
			<content:encoded><![CDATA[<p>So, you want to learn how to create a sexy blog in flash, creating posts, comments, database storage, &#8230;? Are you afraid of spending hours writing complex queries, parsing XML data or writing loads of php files? Don&#8217;t be, and see the power of <a href="http://www.cakephp.org" target="_blank">cakephp</a> and <a href="http://swxformat.org" target="_blank">SWX</a> combined. CakePHP being a rapid development framework for PHP and SWX, the native data format for the flash platform!<span id="more-30"></span></p>
<p>If you don&#8217;t have a running webserver with PHP + mysql + phpmyadmin yet, you&#8217;ll have to 	install these packages first.</p>
<ul>
<li>Windows users can <a target="_blank" href="http://www.wampserver.com/en/">install WAMP</a>, which will install these packages at once on your development machine.</li>
<li>Mac users can <a target="_blank" href="http://sourceforge.net/projects/mamp">install MAMP</a>, which does the same (there is a MAMP bundle on swxformat, but we won&#8217;t use this one, as we&#8217;ll need to copy SWX to another directory anyway to work with cakephp).</li>
</ul>
<p>When you have your webserver set up, we&#8217;ll <a target="_blank" href="http://cakephp.org/downloads">download the latest version of cakephp</a>. Unzip it to you webroot (WAMP default: C:\wamp\www &#8211; MAMP default: /Applications/MAMP/htdocs) and rename the unzipped directory to &#8220;flashblog&#8221;. You now have the following file structure:</p>
<ul>
<li>WWW</li>
<ul>
<li>flashblog</li>
<ul>
<li>app</li>
<li>cake</li>
<li>docs</li>
<li>index.php</li>
<li>vendors</li>
</ul>
</ul>
</ul>
<p>If you are deploying on a webserver, make sure the app/tmp/ directory and it&#8217;s subdirectories are writeable (chmod 777).</p>
<p>After that, we&#8217;ll add <a target="_blank" href="http://blog.aboutme.be/cakeswxphp">cakeswxphp</a> to our cake install. <a target="_blank" href="http://blog.aboutme.be/cakeswxphp">Download cakeswxphp</a> and unzip it somewhere on your computer. Copy/Paste the content of the app and vendors dir of cakeswxphp to the same directories of your flashblog directory. If you did everything correctly, you can point your browser to: <a target="_blank" href="http://localhost/flashblog/explorer/">http://localhost/flashblog/explorer/</a>. This opens the SWX Service Explorer. Set the amf path to http://localhost/flashblog/amf.php (default).</p>
<p>This should give you an overview of the remoting services, which we can call via flash. Right now, the only service is amfphp/discovery_service&#8230;</p>
<p>Now that we have cakephp &#038; cakeswxphp installed, we will setup our database for our blog. Point your browser to the phpMyAdmin on your development machine (WAMP default: http://localhost/phpmyadmin &#8211; MAMP default: http://localhost/phpMyAdmin/).</p>
<p>Using phpmyadmin, create a new database called &#8220;flashblog&#8221;.</p>
<p><img id="image31" alt="afbeelding-1.png" src="http://blog.aboutme.be/wp-content/uploads/2007/09/afbeelding-1.png" /></p>
<p>Execute the following SQL to create the tables for our blog:</p>

<div class="wp_syntax"><div class="code"><pre class="sql sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`comments`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`post_id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`nickname`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`title`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`content`</span> text <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> ; <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`posts`</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #ff0000;">`id`</span> int<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`created`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`modified`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`nickname`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`title`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">`content`</span> text <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span> ENGINE<span style="color: #66cc66;">=</span>MyISAM <span style="color: #993333; font-weight: bold;">DEFAULT</span> CHARSET<span style="color: #66cc66;">=</span>latin1 <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span> ;</pre></div></div>

<p>That&#8217;s it, our database is set up! Now it is time to write our cakephp classes to work with our database&#8230;</p>
<p>First of all, we need to tell cakephp how to access our database. Rename flashblog/app/config/database.php.default to database.php and open it in your favorite text/php editor. You can adjust the database configuration in the $default var in this file. In my case, it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'driver'</span> <span style="color: #339933;">=&gt;</span> <span style="">'mysql'</span><span style="color: #339933;">,</span>
	<span style="">'connect'</span> <span style="color: #339933;">=&gt;</span> <span style="">'mysql_connect'</span><span style="color: #339933;">,</span>
	<span style="">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="">'localhost'</span><span style="color: #339933;">,</span>
	<span style="">'login'</span> <span style="color: #339933;">=&gt;</span> <span style="">'root'</span><span style="color: #339933;">,</span>
	<span style="">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="">'root'</span><span style="color: #339933;">,</span>
	<span style="">'database'</span> <span style="color: #339933;">=&gt;</span> <span style="">'flashblog'</span><span style="color: #339933;">,</span>
	<span style="">'prefix'</span> <span style="color: #339933;">=&gt;</span> <span style="">''</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>If you point your browser to http://localhost/flashblog/ you should get the message that cake is able to connect to the database. If not, check your database settings again in flashblog/app/config/database.php.</p>
<p>So, we can connect to our database. Now we&#8217;ll define our post and comment models in php so that cakephp knows how to read and write posts and comments to the database. We could use the cake bake script to do this, but right now we&#8217;ll just write the code ourselves.</p>
<p>First of all, we&#8217;ll adjust the default model. Create app_model.php in flashblog/app/ with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> AppModel <span style="color: #000000; font-weight: bold;">extends</span> Model <span style="color: #009900;">&#123;</span>
	 <span style="color: #000000; font-weight: bold;">function</span> beforeSave<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
					 <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
					 <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">is_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primaryKey</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="">'$this-&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">primaryKey</span> <span style="color: #339933;">.</span> <span style="">' =  $this-&gt;data[$this-&gt;name][$this-&gt;primaryKey];'</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now, we can define our post and comments models. Create a file called post.php in flashblog/app/models/:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Post <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="">'Post'</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$hasMany</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="">'Comment'</span> <span style="color: #339933;">=&gt;</span>
				<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Comment'</span><span style="color: #339933;">,</span>
						<span style="">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="">'post_id'</span><span style="color: #339933;">,</span>
						<span style="">'dependent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">true</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then, create comment.php in that same directory (flashblog/app/models/) :</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Comment <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="">'Comment'</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$belongsTo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="">'Post'</span> <span style="color: #339933;">=&gt;</span>
				<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'className'</span> <span style="color: #339933;">=&gt;</span> <span style="">'Post'</span><span style="color: #339933;">,</span>
						<span style="">'foreignKey'</span> <span style="color: #339933;">=&gt;</span> <span style="">'post_id'</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>CakePHP now knows how to read and write posts and related comments to the database! Next, we will create our remoting methods (cake controllers) which we will call from flash.</p>
<p>Create posts_controller.php in flashblog/app/controllers:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> PostsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="">'Posts'</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$uses</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'Post'</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">function</span> getPosts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">findAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> getPost<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> savePost<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> deletePost<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">del</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then, create the controller for our comments (flashblog/app/controller/comments_controller.php):</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> CommentsController <span style="color: #000000; font-weight: bold;">extends</span> AppController <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="">'Comments'</span>;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$uses</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="">'Comment'</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">function</span> saveComment<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> deleteComment<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">del</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And here ends the PHP side of our flash blog. Let&#8217;s have some fun with Flash &#038; ActionScript, shall we?</p>
<p>Launch up flash and create a new fla (Actionscript 2). Save it somewhere as &#8220;flashblog.fla&#8221;. Now we&#8217;ll write the methods to read/write/delete blogposts and comments. SWX remoting doesn&#8217;t really need extra classes (you loadMovie your data), but using the classes makes you code a lot smaller and easier to write. So <a href="http://swxformat.org/download/" target="_blank">download the SWX ActionScript library</a> and extract the &#8220;org&#8221; folder to the same directory as your flashblog.fla file.</p>
<p>When you&#8217;ve got the org folder in the same folder as your flashblog.fla file, go back to your flashblog.fla file, select frame one and open the actions panel. We&#8217;ll start with importing the SWX class and setting up our gateway:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> org.<span style="color: #006600;">swxformat</span>.<span style="color: #66cc66;">*</span>;
<span style="color: #000000; font-weight: bold;">var</span> swx:SWX = <span style="color: #000000; font-weight: bold;">new</span> SWX<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
swx.<span style="color: #006600;">gateway</span> = <span style="color: #ff0000;">&quot;http://localhost/flashblog/swx.php&quot;</span>;
swx.<span style="color: #006600;">encoding</span> = <span style="color: #ff0000;">&quot;POST&quot;</span>;</pre></div></div>

<p>Now we can write our actionscript functions to communicate with our swx php classes. The following function sends a new post to our php class, which inserts it in the database:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
* function to create a new post
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> createPost<span style="color: #66cc66;">&#40;</span>nickname:<span style="color: #0066CC;">String</span>, title:<span style="color: #0066CC;">String</span>, content:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;savePost&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span>nickname, title, content<span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, savePostResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* called when the post was saved
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> savePostResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//nr of saved post or false when failed</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>That&#8217;s all it takes. No query writing. No XML parsing. No complex php files&#8230;<br />
Now, let&#8217;s complete our actionscript code with the other functions to communicate with php:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">//we import the SWX classes</span>
<span style="color: #0066CC;">import</span> org.<span style="color: #006600;">swxformat</span>.<span style="color: #66cc66;">*</span>;
<span style="color: #808080; font-style: italic;">//create a new SWX instance</span>
<span style="color: #000000; font-weight: bold;">var</span> swx:SWX = <span style="color: #000000; font-weight: bold;">new</span> SWX<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//location of the SWX gateway</span>
swx.<span style="color: #006600;">gateway</span> = <span style="color: #ff0000;">&quot;http://localhost/flashblog/swx.php&quot;</span>;
<span style="color: #808080; font-style: italic;">//we'll transfer data using POST.</span>
swx.<span style="color: #006600;">encoding</span> = <span style="color: #ff0000;">&quot;POST&quot;</span>;
<span style="color: #808080; font-style: italic;">/**
*get all posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getPosts<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;getPosts&quot;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, getPostsResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*
* called when we receive the posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getPostsResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> posts_length:<span style="color: #0066CC;">Number</span> = resultObj.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">length</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">Number</span> = 0; i <span style="color: #66cc66;">&lt;</span> posts_length; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> post:<span style="color: #0066CC;">Object</span> = resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>post.<span style="color: #006600;">Post</span>.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>post.<span style="color: #006600;">Post</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
*get a post with given id
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getPost<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;getPost&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, getPostResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*
* called when we receive the posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getPostResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span>.<span style="color: #006600;">Post</span>.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span>.<span style="color: #006600;">Comment</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* function to create a new post
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> createPost<span style="color: #66cc66;">&#40;</span>nickname:<span style="color: #0066CC;">String</span>, title:<span style="color: #0066CC;">String</span>, content:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;savePost&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>Post: <span style="color: #66cc66;">&#123;</span>nickname: nickname, title: title, content: content<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, savePostResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* function to edit a post
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> editPost<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">Number</span>, nickname:<span style="color: #0066CC;">String</span>, title:<span style="color: #0066CC;">String</span>, content:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;savePost&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>Post: <span style="color: #66cc66;">&#123;</span>id: id, nickname: nickname, title: title, content: content<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, savePostResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* called when the post was saved
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> savePostResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//nr of saved post or false when failed</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*
* called when we receive the posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> getPostResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span>.<span style="color: #006600;">Post</span>.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">var</span> comments_length:<span style="color: #0066CC;">Number</span> = resultObj.<span style="color: #006600;">result</span>.<span style="color: #006600;">Comment</span>.<span style="color: #0066CC;">length</span>;
	<span style="color: #b1b100;">for</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">Number</span> = 0; i <span style="color: #66cc66;">&lt;</span> comments_length; i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> comment:<span style="color: #0066CC;">Object</span> = resultObj.<span style="color: #006600;">result</span>.<span style="color: #006600;">Comment</span><span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>comment.<span style="color: #006600;">title</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>comment.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
*delete a post with given id
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> deletePost<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;PostsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;deletePost&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, deletePostResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*
* called when we receive the posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> deletePostResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* function to create a new comment
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> createComment<span style="color: #66cc66;">&#40;</span>post_id:<span style="color: #0066CC;">Number</span>, nickname:<span style="color: #0066CC;">String</span>, title:<span style="color: #0066CC;">String</span>, content:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;CommentsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;saveComment&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>Comment: <span style="color: #66cc66;">&#123;</span>post_id: post_id, nickname: nickname, title: title, content: content<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, saveCommentResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* function to edit a comment
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> editComment<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">Number</span>, post_id:<span style="color: #0066CC;">Number</span>, nickname:<span style="color: #0066CC;">String</span>, title:<span style="color: #0066CC;">String</span>, content:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;CommentsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;saveComment&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span>Comment: <span style="color: #66cc66;">&#123;</span>id: id, post_id: post_id, nickname: nickname, title: title, content: content<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, saveCommentResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
* called when the comment was saved
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> saveCommentResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//nr of saved post or false when failed</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/**
*delete a comment with given id
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> deleteComment<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> callDetails:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span>
		serviceClass: <span style="color: #ff0000;">&quot;CommentsController&quot;</span>,
		method: <span style="color: #ff0000;">&quot;deleteComment&quot;</span>,
		args: <span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span>,
		result: <span style="color: #66cc66;">&#91;</span><span style="color: #0066CC;">this</span>, deleteCommentResultHandler<span style="color: #66cc66;">&#93;</span>
	<span style="color: #66cc66;">&#125;</span>
	swx.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span>callDetails<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*
* called when we receive the posts from the server
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> deleteCommentResultHandler<span style="color: #66cc66;">&#40;</span>resultObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>resultObj.<span style="color: #006600;">result</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>You can test the functions by calling them manually through AS code. The next thing todo is create a gui to show posts, edit posts, etc. But that&#8217;s beyond the scope of this tutorial&#8230;</p>
<p>Happy flashing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/09/30/flash-remoting-with-swx-and-cakephp/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>CakeSWXPHP updated to SWX version 1.01</title>
		<link>http://blog.aboutme.be/2007/09/22/cakeswxphp-updated-to-swx-version-101/</link>
		<comments>http://blog.aboutme.be/2007/09/22/cakeswxphp-updated-to-swx-version-101/#comments</comments>
		<pubDate>Sat, 22 Sep 2007 14:40:38 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/09/22/cakeswxphp-updated-to-swx-version-101/</guid>
		<description><![CDATA[Aral Balkan released SWX version 1.0 a few weeks ago. I finally found the time to incorporate the changes into CakeSWXPHP! The changes include the swxAssembler class (instead of the old swfCompiler) and the rebranded service explorer.
Go to the cakeswxphp page for the latest downloads!
]]></description>
			<content:encoded><![CDATA[<p><a title="Blog of Aral Balkan" href="http://www.aralbalkan.com/">Aral Balkan</a> released <a title="Official SWX homepage" href="http://www.swxformat.org">SWX version 1.0</a> a few weeks ago. I finally found the time to incorporate the changes into CakeSWXPHP! The changes include the swxAssembler class (instead of the old swfCompiler) and the rebranded service explorer.</p>
<p>Go to the <a href="http://blog.aboutme.be/cakeswxphp">cakeswxphp page</a> for the latest downloads!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/09/22/cakeswxphp-updated-to-swx-version-101/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CakeSWXPHP updated to SWX beta 1.3</title>
		<link>http://blog.aboutme.be/2007/08/07/cakeswxphp-updated-to-swx-beta-13/</link>
		<comments>http://blog.aboutme.be/2007/08/07/cakeswxphp-updated-to-swx-beta-13/#comments</comments>
		<pubDate>Tue, 07 Aug 2007 09:41:42 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/08/07/cakeswxphp-updated-to-swx-beta-13/</guid>
		<description><![CDATA[I took some time updating my cakeswxphp package to the SWX beta 1.3. One of the new features is the new service explorer from SWX.
You can test your cake gateway, pointing your browser to the /explorer/ directory, gateway location being: cake_amf_gateway.php
Go to the cakeswxphp page for the latest downloads!
Enjoy!
]]></description>
			<content:encoded><![CDATA[<p>I took some time updating my cakeswxphp package to the SWX beta 1.3. One of the new features is the new service explorer from SWX.</p>
<p>You can test your cake gateway, pointing your browser to the /explorer/ directory, gateway location being: cake_amf_gateway.php</p>
<p>Go to the <a href="http://blog.aboutme.be/cakeswxphp">cakeswxphp page</a> for the latest downloads!</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/08/07/cakeswxphp-updated-to-swx-beta-13/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>call cakephp through swx / amf</title>
		<link>http://blog.aboutme.be/2007/08/03/call-cakephp-through-swx-amf/</link>
		<comments>http://blog.aboutme.be/2007/08/03/call-cakephp-through-swx-amf/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 20:41:41 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[amfphp]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[swx]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/08/03/call-cakephp-through-swx-amf/</guid>
		<description><![CDATA[As some of you might know, I&#8217;m a great fan of the cakephp framework. It is a rapid application framework for php. Cakephp already had a subproject called cakeamfphp. Looking at the code from cakeamfphp, I was able to get SWX running and call the cake controllers as remoting services.
Go to the cakeswxphp page for [...]]]></description>
			<content:encoded><![CDATA[<p>As some of you might know, I&#8217;m a great fan of the cakephp framework. It is a rapid application framework for php. Cakephp already had a subproject called cakeamfphp. Looking at the code from cakeamfphp, I was able to get SWX running and call the cake controllers as remoting services.</p>
<p>Go to the <a href="http://blog.aboutme.be/cakeswxphp">cakeswxphp page</a> for the latest downloads&#8230;</p>
<p>Just copy/past in your cake directory! Gateway locations are:</p>
<p>swx.php (SWX)<br />
amf.php (AMFPHP)<br />
json.php (JSON)</p>
<p>Currently it uses an adjusted version of SWX, based on SWX beta 1.0. I will try to update it to future versions of SWX when I get the time&#8230;</p>
<p>More info about SWX and cakephp at:</p>
<p><a target="_blank" title="SWX project" href="http://www.swxformat.org/">http://www.swxformat.org/</a><br />
<a target="_blank" title="aral balkan blog" href="http://www.aralbalkan.com/">http://www.aralbalkan.com/</a> (Aral Balkan, SWX author)<br />
<a target="_blank" title="cakephp project" href="http://www.cakephp.org/">http://www.cakephp.org/</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/08/03/call-cakephp-through-swx-amf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ExternalInterface pain</title>
		<link>http://blog.aboutme.be/2007/03/21/externalinterface-pain/</link>
		<comments>http://blog.aboutme.be/2007/03/21/externalinterface-pain/#comments</comments>
		<pubDate>Tue, 20 Mar 2007 23:03:57 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2007/03/21/externalinterface-pain/</guid>
		<description><![CDATA[Had a difficult time with ExternalInterface today. Ok, swfs work nicely together with javascript on a webserver, but when you access them locally, there are some security issues you have to deal with. The app I needed to created needed communication in both ways, so from swf to javascript and vice versa.
When you run the [...]]]></description>
			<content:encoded><![CDATA[<p>Had a difficult time with ExternalInterface today. Ok, swfs work nicely together with javascript on a webserver, but when you access them locally, there are some security issues you have to deal with. The app I needed to created needed communication in both ways, so from swf to javascript and vice versa.</p>
<p>When you run the app locally through your browser, you get the security warning. In the security settings, you can add locations of local trusted files. Thing is: if you need communication in both ways, you need to specify the <strong>directory</strong> of the swf file, not just the file itself. Otherwise, only swf to javascript communication would work!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2007/03/21/externalinterface-pain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deeplinking &amp; browser back button in Flash</title>
		<link>http://blog.aboutme.be/2006/11/02/deeplinking-browser-back-button-in-flash/</link>
		<comments>http://blog.aboutme.be/2006/11/02/deeplinking-browser-back-button-in-flash/#comments</comments>
		<pubDate>Thu, 02 Nov 2006 18:17:31 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2006/11/02/deeplinking-browser-back-button-in-flash/</guid>
		<description><![CDATA[For a recent company site, I wanted to build in browser history support, to make the site more accessible. I used robert penner&#8217;s browser history before, but it never felt quite good: it requires an html hidden frame setup that communicates with flash &#038; vice versa, using getURL to communicate with the javascript functions,&#8230;
So I [...]]]></description>
			<content:encoded><![CDATA[<p>For a recent company site, I wanted to build in browser history support, to make the site more accessible. I used robert penner&#8217;s browser history before, but it never felt quite good: it requires an html hidden frame setup that communicates with flash &#038; vice versa, using getURL to communicate with the javascript functions,&#8230;</p>
<p>So I searched for an alternative method, and <a title="Deeplinking &#038; browser back button in Flash" href="http://reefscape.net/?p=10">found one which doesn&#8217;t use frames, uses ExternalInterface to communicate with the javascript code AND it supports deeplinking</a>! Flash &#038; accessibility, another milestone reached?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2006/11/02/deeplinking-browser-back-button-in-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing videos from YouTube</title>
		<link>http://blog.aboutme.be/2006/10/11/playing-videos-from-youtube/</link>
		<comments>http://blog.aboutme.be/2006/10/11/playing-videos-from-youtube/#comments</comments>
		<pubDate>Wed, 11 Oct 2006 18:19:37 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2006/10/11/playing-videos-from-youtube/</guid>
		<description><![CDATA[Just finished a little experiment to load flv&#8217;s from YouTube into your own swf files&#8230;
Every YouTube video has a unique id. You can find this id, using the public YouTube API. However, you&#8217;ll need more than this simple id to play the video&#8217;s in your own flash/flex/&#8230; application.

If you take a closer look to the [...]]]></description>
			<content:encoded><![CDATA[<p>Just finished a little experiment to load flv&#8217;s from YouTube into your own swf files&#8230;</p>
<p>Every YouTube video has a unique id. You can find this id, using the public YouTube API. However, you&#8217;ll need more than this simple id to play the video&#8217;s in your own flash/flex/&#8230; application.<br />
<span id="more-9"></span><br />
If you take a closer look to the source code on a YouTube page, playing a video, you will find something like this in the source code:</p>
<p><code>		// &lt;![CDATA[<br />
		var fo = new SWFObject("/player2.swf?video_id=lejN7Ulh10s&#038;l=149&#038;t=OEgsToPDskIn_fJRn5UCNu_UAHkEu6jJ", "movie_player", "450", "370", 7, "#FFFFFF");<br />
		fo.write("playerDiv");<br />
		// ]]&gt;</code></p>
<p>You can see it adds some more variables after the video_id parameter. These parameters are needed to retrieve the flv itself. What you could do in flash, is retrieve the html source of a video with the given video_id, so a search in the retrieved source and retrieve the full video id. If you have a video object on the stage, you could then play the video using this object:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Delegate</span>;
<span style="color: #000000; font-weight: bold;">function</span> loadYoutubeVideo<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">_visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
	<span style="color: #000000; font-weight: bold;">var</span> test_xml:<span style="color: #0066CC;">XML</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	test_xml.<span style="color: #0066CC;">onData</span> = Delegate.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, youtubeHtmlData<span style="color: #66cc66;">&#41;</span>;
	test_xml.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.youtube.com/watch?v=&quot;</span>+id<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> youtubeHtmlData<span style="color: #66cc66;">&#40;</span>src:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> args:<span style="color: #0066CC;">String</span> = src.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span>src.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'video_id='</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">9</span><span style="color: #66cc66;">&#41;</span>;
	args = args.<span style="color: #0066CC;">substr</span><span style="color: #66cc66;">&#40;</span>0, args.<span style="color: #0066CC;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;'&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">ns</span>.<span style="color: #0066CC;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://www.youtube.com/get_video?video_id=&quot;</span>+args<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> statusChanged<span style="color: #66cc66;">&#40;</span>infoObject:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>infoObject.<span style="color: #006600;">code</span> == <span style="color: #ff0000;">&quot;NetStream.Buffer.Empty&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		scaleToVideoDimensions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> scaleToVideoDimensions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">_width</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">width</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">_height</span> = <span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">height</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">_visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">align</span> = <span style="color: #ff0000;">&quot;TL&quot;</span>;
<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">scaleMode</span> = <span style="color: #ff0000;">&quot;noScale&quot;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">nc</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">nc</span>.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">ns</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetStream</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">nc</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">ns</span>.<span style="color: #0066CC;">onStatus</span> = Delegate.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, statusChanged<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">ns</span>.<span style="color: #006600;">onMetaData</span> = Delegate.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, metaDataRecieved<span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>.<span style="color: #006600;">youtube_flv</span>.<span style="color: #0066CC;">attachVideo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>.<span style="color: #006600;">ns</span><span style="color: #66cc66;">&#41;</span>;
loadYoutubeVideo<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;ogIqayRDr4w&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><a href='http://blog.aboutme.be/wp-content/uploads/2008/01/youtubefla.zip' title=''>You can download the working fla source here.</a></p>
<p>I had to use the NetStream object on a video object on stage, for some reason I couldn&#8217;t get this to work with the default FLVPlayback component&#8230; Also, the width and height of the movie aren&#8217;t specified in the flv metadata from youtube, so I retrieved those values another way (onStatus event, when Buffer is empty) If you run it outside of the authoring environment, you will also get a security sandbox warning&#8230; Maybe somebody knows a workaround for this in this application?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2006/10/11/playing-videos-from-youtube/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>extending MovieClip</title>
		<link>http://blog.aboutme.be/2006/09/20/extending-movieclip/</link>
		<comments>http://blog.aboutme.be/2006/09/20/extending-movieclip/#comments</comments>
		<pubDate>Wed, 20 Sep 2006 20:36:36 +0000</pubDate>
		<dc:creator>wouter</dc:creator>
				<category><![CDATA[Actionscript 2.0]]></category>

		<guid isPermaLink="false">http://blog.aboutme.be/2006/09/20/extending-movieclip/</guid>
		<description><![CDATA[Have you ever tried extending the MovieClip class? The standard way is to create your actionscript class extending from MovieClip, adding a MovieClip symbol to the library, setting a Linkage Identifier and specify the Actionscript 2 class. To create an instance of your class on the stage, you have to use attachMovie(). Problems of this [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever tried extending the MovieClip class? The standard way is to create your actionscript class extending from MovieClip, adding a MovieClip symbol to the library, setting a Linkage Identifier and specify the Actionscript 2 class. To create an instance of your class on the stage, you have to use attachMovie(). Problems of this method are: it requires a great deal of &#8220;work&#8221; to create class file, create library symbol &#038; set it up and your code is more difficult to port between projects (recreate the library stuff in each projects). However, there are ways to extend MovieClip, without using the library directly.</p>
<p><span id="more-6"></span></p>
<p><strong>classic way</strong></p>
<p>We start with a basic MyRectangle class</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyRectangle <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __width:<span style="color: #0066CC;">Number</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __height:<span style="color: #0066CC;">Number</span>;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		__width = value;
		draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> __width;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> <span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#40;</span>value:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		__height = value;
		draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> <span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Number</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> __height;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyRectangle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;created MyRectangle instance&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onLoad</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;loaded&quot;</span><span style="color: #66cc66;">&#41;</span>;
		__width = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0066CC;">width</span> : <span style="color: #cc66cc;">100</span>;
		__height = <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0066CC;">height</span> : <span style="color: #cc66cc;">100</span>;
		draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> draw<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0x000000, <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>, 0<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, <span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span>0, 0<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To start, we use the classic way:</p>
<ol>
<li>create a new movieclip symbol in your library</li>
<li>right click, choose linkage and fill in the linkage identifier &#038; Actionscript 2 class (MyRectangle)</li>
<li>drag an instance of the MyRectangle MovieClip on your stage</li>
</ol>
<p>By default, it will create a 100&#215;100 rectangle on the stage. Notice the constructor and onLoad event and the order of (auto) execution when you run the swf&#8230;</p>
<p><strong>getting rid of the library symbol</strong></p>
<p>Now, we&#8217;re gonna get rid of the library symbol. We don&#8217;t want to create empty library symbols for each class extending MovieClip. We will use attachMovie to create an instance of our MyRectangle class. However, as we don&#8217;t have a linked library item, we can&#8217;t use attachMovie&#8230; or can we?</p>
<p>When a linked class is compiled into the swf, it gets a linkage name of &#8220;__Packages.&#8221; followed by the full package name and class name. We can do this trough code aswell! By linking that linkage name to the class constructor, using Object.registerClass, we can use attachMovie again&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyRectangle <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> symbolName:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;__Packages.MyRectangle&quot;</span>;
	<span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> symbolOwner:<span style="color: #000000; font-weight: bold;">Function</span> = MyRectangle;
	<span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> symbolLinked = <span style="color: #0066CC;">Object</span>.<span style="color: #0066CC;">registerClass</span><span style="color: #66cc66;">&#40;</span>symbolName, symbolOwner<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __width:<span style="color: #0066CC;">Number</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> __height:<span style="color: #0066CC;">Number</span>;
	<span style="color: #808080; font-style: italic;">//...</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>We now use attachMovie on our main timeline to create an instance of our rectangle class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">attachMovie</span><span style="color: #66cc66;">&#40;</span>MyRectangle.<span style="color: #006600;">symbolName</span>, <span style="color: #ff0000;">&quot;rectangle_mc&quot;</span>, <span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Hooray! We don&#8217;t have a library item anymore! But I still don&#8217;t like the attachMovie outside of our class. Instead, you could write a static create method, that does the attachMovie and returns an instance of our MyRectangle. You could also <a href="http://blog.aboutme.be/2006/09/12/passing-arguments-through-parameter-objects/">pass a parameter object</a> to the function&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> create<span style="color: #66cc66;">&#40;</span>container:<span style="color: #0066CC;">MovieClip</span>, initObj:<span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#41;</span>:MyRectangle<span style="color: #66cc66;">&#123;</span>
	container.<span style="color: #0066CC;">attachMovie</span><span style="color: #66cc66;">&#40;</span>symbolName, <span style="color: #ff0000;">&quot;rectangle_mc&quot;</span>, container.<span style="color: #0066CC;">getNextHighestDepth</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, initObj<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">return</span> MyRectangle<span style="color: #66cc66;">&#40;</span>container<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;rectangle_mc&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To create a rectangle, you could use:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> rect = MyRectangle.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #0066CC;">_x</span>:<span style="color: #cc66cc;">100</span>, <span style="color: #0066CC;">_y</span>:<span style="color: #cc66cc;">100</span>, <span style="color: #0066CC;">height</span>:<span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Using this method, you could create classes extending from eachother and MovieClip as the root class. I&#8217;m thinking about adding eventdispatching to all your MovieClips, basic animations (flyTo(x,y)),&#8230;</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.aboutme.be/2006/09/20/extending-movieclip/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
