<?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>In Flagrante Delicto! &#187; Images</title>
	<atom:link href="http://inflagrantedelicto.memoryspiral.com/tag/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://inflagrantedelicto.memoryspiral.com</link>
	<description>Joseph Labrecque: Flash Platform Developer - Multidisciplinary Digital Artist - Adobe Education Leader</description>
	<lastBuildDate>Wed, 01 Sep 2010 15:48:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Scaling Your Images in Flash Player? Smooth Those Things!!!</title>
		<link>http://inflagrantedelicto.memoryspiral.com/2009/09/scaling-your-images-in-flash-player-smooth-those-things/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=scaling-your-images-in-flash-player-smooth-those-things</link>
		<comments>http://inflagrantedelicto.memoryspiral.com/2009/09/scaling-your-images-in-flash-player-smooth-those-things/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 21:54:10 +0000</pubDate>
		<dc:creator>Joseph Labrecque</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://inflagrantedelicto.memoryspiral.com/?p=1018</guid>
		<description><![CDATA[I actually forgot to apply the &#8220;smoothing&#8221; property to a flash.display.Bitmap display object being scaled inside Flash Player. Just look at the difference such an oversight made! Since I was using a flash.display.Loader display object to load the image up, &#8230; <a href="http://inflagrantedelicto.memoryspiral.com/2009/09/scaling-your-images-in-flash-player-smooth-those-things/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I actually forgot to apply the &#8220;smoothing&#8221; property to a flash.display.Bitmap display object being scaled inside Flash Player.  Just look at the difference such an oversight made!</p>
<p><a href="http://inflagrantedelicto.memoryspiral.com/wp-content/uploads/2009/09/Smoothing.png"><img src="http://inflagrantedelicto.memoryspiral.com/wp-content/uploads/2009/09/Smoothing.png" alt="Smoothing" title="Smoothing" class="alignnone" width="600" /></a></p>
<p>Since I was using a flash.display.Loader display object to load the image up, and Loader has no smoothing property, I totally spaced on this and it&#8217;s been out there for months rendering images in a pretty crappy way.  I just needed to assign the image data to a Bitmap object and use that for display instead.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> imageLoaded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<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> imageBitmap:Bitmap = imageLoader.<span style="color: #006600;">content</span> as Bitmap;
    imageBitmap.<span style="color: #0066CC;">smoothing</span> = <span style="color: #000000; font-weight: bold;">true</span>;
    imageDrag.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageBitmap<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #808080; font-style: italic;">//scale away!</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Easy.</p>
<p>Learn from my blunder- always make sure to enable smoothing!</p>
]]></content:encoded>
			<wfw:commentRss>http://inflagrantedelicto.memoryspiral.com/2009/09/scaling-your-images-in-flash-player-smooth-those-things/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple AS3 Slideshow Widget: Part 3</title>
		<link>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-3/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simple-as3-slideshow-widget-part-3</link>
		<comments>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-3/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 14:45:59 +0000</pubDate>
		<dc:creator>Joseph Labrecque</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://inflagrantedelicto.memoryspiral.com/?p=535</guid>
		<description><![CDATA[This is the final post in a three part tutorial detailing the creation of a Flash slideshow widget using ActionScript 3.0. Have a look over Part 1 and Part 2 before moving ahead. In this post, we are examining the &#8230; <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is the final post in a three part tutorial detailing the creation of a Flash slideshow widget using ActionScript 3.0.  Have a look over <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/">Part 1</a> and <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/">Part 2</a> before moving ahead.</p>
<p>In this post, we are examining the two methods which actually handle image loading and display within our module.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> switchImage<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	imageBitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	imageBitmap.<span style="color: #006600;">bitmapData</span> = imageBitmapData;
	imageBitmap.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">1</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>currentImage <span style="color: #66cc66;">&lt;</span> imageArray.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		currentImage++;
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
		currentImage = <span style="color: #cc66cc;">0</span>;
	<span style="color: #66cc66;">&#125;</span>
	urlRequ.<span style="color: #0066CC;">url</span> = appPath + <span style="color: #ff0000;">&quot;path/to/images/&quot;</span> + imageArray<span style="color: #66cc66;">&#91;</span>currentImage<span style="color: #66cc66;">&#93;</span>;
	imageLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>urlRequ<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>&#8220;switchImage&#8221; is invoked by the Timer we established previously.  The function this method is to set up our eventual transition from one image to the next, grab the next image from our Array and begin to load it into our Loader instance on the Stage, and keep track of what position we are at in our Array.  To accomplish this, we first &#8220;draw()&#8221; the entire Stage to our &#8220;imageBitmapData&#8221; instance.  This data is then assigned to the &#8220;imageBitmap&#8221; bitmapData property, effectively duplicating the visible data within our Loader instance.  This switch from Loader to Bitmap is in no way apparent to the viewer.  We also switch the alpha property of out Bitmap to 1, ensuring that it is completely visible.</p>
<p>We then manage our &#8220;currentPosition&#8221; variable by checking the current value against the Length of the Array.  If we have reached the end, we simply revert to a value of &#8220;0&#8243; causing an infinite loop.</p>
<p>All we have to do then is change the &#8220;url&#8221; property of our URLRequest object and then invoke another load() upon &#8220;imageLoader&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> imageLoaded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	imageTween = <span style="color: #000000; font-weight: bold;">new</span> Tween<span style="color: #66cc66;">&#40;</span>imageBitmap, <span style="color: #ff0000;">&quot;alpha&quot;</span>, Regular.<span style="color: #006600;">easeIn</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>This is the last method we have in our little widget.  &#8220;imageLoaded&#8221; is fired by an Event.COMPLETE when a loading image is finally loaded up.  At this point, we simply use Tweener to tween the alpha of our Bitmap (displaying the previous image) down to 0, revealing the freshly loaded image beneath.</p>
<p>I recommend using <a href="http://code.google.com/p/swfobject/">SWFObject</a> to embed the module into your website. </p>
<p>Here is the full PHP code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000088;">$firstrun</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;front_images&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</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;">$firstrun</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$firstrun</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;,&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Here is the full ActionScript class:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</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;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">Tween</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">easing</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SlideShow <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> appPath:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imgDur:<span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> currentImage:<span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlRequ:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlLoad:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageArray:<span style="color: #0066CC;">Array</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageBitmap:Bitmap;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageBitmapData:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageLoader:Loader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageTimer:Timer;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageTween:Tween;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SlideShow<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: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">appPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				appPath = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">appPath</span>;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				appPath = <span style="color: #ff0000;">&quot;http://yourwebsite.com/&quot;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">imgDur</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				imgDur = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">imgDur</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span>;;
			<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
				imgDur = <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span>;
			<span style="color: #66cc66;">&#125;</span>
			gatherFiles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> gatherFiles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			urlRequ = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			urlRequ.<span style="color: #0066CC;">url</span> = appPath + <span style="color: #ff0000;">&quot;gatherFrontImages.php&quot;</span>;
			urlLoad = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			urlLoad.<span style="color: #006600;">dataFormat</span> = flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>.<span style="color: #0066CC;">TEXT</span>;
			urlLoad.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, urlComplete<span style="color: #66cc66;">&#41;</span>;
			urlLoad.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>urlRequ<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> urlComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			imageArray = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;,&quot;</span><span style="color: #66cc66;">&#41;</span>;
			currentImage = imageArray.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span>;
			imageLoader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			imageLoader.<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>, imageLoaded<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageLoader<span style="color: #66cc66;">&#41;</span>;
			imageBitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span>;
			imageBitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageBitmap<span style="color: #66cc66;">&#41;</span>;
			switchImage<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TimerEvent<span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			imageTimer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span>imgDur<span style="color: #66cc66;">&#41;</span>;
			imageTimer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, switchImage<span style="color: #66cc66;">&#41;</span>;
			imageTimer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> switchImage<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:TimerEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			imageBitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
			imageBitmap.<span style="color: #006600;">bitmapData</span> = imageBitmapData;
			imageBitmap.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">1</span>;
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>currentImage <span style="color: #66cc66;">&lt;</span> imageArray.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				currentImage++;
			<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
				currentImage = <span style="color: #cc66cc;">0</span>;
			<span style="color: #66cc66;">&#125;</span>
			urlRequ.<span style="color: #0066CC;">url</span> = appPath + <span style="color: #ff0000;">&quot;path/to/images/&quot;</span> + imageArray<span style="color: #66cc66;">&#91;</span>currentImage<span style="color: #66cc66;">&#93;</span>;
			imageLoader.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>urlRequ<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> imageLoaded<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			imageTween = <span style="color: #000000; font-weight: bold;">new</span> Tween<span style="color: #66cc66;">&#40;</span>imageBitmap, <span style="color: #ff0000;">&quot;alpha&quot;</span>, Regular.<span style="color: #006600;">easeIn</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Simple AS3 Slideshow Widget: Part 2</title>
		<link>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simple-as3-slideshow-widget-part-2</link>
		<comments>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 16:34:30 +0000</pubDate>
		<dc:creator>Joseph Labrecque</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://inflagrantedelicto.memoryspiral.com/?p=512</guid>
		<description><![CDATA[In Part 1, we had a look at the basic structure of what we are working toward, including a PHP file to read images from a directory and return a list of images to Flash, the setup of our FLA, &#8230; <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/">Part 1</a>, we had a look at the basic structure of what we are working toward, including a PHP file to read images from a directory and return a list of images to Flash, the setup of our FLA, and the basic construction of our document class. This widget, being so simple, will only require the document class.</p>
<p>We will now go through each method and describe what is happening&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SlideShow<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: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">appPath</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		appPath = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">appPath</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		appPath = <span style="color: #ff0000;">&quot;http://yourwebsite.com/&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">imgDur</span> <span style="color: #66cc66;">!</span>= <span style="color: #0066CC;">undefined</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		imgDur = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>.<span style="color: #006600;">imgDur</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span>;;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		imgDur = <span style="color: #cc66cc;">5</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span>;
	<span style="color: #66cc66;">&#125;</span>
	gatherFiles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>There are a few things to set up in our constructor function.  These values can be passed in through flashvars or hard-coded into your class.  We are being super flexible and allowing the user to input these values upon embed.  For a short explanation of what is going on here, have a look at my <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/testing-flash-projects-w-dynamic-variables/">previous post</a>.</p>
<p>We now assign values to the &#8220;appPath&#8221; and &#8220;imgDur&#8221; variables.  &#8220;appPath&#8221; is simply the path to our actual application or website.  We will use this to construct both calls to the PHP file and also the images themselves.  &#8220;imgDur&#8221; is a setting that specifies how long each image should persist on the screen before fetching another.  We then call &#8220;gatherFiles()&#8221; after these values are established.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Loader</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">TimerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">Timer</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;">net</span>.<span style="color: #006600;">URLLoader</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">Tween</span>;
	<span style="color: #0066CC;">import</span> fl.<span style="color: #006600;">transitions</span>.<span style="color: #006600;">easing</span>.<span style="color: #66cc66;">*</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SlideShow <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> appPath:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imgDur:<span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> currentImage:<span style="color: #0066CC;">int</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlRequ:URLRequest;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> urlLoad:URLLoader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageArray:<span style="color: #0066CC;">Array</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageBitmap:Bitmap;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageBitmapData:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageLoader:Loader;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageTimer:Timer;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imageTween:Tween;</pre></td></tr></table></div>

<p>As we step through this and encounter new variables, they will of course need to be defined and datatyped properly at the beginning of our class.  We will also need to import any other classes we need within our package.  The full list of import statements and variable declarations is included here for the sake of overview.</p>
<p>An important thing to note here, is that we are importing classes that are native to Flash, but are also importing the excellent &#8220;Tweener&#8221; packages which can be found at <a href="http://code.google.com/p/tweener/">Google Code</a>.  You could use the build in tween classes, but Tweener is a lot more flexible and provides much more control.</p>
<p>Now, on to our data loading methods!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> gatherFiles<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	urlRequ = <span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	urlRequ.<span style="color: #0066CC;">url</span> = appPath + <span style="color: #ff0000;">&quot;gatherFrontImages.php&quot;</span>;
	urlLoad = <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	urlLoad.<span style="color: #006600;">dataFormat</span> = flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">URLLoaderDataFormat</span>.<span style="color: #0066CC;">TEXT</span>;
	urlLoad.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, urlComplete<span style="color: #66cc66;">&#41;</span>;
	urlLoad.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span>urlRequ<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Our goal with this method is to create a connection to the PHP file and establish a handler for the results.  In order to do this, we will use the &#8220;URLLoader&#8221; class.  URLLoader has a method called &#8220;load&#8221; which requires a &#8220;URLRequest&#8221; object.  URLRequest has a &#8220;url&#8221; property which we set using a combination of the &#8220;appPath&#8221; variable defined upon initialization and the location and name of our PHP file.  We also set the &#8220;dataFormat&#8221; property of the URLLoader to &#8220;flash.net.URLLoaderDataFormat.TEXT&#8221;.  This will ensure that the data we receive is properly interpreted as text.  Finally, we add an event listener to watch for an &#8220;Event.COMPLETE&#8221; to our URLLoader and invoke the &#8220;load()&#8221; method.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> urlComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	imageArray = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;,&quot;</span><span style="color: #66cc66;">&#41;</span>;
	currentImage = imageArray.<span style="color: #006600;">length</span>-<span style="color: #cc66cc;">1</span>;
	imageLoader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	imageLoader.<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>, imageLoaded<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageLoader<span style="color: #66cc66;">&#41;</span>;
	imageBitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span><span style="color: #66cc66;">&#41;</span>;
	imageBitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">this</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imageBitmap<span style="color: #66cc66;">&#41;</span>;
	switchImage<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> TimerEvent<span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	imageTimer = <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #66cc66;">&#40;</span>imgDur<span style="color: #66cc66;">&#41;</span>;
	imageTimer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>TimerEvent.<span style="color: #006600;">TIMER</span>, switchImage<span style="color: #66cc66;">&#41;</span>;
	imageTimer.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>&#8220;urlComplete&#8221; is the method that fires off once our URLLoader request is returned to Flash.  We are doing four main things here for the final setup of our slideshow.  </p>
<ol>
<li>First, we use the &#8220;split()&#8221; method to assign each file name to an Array called &#8220;imageArray&#8221;.  We access the returned data (comma-delimited string) through the data property of the event target.  The &#8220;currentImage&#8221; variable keeps track of which image is being displayed later on.  We now set this to the Array length minus one.  This provides us with the final index of our Array.</li>
<li>Next, we will set up our display objects and add them to the display list.  We create a Loader instance &#8220;imageLoader&#8221; to hold our loaded image and display it upon the Stage.  We also add an event listener to the &#8220;contentLoaderInfo&#8221; property of our Loader instance.  This will enable us to detect when the load has completed so that we can safely display the next image.</li>
<li>Similar to the Loader instance, we now create a new BitmapData object &#8220;imageBitmapData&#8221; matching the size of our Stage.  This will be used later on during image transitions and will feed a Bitmap object &#8220;imageBitmap&#8221; that we now create and add to the Stage.</li>
<li>Finally, we set up a Timer  to run based off of the &#8220;imgDur&#8221; variable set upon initialization.  We just need to add an event listener to the Timer to handle each new image load and then invoke the &#8220;start()&#8221; method to get things rolling.  Note that I am also manually triggering the &#8220;switchImage&#8221; method so we do not have to wait a full tick before our first image is shown.</li>
</ol>
<p>Now we have our data imported and arranged nicely.  Our structures and display list are all established.  Everything is set up to begin actually displaying these images upon the Stage.  In <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-3/">Part 3</a>, we will examine the two remaining methods and have a look at the full, completed class structure.</p>
]]></content:encoded>
			<wfw:commentRss>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple AS3 Slideshow Widget: Part 1</title>
		<link>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simple-as3-slideshow-widget-part-1</link>
		<comments>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 23:48:38 +0000</pubDate>
		<dc:creator>Joseph Labrecque</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://inflagrantedelicto.memoryspiral.com/?p=504</guid>
		<description><![CDATA[This is a simple example of how to build a dynamic slideshow widget in Flash using ActionScript 3.0 such as the one seen here. The first thing you&#8217;ll need to do is set up an FLA with the properties you&#8217;d &#8230; <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a simple example of how to build a dynamic slideshow widget in Flash using ActionScript 3.0 such as the one seen <del datetime="2009-08-29T00:52:50+00:00">here</del>.</p>
<p>The first thing you&#8217;ll need to do is set up an FLA with the properties you&#8217;d like to exhibit.   Stage resolution is set to 500&#215;300 with a black background.  This will vary depending on the size of your generated images.  Be sure that your FLA is set to use ActionScript 3.0 and declare your document class, in this case &#8220;SlideShow&#8221;.</p>
<p>Let&#8217;s set up a PHP file to read from the directory of our choosing and return a list of images to us.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$firstrun</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;images&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So, here we declare some variables. &#8220;$firstrun&#8221; to determine where we are in our loop, and &#8220;$files&#8221; to hold the comma-delimited list the loop will produce.  &#8220;$dir&#8221; is a directory reference for our image directory.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</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: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.gif&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.jpg&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;.png&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</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;">$firstrun</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$firstrun</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$files</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$files</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;,&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$files</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The next part is pretty simple as well.  We create &#8220;$files&#8221; and populate it with all of the files in our directory.  Next, we simply loop over each item and look for certain character sequences to determine whether we should include a particular file in our list of images.  You can see that the &#8220;$firstrun&#8221; Boolean is used here to determine comma placement for each item.</p>
<p>It is assumed at this point that we have also generated a set of images to use in our slide show and have dumped them into our &#8220;images&#8221; directory on the server.</p>
<p>So now it&#8217;s time to create an ActionScript class to use as the FLA document class.  We called this class &#8220;SlideShow&#8221; in our FLA so this is the exact name we will need to give the file &#8220;SlideShow.as&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;">package <span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SlideShow <span style="color: #0066CC;">extends</span> Sprite <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> SlideShow<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: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Here is the basic setup for our SlideShow class.  It extends flash.display.Sprite so we have to be sure to import that in our package.  Planning our class, we are going to need to define a few different methods:</p>
<p><strong>gatherFiles()</strong><br />
This will be used to create a connection to the server and run the PHP code we previously created.</p>
<p><strong>urlComplete()</strong><br />
Will handle the processing of the comma-delimited String which is returned by PHP and the setup of our display objects on the Stage.</p>
<p><strong>switchImage()</strong><br />
Will handle the image management and loading features.</p>
<p><strong>imageLoaded()</strong><br />
This will serve to process our image transitions and is triggered as each image load completes.</p>
<p>In <a href="http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-2/">Part 2</a>, we will look at each of these methods in detail.</p>
]]></content:encoded>
			<wfw:commentRss>http://inflagrantedelicto.memoryspiral.com/2009/01/simple-as3-slideshow-widget-part-1/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
