<?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>nichmekof.com &#187; Tutorials</title>
	<atom:link href="http://blog.nichmekof.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nichmekof.com</link>
	<description>Learnings of a flash developer</description>
	<lastBuildDate>Tue, 31 Jan 2012 17:07:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Use SharedObject to save data on users computer</title>
		<link>http://blog.nichmekof.com/2009/03/use-sharedobject-to-save-data-on-users-computer/</link>
		<comments>http://blog.nichmekof.com/2009/03/use-sharedobject-to-save-data-on-users-computer/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 07:57:59 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.nichmekof.com/?p=116</guid>
		<description><![CDATA[By using SharedObject you are able to store limited amounts of data on a user's computer. It's works in the same kind of way that your browser stores cookies. However there are some limitations with using this. Sometimes swf files may not be able to write the data, and the data can sometimes be deleted [...]]]></description>
			<content:encoded><![CDATA[<p>By using SharedObject you are able to store limited amounts of data on a user's computer. It's works in the same kind of way that your browser stores cookies. However there are some limitations with using this. Sometimes swf files may not be able to write the data, and the data can sometimes be deleted without your knowledge. Users can set their own limits on how much space flash player can use on their computer. When they lower the amount of disk space available, some local shared objects might get removed.</p>
<p>I'll show you a basic example of using SharedObject. We will have an input text field on stage and a button that will save the text in the text field.</p>
<p>Create a new AS3 Document and put a text field on stage and give it an instance name. I will call mine <strong>theText_txt</strong>.<br />
Next make a button on stage and give it an instance name. I called mine <strong>save_btn</strong>.</p>
<p>Create a new layer in the main timeline and call it actions and lock it. Open up the actions panel and enter the following:</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> mySO:<span style="color: #0066CC;">SharedObject</span>;
mySO = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myfirstSO&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>The first line creates the shared object. The second line gets a local shared object called <strong>myfirstSO</strong>. Nothing is stored in it at the moment but we will assign data to it shortly.</p>
<p>Now when we click the button we want to assign whatever text is in the text field to the shared object. In the actions panel enter:</p>
<pre class="actionscript">save_btn.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, saveText<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> saveText<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
     mySO.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">myText</span> = theText_txt.<span style="color: #0066CC;">text</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>This has now assigned the text in the text field to a variable called <strong>myText</strong> in the SharedObject.</p>
<p>OK now that the text is saved we will want to populate the text field with that saved data when you open the swf again. In the actions panel enter the following.</p>
<pre class="actionscript"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>mySO.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">myText</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
     theText_txt.<span style="color: #0066CC;">text</span> = mySO.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">myText</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>This checks to see if there is any data in the myText variable in the SharedObject. If there is then it assigns that value to the text field.</p>
<p>Now test the movie. Enter some text in the text field and click your save button. Close the swf and test the movie again. You will see that the text you entered before is in the text field.</p>
<p>You can download the example here: <a href="http://blog.nichmekof.com/wp-content/uploads/2009/03/sharedobject.zip">SharedObject.zip</a></p>
<p>Hope this was helpful,<br />
Ed</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nichmekof.com/2009/03/use-sharedobject-to-save-data-on-users-computer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Searching through arrays</title>
		<link>http://blog.nichmekof.com/2008/07/searching-through-arrays/</link>
		<comments>http://blog.nichmekof.com/2008/07/searching-through-arrays/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 08:22:24 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.nichmekof.com/?p=11</guid>
		<description><![CDATA[This works in both actionscript 2 and actionscript 3. To search an array starting from the first position in the array we use: for &#40;var i:int = 0; i &#60; myArray.length; i++&#41; &#123; ... &#125; Where you would change myArray with the variable name of your array. But what if you wanted to search through [...]]]></description>
			<content:encoded><![CDATA[<p>This works in both actionscript 2 and actionscript 3.</p>
<p>To search an array starting from the first position in the array we use:</p>
<pre class="actionscript"><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;">int</span> = <span style="color: #cc66cc;">0</span>; i &lt; myArray.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   ...
<span style="color: #66cc66;">&#125;</span></pre>
<p>Where you would change myArray with the variable name of your array.</p>
<p>But what if you wanted to search through the array from the last item? Well the easiest way of doing this is by using:</p>
<pre class="actionscript"><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: #b1b100;">in</span> myArray<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
   ...
<span style="color: #66cc66;">&#125;</span></pre>
<p>Now you know. And knowing is half the battle. - G.I. Joe</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nichmekof.com/2008/07/searching-through-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Load an image with Actionscript 3</title>
		<link>http://blog.nichmekof.com/2008/05/load-image-with-actionscript-3/</link>
		<comments>http://blog.nichmekof.com/2008/05/load-image-with-actionscript-3/#comments</comments>
		<pubDate>Fri, 23 May 2008 05:40:07 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.nichmekof.com/?p=5</guid>
		<description><![CDATA[To load an image into flash with actionscript 3 the first thing you need to do is set up 2 variables. The first will be the loader which is what will actually load in the image. The second is the URL request which will tell flash where the image to be loaded is. var url:URLRequest [...]]]></description>
			<content:encoded><![CDATA[<p>To load an image into flash with actionscript 3 the first thing you need to do is set up 2 variables. The first will be the loader which is what will actually load in the image. The second is the URL request which will tell flash where the image to be loaded is.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myimage.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>Now we will call flash to load the image into the loader variable.</p>
<pre class="actionscript">loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;</pre>
<p>However if we just have this, flash wont know what to do with it. So what we have to do is setup some event listeners which will call a function to tell flash what to do when it loads the file.</p>
<p>We will create one event listener to check what is happening while the image is loading.</p>
<pre class="actionscript">loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, loadProgress<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>At first you may be thinking "why do I need contentLoaderInfo in there? Why can't I just add an event listener straight onto the loader?" The reason for this is <span>basically that the loader just holds the image whereas the contentLoaderInfo hold all the information about the file. So if you don't use contentLoaderInfo then you can't get any information about the file.</span></p>
<p>Create another event listener to check if the file has finished loading;</p>
<pre class="actionscript">loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, loadComplete<span style="color: #66cc66;">&#41;</span>;</pre>
<p>Now these 2 event listeners are calling some functions one called loadProgress and the other called loadComplete. So lets create those functions.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> loadProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loadComplete<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>In the loadProgress function you will notice that it is looking for a progress event. What this means is that while the image is downloading flash keeps checking this function to check the progress of the image download. This is called in the event listener that we created earlier.</p>
<p>In the loadProgress function we want to see the percentage of the file being downloaded. for this example we will just use the trace function.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> loadProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<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> percentLoaded:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">bytesLoaded</span>/event.<span style="color: #0066CC;">bytesTotal</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Loading: &quot;</span>+percentLoaded+<span style="color: #ff0000;">&quot;%&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>What is happening here is we are getting the bytesLoaded from the image and dividing that by the bytesTotal of the image. This will get a number between 0 and 1. We then multiply that by 100 to get the percentage of the download. We also want to round this off so it won't display a number with a long decimal at the end like 13.2352274564. We then trace this out and when the image is downloading we will see how much of it has been downloaded.</p>
<p>Once the image has been downloaded we then need to tell Flash what to do with that image. What we will do in this instance is add it to the stage. So go into the loadComplete function and add this</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">function</span> loadComplete<span style="color: #66cc66;">&#40;</span>event:Event<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;Complete&quot;</span><span style="color: #66cc66;">&#41;</span>;
   addChild<span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>
<p>This tells flash that once the image has been downloaded add the loader to the stage. This will now display the image.</p>
<p>Your code should now look like this.</p>
<pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">url</span>:URLRequest = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myimage.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">url</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ProgressEvent.<span style="color: #006600;">PROGRESS</span>, loadProgress<span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, loadComplete<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loadProgress<span style="color: #66cc66;">&#40;</span>event:ProgressEvent<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> percentLoaded:<span style="color: #0066CC;">Number</span> = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">round</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">bytesLoaded</span>/event.<span style="color: #0066CC;">bytesTotal</span><span style="color: #66cc66;">&#41;</span> * <span style="color: #cc66cc;">100</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Loading: &quot;</span>+percentLoaded+<span style="color: #ff0000;">&quot;%&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> loadComplete<span style="color: #66cc66;">&#40;</span>event:Event<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;Complete&quot;</span><span style="color: #66cc66;">&#41;</span>;
   addChild<span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>If you are using this inside a class then you would also need to import:</p>
<pre class="actionscript"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">*</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLRequest</span>;
<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.nichmekof.com/2008/05/load-image-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

