<?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>Flash - TheTechlabs.com</title>
	<atom:link href="https://www.thetechlabs.com/category/flash/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.thetechlabs.com</link>
	<description>The Tech Labs</description>
	<lastBuildDate>Mon, 15 Feb 2016 10:21:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Creating a Gallery in Flash Using the Moto CMS Component</title>
		<link>https://www.thetechlabs.com/tech-tutorials/flash/moto-cms-photo-gallery/</link>
		
		<dc:creator><![CDATA[Paul Flores]]></dc:creator>
		<pubDate>Wed, 10 Aug 2011 15:13:01 +0000</pubDate>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tech News]]></category>
		<category><![CDATA[Tech Tutorials]]></category>
		<category><![CDATA[creating a gallery in flash]]></category>
		<category><![CDATA[motocms]]></category>
		<guid isPermaLink="false">https://www.thetechlabs.com/?p=4963</guid>

					<description><![CDATA[<p>In this tutorial we will create a gallery with the help of the Moto CMS Component. I think many of you have heard about (or even worked with) Moto Flash...</p>
<p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/moto-cms-photo-gallery/">Creating a Gallery in Flash Using the Moto CMS Component</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>In this tutorial we will create a gallery with the help of the <strong>Moto CMS</strong> Component.</p>
<p>I think many of you have heard about (or even worked with) <strong>Moto Flash CMS</strong> &#8211; an advanced content management system for Flash. The CMS is considered as today&#8217;s most feature-rich system for Flash that  allows us to develop Flash websites with no limits in animation and effects, without getting into any coding.</p>
<p>The system is used by developers as a standalone version or together with a Flash template (that is actually a complete website that can be edited even by a user with no programming skills).</p>
<h1>Results of Moto CMS Component:</h1>
<p>Today I would like to show you what can be done with the help of the <em>Moto CMS</em> component. So, for creating a Flash photo gallery we will use two abstract classes.</p>
<p>Final Result:</p>
<figure id="attachment_5675" aria-describedby="caption-attachment-5675" style="width: 550px" class="wp-caption aligncenter"><a rel="nofollow" title="Moto CMS Gallery" href="http://demo.cms-guide.com/websites/tutorials/2/thumbnailsModule.swf" target="_blank"><img fetchpriority="high" decoding="async" class="size-full wp-image-5675 " src="https://www.thetechlabs.com/wp-content/uploads/2016/02/admin.jpg" alt="Moto CMS - CMS Photo Gallery" width="550" height="355" /></a><figcaption id="caption-attachment-5675" class="wp-caption-text">Moto CMS - CMS Photo Gallery</figcaption></figure>
<p><a rel="nofollow" title="Download Source" href="http://demo.cms-guide.com/websites/tutorials/2/source_files.zip" target="_blank"><img decoding="async" class="size-full wp-image-5676 aligncenter" src="http://www.motocms.com/wp-content/uploads/2011/08/sourcefiles.jpg" alt="" width="246" height="93" /></a></p>
<h2>1. FLA file settings For Moto CMS Gallery</h2>
<p style="text-align: left" lang="en-US">Let&#8217;s start by opening Flash and creating a new FLA file. We&#8217;ll name it thumbnailsModule.fla in this tutorial. It should be put in the same folder where the &#8220;src&#8221; folder is placed. Now we&#8217;ll open the Publish Settings (Ctrl+Shift+F12), open the ActionScript settings, and set the classpath &#8220;./src&#8221;:</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/01.png" alt="" width="497" height="631" /></p>
<h3 style="text-align: left">2. Creating the ThumbnailsModule Symbol CMS Photo Gallery</h3>
<p style="text-align: left" lang="en-US">Open the Components window (Ctrl+F7) and drag the Moto CMS Component, the Moto CMS Image Loader, and Photo Gallery Thumbnails components to the library.</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/02.png" alt="" width="550" /></p>
<p>Drag the Photo Gallery Thumbnails component to the stage, give it the instance name &#8220;preview&#8221;, and press F8 to convert it to Symbol. Let&#8217;s name it ThumbnailsModule; use the same name for the Class name, and set the Base class: <strong>modules.photoGalleryModules.ThumbnailsModule</strong></p>
<p>This class is not created yet, so we should create it before clicking OK. Let&#8217;s go to srcmodulesphotoGalleryModules and create ThumbnailsModule.as. We&#8217;ll add the script later.</p>
<p>Now let&#8217;s get back to the FLA, click OK, and select the created Movie Clip on the stage. We set its instance name to thumbnailsModule.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/03.png" alt="" width="345" height="665" /></p>
<p style="text-align: left" lang="en-US">Open the ThumbnailsModule Movie Clip. Let&#8217;s create a Shape object on a new layer with the Rectangle tool (R), set Alpha = 0% in its color settings, and convert it to Symbol. Let&#8217;s name it contentHolder and give it the same instance name on the stage. Then we convert it to Symbol again. We name it galleryHolder, and use the same instance name as well.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/04.png" alt="" width="323" height="699" /></p>
<p style="text-align: left" lang="en-US">As you can see, we have two layers in our ThumbnailsModule Movie Clip – one for preview, and the other for galleryHolder. The galleryHolder has the contentHolder inside.</p>
<h3 style="text-align: left">3. Creating navigation controls with Moto CMS</h3>
<p style="text-align: left" lang="en-US">Open the galleryHolder Movie Clip and insert a new layer. Let&#8217;s use the Pencil tool (Y) to draw an arrow on this layer. Then we can use the Transform Tool (Q) to rotate it the way we need to.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/05.png" alt="" width="363" height="700" /></p>
<p>As we draw the white arrow in this example, we change the Backgrond Color of the flash document to grey.</p>
<p>Let&#8217;s convert this arrow to Symbol. The name and the Class name will be ThumbnailsNavigationBtn, and the Base class will be: <strong>modules.photoGalleryModules.ThumbnailsNavigationBtn</strong></p>
<p>Let&#8217;s also set the Registration in the center.</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/06.png" alt="" width="550" /></p>
<p>We should create ThumbnailsNavigationBtn.as in srcmodulesphotoGalleryModules before clicking OK. We&#8217;ll leave the class empty for now.</p>
<p>Then we open the  ThumbnailsNavigationBtn Movie Clip and convert the arrow to Symbol again. Let&#8217;s name it &#8220;clip&#8221;, and give its instance the same name. The Registration should be set in the center.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/07.png" alt="" width="546" height="658" /></p>
<p>We should convert this Movie Clip to Symbol once again. This time it will be named &#8220;icon&#8221;. Registration: center. So now we have two Movie Clips inside the ThumbnailsNavigationBtn – &#8220;icon&#8221; and &#8220;clip&#8221;. We have created this structure to easily handle the button properties with the help of the script.</p>
<p>We should also create a Movie Clip which would be a hit area for the button. We open the  ThumbnailsNavigationBtn Movie Clip, insert a new layer, and put it under the icon layer. Then we draw a Shaped object of the arrow&#8217;s dimensions, make it transparent, and convert it to Symbol. Let&#8217;s name it &#8220;back&#8221;. The instance name should be &#8220;back&#8221; as well.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/08.png" alt="CMS Photo Gallery" width="306" height="668" /></p>
<p>Then we open this Movie Clip and convert the Shape object to Symbol again. This Movie Clip will be named backIcon. The instance name should be &#8220;icon&#8221;.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/09.png" alt="Moto CMS" width="348" height="668" /></p>
<p>Now we&#8217;ll get back to the galleryHolder Movie Clip, select the ThumbnailsNavigationBtn on the stage, and convert it to Symbol. It will be the controlsHolder Movie Clip with the same instance name. We should also place it in zero coordinates inside Moto CMS.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/10.png" alt="" width="377" height="668" /></p>
<p>Let&#8217;s open it, insert a new layer, and add one more instance of the ThumbnailsNavigationBtn Movie Clip to the stage. Again, in Moto CMS, lets&#8217; move it to the right and select Modify – Transform – Flip Horizontal. It will be the next button. Let&#8217;s give the buttons instance names prevBtn and nextBtn, respectively.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/11.png" alt="" width="484" height="668" /></p>
<p>So, we have created the thumbnails controls.</p>
<h3>4. Creating the Moto CMS item class</h3>
<p>Now we should create the thumbnail class (item renderer), which will be used by the script for every new thumbnail. Let&#8217;s get back to the main timeline of the FLA document and drag the <span style="text-decoration: underline">Moto CMS</span> Image Loader component to the stage. Let&#8217;s give it the instance name &#8220;image&#8221;. We should also open the Parameters tab and set the Scaling Mode: fill.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/12.png" alt="" width="437" height="407" /></p>
<p>Then we convert it to Symbol and name it imageHolder. Don&#8217;t forget to set the Move Clip Registration to the top left corner, as it was by default.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/13.png" alt="Moto CMS" width="548" height="668" /></p>
<p>Now we convert it to Symbol again. It will be the item renderer class, so we&#8217;ll check the &#8220;Export for ActionScript&#8221; box, and specify the class names:</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/14.png" alt="" width="550" /></p>
<p>We set Base class: <strong>modules.photoGalleryModules.ThumbnailItemRenderer</strong><br />
This class is not created yet, so we go to srcmodulesphotoGalleryModules and create an empty ThumbnailItemRenderer.as.</p>
<p>Now we can open the ThumbnailItemRenderer Movie Clip and animate the imageHolder. We should set the frame labels to &#8220;show&#8221;, &#8220;over&#8221;, and &#8220;out&#8221;. You can make any animation you like. In this example we make it appear from transparency (Alpha = 0% in the first keyframe), and increase its brightness on mouse over (Advanced color in the third keyframe, and 140% to every color channel).</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/15.png" alt="" width="550" /></p>
<p>We put the &#8220;stop();&#8221; code over each keyframe. There should also be the condition over the second keyframe, so that the selected thumbnail looks moused overe right after appearing:</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/16.png" alt="" width="616" height="211" /></p>
<p>Let&#8217;s also create the preloader. We insert a new layer, and create a Movie Clip with an instance name &#8220;preloader&#8221;. You can create any preloading animation insde this Movie Clip.</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/17.png" alt="" width="550" /></p>
<p style="text-align: left" lang="en-US">The item renderer is ready.</p>
<h3 style="text-align: left">5. Creating the thumbnail cover with Moto CMS</h3>
<p style="text-align: left" lang="en-US">Now we should create one more class, which will be something like a cover for the item renderer. Our thumbnails will have the border and the rounded corners set by the code, so it will be better to work with the cover.</p>
<p>Let&#8217;s get to to the main timeline and create a Movie Clip inside moto cms with a transparent shaped object. It&#8217;s instance name should be contentHolder (do not confuse with the contentHolder Movie Clip we have created before). Then we convert it to Symbol once again. We export it for ActionScript and specify the class names:</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/18.png" alt="" width="550" /></p>
<p>Base class: <strong>modules.photoGalleryModules.ThumbnailItemRendererCover</strong></p>
<p>Same as before, we should go to srcmodulesphotoGalleryModules and create an empty ThumbnailItemRendererCover.as.</p>
<p>Now we can open the ThumbnailItemRendererCover Movie Clip and create the animation. We should use the same frame labels as we used for the ThumbnailItemRenderer: &#8220;show&#8221;, &#8220;over&#8221;, and &#8220;out&#8221;. In this example we only create the animation of appearing from transparency. You may also create the animation of mouse over and mouse out, if needed.</p>
<p style="text-align: center" lang="en-US"><img decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/19.png" alt="" width="550" /></p>
<p>We have created all the needed elements in Flash. We should go to the main timeline and remove ThumbnailItemRenderer and ThumbnailItemRendererCover Movie Clips from the stage. They will be taken from the library via the linkage name. The only Movie Clip that has to be left on the stage is ThumbnailsModule.</p>
<h3>6. Creating the CMS Photo Gallery ThumbnailsModule class</h3>
<p>Now it&#8217;s time to create the script. The srcmodulesphotoGalleryModules path contains 6 AS files at the moment – 2 abstract classes, which will not be modified by us, and 4 empty classes. Let&#8217;s start from the main class – ThumbnailsModule.as. We add the class constructor with the main imports:</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.common.Moto;
	import com.moto.template.common.events.ExternalDataProviderEvent;
	import com.moto.template.common.view.IInteractiveItemRenderer;

	public class ThumbnailsModule extends AbstractGalleryThumbnailsModule
	{

		public function ThumbnailsModule()
		{
			super();

		}

	}
}</pre>
<p>Then we create the necessary variables:</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.common.Moto;
	import com.moto.template.common.events.ExternalDataProviderEvent;
	import com.moto.template.common.view.IInteractiveItemRenderer;

	public class ThumbnailsModule extends AbstractGalleryThumbnailsModule
	{
		private var _controlsHolder:MovieClip;
		private var _nextBtn:ThumbnailsNavigationBtn;
		private var _prevBtn:ThumbnailsNavigationBtn;
		private var _propertyNavigationBtnWidth:Number = 0;

		public function ThumbnailsModule()
		{
			super();

		}

	}
}</pre>
<p>Let&#8217;s also add MovieClip to imports: <strong>import flash.display.MovieClip;</strong></p>
<p>Then we should assign the variables to the created elements, and specify the next/previous buttons:</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.common.Moto;
	import com.moto.template.common.events.ExternalDataProviderEvent;
	import com.moto.template.common.view.IInteractiveItemRenderer;

	public class ThumbnailsModule extends AbstractGalleryThumbnailsModule
	{
		private var _controlsHolder:MovieClip;
		private var _nextBtn:ThumbnailsNavigationBtn;
		private var _prevBtn:ThumbnailsNavigationBtn;
		private var _propertyNavigationBtnWidth:Number = 0;

		public function ThumbnailsModule()
		{
			super();

			_controlsHolder = _galleryHolder["controlsHolder"];
			_nextBtn = _controlsHolder["nextBtn"];
			_prevBtn = _controlsHolder["prevBtn"];

			thumbnailsPaginator.nextButton = _nextBtn;
			thumbnailsPaginator.previousButton = _prevBtn;
		}

	}
}</pre>
<p>Now we override the updateProperty method. This method will handle the properties set in the xml file. Each case number matches the property ID in the XML file.</p>
<pre>		override public function updateProperty(propertyVO:PropertyVO):void
		{
			super.updateProperty(propertyVO);
			switch (propertyVO.propertyType)
			{
				case 8:
					_nextBtn.updateProperty(propertyVO);
					_prevBtn.updateProperty(propertyVO);
				break;

				case 18:
				case 19:
				case 20:
					_nextBtn.updateProperty(propertyVO);
					_prevBtn.updateProperty(propertyVO);
				break;
			}
		}</pre>
<p>We should also add PropertyVO to imports:</p>
<p><strong>import com.moto.template.shell.model.vo.PropertyVO;</strong></p>
<p>Then we override the protected method switchPaginatorHandler. We check whether there is the next/previous page and disable the appropriate button if not. Also we check to see if the thumbnail is clicked now. If it is not, the script switches pages.</p>
<pre>		override protected function switchPaginatorHandler(event:Event = null):void
		{
			if (thumbnailsPaginator.hasNextPage())
			{
				_nextBtn.alpha = 1;
				_nextBtn.mouseEnabled = true;
			}
			else
			{
				_nextBtn.alpha = .5;
				_nextBtn.mouseEnabled = false;
			}

			if (thumbnailsPaginator.hasPreviousPage())
			{
				_prevBtn.alpha = 1;
				_prevBtn.mouseEnabled = true;
			}
			else
			{
				_prevBtn.alpha = .5;
				_prevBtn.mouseEnabled = false;
			}

			if (thumbnailsArranger.rememberSelectedItem)
			{
				thumbnailsArranger.selectItemRendererByIndex(currentIndex, false);
				if(thumbnailsArranger.selectedItemRenderer){
					ThumbnailItemRendererCover(thumbnailsArranger.selectedItemRenderer).showOverState();
				}
			}
		}</pre>
<p>Let&#8217;s also import Event:</p>
<p><strong>import flash.events.Event;</strong></p>
<p>The next method which we are going to override is setSize. This method contains the logic of resizing and positioning.</p>
<pre>		override public function setSize(newWidth:Number, newHeight:Number):void
		{
			super.setSize(newWidth, newHeight);

			newWidth = int(newWidth);
			newHeight = int(newHeight);

			if (initialized)
			{
				_nextBtn.setSize(newHeight, _propertyNavigationBtnWidth);
				_prevBtn.setSize(newHeight, _propertyNavigationBtnWidth);

				_nextBtn.x = _contentHolder.width;
				_controlsHolder.y = newHeight/2;
				_controlsHolder.rotation = 0;
				_contentHolder.x = 0;
				_contentHolder.y = 0;
			}
		}</pre>
<p>We should add OrientationEnum to imports:</p>
<p><strong>import com.moto.template.common.view.OrientationEnum;</strong></p>
<p>Finally we override the show and hide methods to add tweens.</p>
<pre>		override public function show():void
		{
			super.show();
			this.mouseChildren = true;
			Tweener.addTween(this, { alpha:1, time:.5 } );

		}

		override public function hide():void
		{
			super.hide();
			this.mouseChildren = false;
			Tweener.addTween(this, { alpha:0, time:.5} );
		}</pre>
<p>We add the Tweener class to imports:</p>
<p><strong>import caurina.transitions.Tweener;</strong></p>
<h3>7. Creating the ThumbnailItemRenderer class</h3>
<p>When the ThumbnailsModule class is ready, we can switch over to ThumbnailItemRenderer.as. The class constructor will be:</p>
<pre>package modules.photoGalleryModules
{

	public class ThumbnailItemRenderer extends AbstractThumbnailItemRenderer
	{

		public function ThumbnailItemRenderer()
		{
			super();

		}

	}
}</pre>
<p>Then we create variables for image and preloader and import the needed classes.</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.common.view.components.loaders.ImageLoader;
	import flash.display.MovieClip;	

	public class ThumbnailItemRenderer extends AbstractThumbnailItemRenderer
	{
		private var _image:ImageLoader;
		private var _preloader:MovieClip;

		public function ThumbnailItemRenderer()
		{
			super();

		}

	}
}</pre>
<p>Now we assign the variables to the elements in the class constructor.</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.common.view.components.loaders.ImageLoader;
	import flash.display.MovieClip;	

	public class ThumbnailItemRenderer extends AbstractThumbnailItemRenderer
	{
		private var _image:ImageLoader;
		private var _preloader:MovieClip;

		public function ThumbnailItemRenderer()
		{
			super();

			_image = imageHolder["image"];
			_preloader = this["preloader"];

			_preloader.alpha = 0;
		}

	}
}</pre>
<p>Then we override the updateRenderer method. We specify the image path and add listeners for successful complete and error events.</p>
<p>These classes should be added to imports:</p>
<p><strong>import com.moto.template.common.events.MediaLoaderErrorEvent;<br />
import flash.events.Event;</strong></p>
<pre>		override public function updateRenderer(data:Object):void
		{
			super.updateRenderer(data);

			_image.source = pathPrefix + dataVO.getPropertyValueByID(2);
			_image.addEventListener(Event.COMPLETE, imageCompleteHandler);
			_image.addEventListener(MediaLoaderErrorEvent.ERROR, imageCompleteHandler);			

			Tweener.addTween(_preloader, {alpha:1 , delay:0.5, time:1});
		}</pre>
<p>The events will be handled by the imageCompleteHandler method, which we need to create now. In case of succesful complete we hide the preloader and play the showing animation.</p>
<pre>		private function imageCompleteHandler(event:Event):void {
			switch(event.type) {
				case Event.COMPLETE:
					Tweener.addTween(_preloader, { alpha:0, time:1 } );
					show();
					gotoAndPlay(showLabel);
				break;

				case MediaLoaderErrorEvent.ERROR:
					Tweener.addTween(_preloader, { alpha:0, time:1 } );
				break;
			}

		}</pre>
<p>Let&#8217;s also import the Tweener class:</p>
<p><strong>import caurina.transitions.Tweener;</strong></p>
<p>The next step will be overriding the setSize method and adding the resizing logic.</p>
<pre>		override public function setSize(newWidth:Number, newHeight:Number):void
		{
			newWidth = newWidth || getDimensions().width;
			newHeight = newHeight || getDimensions().height;

			_image.setSize(newWidth, newHeight);
			_image.drawNow();

			_preloader.x = (newWidth - _preloader.width) / 2;
			_preloader.y = (newHeight - _preloader.height) / 2;
		}</pre>
<p>The getDimensions method passes the actual size of the element. So, we override it and return a rectangle of image dimensions.</p>
<pre>		override public function getDimensions():Rectangle
		{
			return new Rectangle(0, 0, _image.width, _image.height);
		}</pre>
<p>Rectangle should be added to imports:</p>
<p>import flash.geom.Rectangle;</p>
<h3>8. Creating the ThumbnailItemRendererCover class</h3>
<p>Right after the ThumbnailItemRenderer class we are going to write a script for its &#8220;cover&#8221; – ThumbnailItemRendererCover.as. Let&#8217;s start with adding the basic code:</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.modules.gallery.GalleryThumbnailCover;
	import flash.display.MovieClip;

	public class ThumbnailItemRendererCover extends GalleryThumbnailCover
	{

		public function ThumbnailItemRendererCover()
		{
			super();

		}

	}
}</pre>
<p>We add a new variable, which will be used in the script. Then we create a new Sprite object in the base class and add a content holder. This way we implement the thumbnail covering. We also enable buttonMode, disable mouseChildren, and add an event listener.</p>
<pre>package modules.photoGalleryModules
{
	import com.moto.template.modules.gallery.GalleryThumbnailCover;
	import flash.display.MovieClip;

	public class ThumbnailItemRendererCover extends GalleryThumbnailCover
	{
		private var _borderThicknessOnOver:uint;

		public function ThumbnailItemRendererCover()
		{
			super(new Sprite());

			Sprite(this["contentHolder"]).addChild(_contentHolder);

			buttonMode = true;
			mouseChildren = false;

			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler)
		}

	}
}</pre>
<p>Let&#8217;s also add Sprite and Event classes to imports:</p>
<p><strong>import flash.display.Sprite;<br />
import flash.events.Event;</strong></p>
<p>Now we should create a function which will be fired when the thumbnail cover is added to stage. It should remove the event listener and play the showing animation.</p>
<pre>		private function addedToStageHandler(event:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);

			show();
			gotoAndPlay(showLabel);
		}</pre>
<p>Then we override the updateProperty method. It will handle the thumbnail properties related to the border shaping. This way we apply them to the cover, not to the thumbnail itself.</p>
<pre>		override public function updateProperty(propertyVO:PropertyVO):void
		{
			super.updateProperty(propertyVO);
			var thisDimensions:Rectangle = getDimensions();
			switch (propertyVO.propertyType)
			{
				case 6:
					_roundRadius = uint(propertyVO.value) * 2;

					setSize(thisDimensions.width, thisDimensions.height);
				break;

				case 7:
					_borderThicknessOnOver = uint(propertyVO.value);
					_strokeThickness = 0;
					setSize(thisDimensions.width, thisDimensions.height);
				break;

				case 8:
					_strokeColor = uint(propertyVO.value);

					setSize(thisDimensions.width, thisDimensions.height);
				break;

				case 9:
					_strokeAlpha = uint(propertyVO.value) / 100;

					setSize(thisDimensions.width, thisDimensions.height);
				break;
			}
		}</pre>
<p>We also add PropertyVO and Rectangle to imports:</p>
<p><strong>import com.moto.template.shell.model.vo.PropertyVO;<br />
import flash.geom.Rectangle;</strong></p>
<p>Then we add getter and setter for the stroke thickness property.</p>
<pre>		public function get strokeThickness():uint {
			return _strokeThickness;
		}

		public function set strokeThickness(value:uint):void {
			_strokeThickness = value;
		}</pre>
<p>We should also create the showOverState method, which will be called to play the mouseover animation when a new thumbnail is selected by the prev/next button.</p>
<pre>		public function showOverState():void {
			over();
		}</pre>
<p>Then we override over and out methods and add tweens for mouseover and mouseout animation.</p>
<pre>		override protected function over():void
		{
			super.over();

			Tweener.addTween(this, {strokeThickness:_borderThicknessOnOver, time:0.3, rounded:true, onUpdate:setSize, onUpdateParams:[0, 0]} );
		}

		override protected function out():void
		{
			super.out();

			Tweener.addTween(this, {strokeThickness:0, time:0.6, onUpdate:setSize, onUpdateParams:[0, 0]} );
		}</pre>
<p>Let&#8217;s also import the Tweener class:</p>
<p><strong>import caurina.transitions.Tweener;</strong></p>
<p>The ThumbnailItemRendererCover class is ready.</p>
<h3>9. Creating the ThumbnailsNavigationBtn class</h3>
<p>Now we proceed to the only class left – ThumbnailsNavigationBtn. Let&#8217;s add the basic code.</p>
<pre>package modules.photoGalleryModules
{
	import common.AbstractNavigationBtn;

	public class ThumbnailsNavigationBtn extends AbstractNavigationBtn
	{

		public function ThumbnailsNavigationBtn()
		{
			super();

		}

	}
}</pre>
<p>Then we create new variables which will be used in the script.</p>
<pre>package modules.photoGalleryModules
{
	import common.AbstractNavigationBtn;
	import flash.display.MovieClip;

	public class ThumbnailsNavigationBtn extends AbstractNavigationBtn
	{
		private var _backShape:MovieClip;
		private var _iconShape:MovieClip;

		private var _propertyBackColor:uint = 0x000000;
		private var _propertyBackAlpha:Number = .15;

		private var _propertyIconColor:uint = 0xFFFFFF;
		private var _propertyActiveIconColor:uint;
		private var _propertyIconAlpha:Number = .15;

		private var _propertyRoundRadius:uint = 0;

		public function ThumbnailsNavigationBtn()
		{
			super();

		}

	}
}</pre>
<p>In the class constructor we stop the playback on the first frame, set buttonMode and mouseChildren, specify hitArea, assign variables to the elements, and initialize ColorShortcuts.</p>
<pre>package modules.photoGalleryModules
{
	import caurina.transitions.properties.ColorShortcuts;
	import common.AbstractNavigationBtn;
	import flash.display.MovieClip;

	public class ThumbnailsNavigationBtn extends AbstractNavigationBtn
	{
		private var _backShape:MovieClip;
		private var _iconShape:MovieClip;

		private var _propertyBackColor:uint = 0x000000;
		private var _propertyBackAlpha:Number = .15;

		private var _propertyIconColor:uint = 0xFFFFFF;
		private var _propertyActiveIconColor:uint;
		private var _propertyIconAlpha:Number = .15;

		private var _propertyRoundRadius:uint = 0;

		public function ThumbnailsNavigationBtn()
		{
			super();

			gotoAndStop(1);

			buttonMode = true;
			mouseChildren = false;
			hitArea = back;

			_backShape = back["clip"];
			_iconShape = icon["clip"];

			ColorShortcuts.init();

		}

	}
}</pre>
<p>Then we override the updateProperty method and handle the buttons&#8217; properties, such as color and transparency level.</p>
<pre>		override public function updateProperty(propertyVO:PropertyVO):void
		{
			super.updateProperty(propertyVO);
			switch (propertyVO.propertyType)
			{
				case 18:
					_propertyActiveIconColor = uint(propertyVO.value);
				break;

				case 19:
					_propertyIconColor = uint(propertyVO.value);

					MotoUtils.setColor(_iconShape, _propertyIconColor, _propertyIconAlpha);
				break;

				case 20:
					_propertyIconAlpha = uint(propertyVO.value) / 100;

					MotoUtils.setColor(_iconShape, _propertyIconColor, _propertyIconAlpha);
				break;
			}
		}</pre>
<p>Finally we override over and out methods. We add tweens and set them to colour the buttons on mouseover and mouseout.</p>
<pre>		override public function over():void
		{
			super.over();
			Tweener.addTween(this, {_color:_propertyActiveIconColor, time:1} );
		}

		override public function out():void
		{
			super.out();
			Tweener.addTween(this, {_color:_propertyIconColor, time:1} );
		}</pre>
<p>So we have created all the needed classes.</p>
<h3>10. Initializing the module</h3>
<p>If we added this gallery to Moto template, it would be initialized automatically. We want to initialize it outside the template, so we need to add special code. Let&#8217;s go to the main timeline of the FLA file and insert a new layer. Then we select the first frame and press F9. We should insert this code:</p>
<pre>import org.puremvc.as3.multicore.patterns.facade.Facade;
import com.moto.template.shell.model.vo.*;
import com.moto.template.shell.model.*;
import com.moto.template.common.*;

var _propertiesXML:XML = new XML(
	'' +
		'' + // Widget Connection ID. This property is needed only when the module is loaded in the Moto template.
		'' + // Prevent Second Click
		'' + // Image to Start From
		'' + // Item Creation Delay
		'' + // Item Corner Radius
		'' + // Item Border Width
		'' + // Item Border Color
		'' + // Item Border Alpha
		'' + // Item Width
		'' + // Vertical Spacing
		'' + // Rows
		'' + // Active Arrows Color
		'' + // Base Arrows Color
		'' + // Arrows Alpha
	''
);

var _facade:Facade = new Facade("TEST");
_facade.registerProxy(new WebsiteProxy(this));
var _motoProxy:MotoProxy = new MotoProxy();
_facade.registerProxy(_motoProxy);
var _templateMoto:TemplateMoto = new TemplateMoto(_motoProxy);
Moto.setInstance(_templateMoto);

initializeModule(
	thumbnailsModule,
	[],
	'' +
		'gallery.xml' +
		'ThumbnailItemRenderer' +
		'ThumbnailItemRendererCover' +
	'',
	true
);

function initializeModule(module:MovieClip, propertiesValues:Array = null, data:String = "",
	resizable:Boolean = true):void
{
	// Module type
	var moduleTypeVO:ModuleTypeVO = new ModuleTypeVO();
	moduleTypeVO.resizable = resizable;

	// Slot
	var moduleVO:ModuleVO = new ModuleVO();
	moduleVO.moduleType = moduleTypeVO;

	moduleVO.width= 937;
	moduleVO.height = 671;
	moduleVO.x = 62;
	moduleVO.y = 0;

	// Properties
	moduleVO.properties = propertiesParser(_propertiesXML);

	// data
	moduleVO.data = data;

	// Init slot
	module.init(moduleVO);
}

function propertiesParser(xml:XML):Array
{
	var objectProperties:Array = [];
	for each (var property:XML in xml.elements())
	{
		var propertyType:uint = uint(property.@propertyType);
		if (propertyType)
		{
			var propertyVO:PropertyVO = new PropertyVO();
			propertyVO.propertyType = propertyType;
			propertyVO.value = String(property);

			// Get parameters
			propertyVO.parameters = new Object();
			for each (var parameter:XML in property.attributes())
			{
				var key:String = parameter.name().toString();
				var value:String = parameter.valueOf().toString();
				propertyVO.parameters[key] = value;
			}

			objectProperties.push(propertyVO);
		}
	}
	return objectProperties;
}</pre>
<p>There is a set of properties in _propertiesXML. These properties are handled by updateProperty methods, which we have created in AS files. Lines 36-38 contain the XML file name and the thumbnail&#8217;s and its cover&#8217;s library linkage names. Lines 54-57 contain the module&#8217;s width, height, and coordinates. You can adjust these values to your needs.</p>
<p>Let&#8217;s open the Flash Document Properties and set the dimensions. These values depend on the thumbnails gallery size. In this example we set 1040 x 671.</p>
<p style="text-align: center" lang="en-US"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-5675" src="http://www.motocms.com/wp-content/uploads/2011/08/20.png" alt="" width="371" height="338" /></p>
<h3>11. Creating the Moto CMS gallery XML file.</h3>
<p>The script from the previous step contains reference to the gallery.xml file. We can put it to the same directory where our SWF file is placed, or create somea folder and add a path prefix to the gallery.xml file location. Here is the XML file content:</p>
<pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;simpleGalleryModule&gt;
 &lt;configuration&gt;
 &lt;option id="previewPropertyID"&gt;
 &lt;value&gt;1&lt;/value&gt;
 &lt;/option&gt;
 &lt;option id="thumbnailPropertyID"&gt;
 &lt;value&gt;2&lt;/value&gt;
 &lt;/option&gt;
 &lt;option id="thumbnailWidth"&gt;
 &lt;value&gt;299&lt;/value&gt;
 &lt;/option&gt;
 &lt;option id="thumbnailHeight"&gt;
 &lt;value&gt;217&lt;/value&gt;
 &lt;/option&gt;
 &lt;option id="maxRootItems"&gt;
 &lt;value&gt;0&lt;/value&gt;
 &lt;/option&gt;
 &lt;/configuration&gt;
 &lt;structure&gt;
 &lt;properties&gt;
 &lt;property id="1" type="media"&gt;
 &lt;name&gt;&lt;![CDATA[Preview]]&gt;&lt;/name&gt;
 &lt;parameters&gt;
 &lt;image&gt;true&lt;/image&gt;
 &lt;flash&gt;true&lt;/flash&gt;
 &lt;video&gt;true&lt;/video&gt;
 &lt;/parameters&gt;
 &lt;/property&gt;
 &lt;property id="2" type="image"&gt;
 &lt;name&gt;&lt;![CDATA[Thumbnail]]&gt;&lt;/name&gt;
 &lt;/property&gt;
 &lt;property id="3" type="link"&gt;
 &lt;name&gt;&lt;![CDATA[Link]]&gt;&lt;/name&gt;
 &lt;/property&gt;
 &lt;/properties&gt;
 &lt;template&gt;
 &lt;properties&gt;
 &lt;item propertyType="1"/&gt;
 &lt;item propertyType="2"/&gt;
 &lt;item propertyType="3"/&gt;
 &lt;/properties&gt;
 &lt;/template&gt;
 &lt;/structure&gt;
 &lt;data&gt;
 &lt;item id="1" order="1"&gt;&lt;properties&gt;&lt;item propertyType="1"&gt;&lt;![CDATA[images/image1_big.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="2"&gt;&lt;![CDATA[images/image1_small.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="3"&gt;&lt;![CDATA[]]&gt;&lt;/item&gt;&lt;/properties&gt;&lt;/item&gt;
 &lt;item id="2" order="2"&gt;&lt;properties&gt;&lt;item propertyType="1"&gt;&lt;![CDATA[images/image2_big.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="2"&gt;&lt;![CDATA[images/image2_small.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="3"&gt;&lt;![CDATA[]]&gt;&lt;/item&gt;&lt;/properties&gt;&lt;/item&gt;
 &lt;item id="3" order="3"&gt;&lt;properties&gt;&lt;item propertyType="1"&gt;&lt;![CDATA[images/image3_big.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="2"&gt;&lt;![CDATA[images/image3_small.jpg]]&gt;&lt;/item&gt;&lt;item propertyType="3"&gt;&lt;![CDATA[]]&gt;&lt;/item&gt;&lt;/properties&gt;&lt;/item&gt;
 &lt;/data&gt;
&lt;/simpleGalleryModule&gt;</pre>
<p>The gallery elements should be put in the  tag. Three items are already added as an example. Every an item has three properties, properties with id 1 and 2 are the preview and the thumbnail images paths. The third property can be used for specifying a link. You can just duplicate the existing &#8220;item&#8221; node to add as many elements as you need. Please note that every new item must have the unique &#8220;id&#8221; and &#8220;order&#8221; attributes.</p>
<p>This post on Moto CMS was brought to you by Paul Flores. He currently works with the Moto CMS components and develops <a rel="nofollow" href="http://www.motocms.com/why/">Flash websites</a> on the basis of Moto CMS and Moto <a rel="nofollow" href="http://templates.motocms.com/">Flash templates</a>.</p>
<p>Thank you for reading the <strong>Moto CMS</strong> tutorial! I hope you liked it. <em><strong>Your comments will be highly appreciated.</strong></em></p>
<p><em><strong><br />
</strong></em></p><p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/moto-cms-photo-gallery/">Creating a Gallery in Flash Using the Moto CMS Component</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Create an intelligent XML image Gallery &#038; Slideshow in Flash CS4 (+PHP) – Part II/II</title>
		<link>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/</link>
					<comments>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/#comments</comments>
		
		<dc:creator><![CDATA[Mario Santos]]></dc:creator>
		<pubDate>Wed, 01 Dec 2010 13:34:11 +0000</pubDate>
				<category><![CDATA[Effects]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tech Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[creation]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[thumbs]]></category>
		<guid isPermaLink="false">https://www.thetechlabs.com/?p=2083</guid>

					<description><![CDATA[<p>In this second part article you will learn how to build an image gallery that will load images from a web server. I decide to call it "Intelligent" because you don't need to configure any XML or flash file. Just put the Flash movie and the images on a server and they will be loaded automatically. Nice ah?</p>
<p>The post <a href="https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/">Create an intelligent XML image Gallery & Slideshow in Flash CS4 (+PHP) – Part II/II</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<h2>Create an intelligent XML image Gallery &amp; Slideshow in Flash CS4 (+PHP) &#8211; Part I/II</h2>
<p>Here is the first part: <a href="https://www.thetechlabs.com/tech-tutorials/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/" target="_blank">Create an intelligent XML image Gallery &amp; Slideshow in Flash CS4 (+PHP) &#8211; Part I/II</a></p>
<p>&nbsp;</p>
<h2>Create an intelligent XML image Gallery &amp; Slideshow in Flash CS4 (+PHP) &#8211; Part II/II</h2>
<p style="text-align: justify;">In the second part you will transform your gallery made on the first part of this two-part tutorial into a gallery with some polaroid distributed thumbnails. You will also learn how to auto-create those thumbs in php, load them randomly into flash and use the same animation style to show the gallery.</p>
<p style="text-align: justify;">We will add also a simple button to swap from thumbnails gallery (part two) to slideshow (part one).</p>
<p style="text-align: justify;">First let&#8217;s take a look to this second part final result.</p>
<p>&nbsp;</p>
<h2><strong>Final Result:</strong></h2>
<p><strong>https://www.thetechlabs.com/wp-content/uploads/2010/11/gallery.swf</strong></p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2010/11/gallery.swf" type="application/x-shockwave-flash" width="700" height="450"><param name="quality" value="autohigh" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2010/11/gallery.swf" /></object></p>
<p style="text-align: justify;">This gallery will have some cool final result features, let&#8217;s take a brief look:</p>
<ul>
<li>Auto-find images in folder (works with PNG, JPEG, JPG)</li>
<li>Write an XML file automatically</li>
<li>Can work only with an XML file and without php</li>
<li>Have a full screen option</li>
<li>Fits automatically the screen center</li>
<li>Can customize the speed of slideshow</li>
<li>Automatically generate thumbnails of images in folder *</li>
<li>Spread the thumbnails automatically on the screen *</li>
<li>Make the slideshow static (only opens in thumbnail click) *</li>
</ul>
<p style="text-align: justify;">This tutorial is be divided into two parts, the first one is available <a href="https://www.thetechlabs.com/tutorials/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/" target="_blank">here</a>.</p>
<div style="width770px;text-align: center;"><a href="https://www.thetechlabs.com/wp-content/uploads/2010/11/final_source.zip" target="_blank"><img loading="lazy" decoding="async" class="size-full wp-image-466 aligncenter" style="border: 0pt none;" src="https://www.thetechlabs.com/wp-content/uploads/2009/04/sourcefiles.jpg" alt="Download Source Files" width="246" height="93" /></a></div>
<p>&nbsp;</p>
<h2><strong>Requirements</strong></h2>
<p>&nbsp;</p>
<ul>
<li>Have Flash CS4.</li>
<li>An amp server (or similar like <a href="http://www.wampserver.com/" target="_blank" rel="nofollow">wampserver</a>), any online hosting with php support works to.</li>
<li>The TweenLite engine that you can download <a href="http://blog.greensock.com/tweenliteas3/" target="_blank">here</a>.</li>
<li>The first part of this tutorial, that can be downloaded <a href="https://www.thetechlabs.com/wp-content/uploads/2009/07/imagegal_slideshow.zip" target="_blank">here</a>.</li>
<li>The open source thumb creation class available <a href="http://www.phpclasses.org/browse/package/1476.html" target="_blank" rel="nofollow">here</a>. Can be downloaded directly <a href="https://www.thetechlabs.com/wp-content/uploads/2010/11/thumbs_creation-2004-12-26.zip" target="_blank">here</a>.</li>
<li>Have <a href="https://www.thetechlabs.com/wp-content/uploads/2010/11/Polaroid.png" target="_blank">this polaroid image</a> to add a better look and feel to our loaded thumb.</li>
</ul>
<p style="text-align: left;"><strong><br />
</strong></p>
<h2><strong>Pre Requirements</strong></h2>
<p>&nbsp;</p>
<ul>
<li>Know a little of PHP.</li>
<li>Understand the concept of constraint layout in flash (auto position content).</li>
<li>A good knowledge of Flash, especially Action Script 3.</li>
</ul>
<p><strong><br />
</strong></p>
<h2><strong>Getting started</strong></h2>
<p>It&#8217;s highly recommended that you go through the first part of tutorial first. Explore the code a little and understand the php part of it. A good knowledge of constraint layouts is a must.</p>
<p>This second part is easier to follow and achieve than the first part, but pay attention to all steps, they are most of them in action script code, so I recommend that you write them and not copy. This is great to practice. Remember; Write instead Copy &amp; Paste!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2><strong>Step 1 &#8211; Updating PHP files</strong></h2>
<p>&nbsp;</p>
<p>All the php files are supposed to be in the c:/www/wamp folder, so we will continue with this. Grab the thumbnail files (the class.files.php and class.thumbs.php) form <a href="https://www.thetechlabs.com/wp-content/uploads/2010/11/thumbs_creation-2004-12-26.zip" target="_blank">this archive</a> and put them on the previously created folder called gallery. Then just open the imageHandler.php file, find the ary2xml() function and inside it, got to the line:</p>
<pre>$data.="&lt;image nameI="".$arr[$h]."" thumb="".$arr[$h]."" /&gt;rn";</pre>
<p>and replace it by this one:</p>
<pre>$data.="&lt;image nameI="".$arr[$h]."" thumb="thumbs/".$arr[$h]."" /&gt;rn";</pre>
<p>This will update your gallery thumbnails path to the folder thumbs so the flash searches this folder for thumbnails. This will do nothing for now because the main thumbnail generation job will be made by those two files we had added on the folder. Just save the file.</p>
<p>&nbsp;</p>
<h2><strong>Step 2 &#8211; Creating the thumbnails with PHP</strong></h2>
<p>This step is quite easy because those two classes are ready to use. Just open your discover.php file and do the following changes:</p>
<p>Add this line after the &lt;?php to call your thumb generation class:</p>
<pre>include_once("class.thumbs.php");</pre>
<p>and before this:</p>
<pre>print_r($tm-&gt;ary2xml($data,0,'',"images.xml"));</pre>
<p>add these two lines:</p>
<pre>$thumbs = new thumbs("./", 0, "thumbs/", false, 0, 100, false, 125, 125);

  $thumbs-&gt;creates_thumbs();</pre>
<p>And that&#8217;s all! This will create thumbnails with 125x125px in the thumbs folder with the same image name. Our thumbs are ready to use. Save the file and open the previous flash project.</p>
<p>&nbsp;</p>
<h2><strong>Step 3 &#8211; Creating a polaroid thumbnail</strong></h2>
<p>With your flash project open, just go to menu Insert-&gt;New Symbol and create a movieClip with polaroidMC name and export it to action script, like this: (please note that my ui language is French, but should be easy to understand when you have this window on flash)</p>
<div style="width: 740px; text-align: center;"><span style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057" src="https://www.thetechlabs.com/wp-content/uploads/2010/11/1.jpg" alt="1" width="415" height="306" /></span></div>
<p>This will create a movieClip that can be loaded from action script to create multiple instances of it. Is the fast way to duplicate items on stage. All the regular MovieClip properties will be available in this movieClip also.</p>
<p>Now, just import into stage our polaroid.png image and center in on stage. File-&gt;Import-&gt;Import into stage and select our <a href="https://www.thetechlabs.com/wp-content/uploads/2010/11/Polaroid.png" target="_blank">polaroid image.</a> Make it similar to this:</p>
<div style="width: 740px; text-align: center;"><span style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057" src="https://www.thetechlabs.com/wp-content/uploads/2010/11/2.jpg" alt="1" width="554" height="238" /></span></div>
<p>Then we just need to put a text input into the bottom part to display the image name and a empty and masked movieclip to load the thumb picture. This is quite easy, create 3 more layers over the existing one, name the first one Text, the second Image Loader and the third Mask.</p>
<p>Now, on the first one draw a text field, center the text and make the field with +- the same with of the image. Then , on the Image Loader draw a rectangle with the same area than the blue part of the polaroid image, something like this:</p>
<div style="width: 740px; text-align: center;"><span style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057" src="https://www.thetechlabs.com/wp-content/uploads/2010/11/3.jpg" alt="1" width="451" height="217" /></span></div>
<p>Now Right Click on it, and convert it into a movieClip Symbol&#8230; name this instance img. Name the text Field instance to &#8220;lbl&#8221; and now just create another rectangle with the same area of the one in black but do draw it on the Mask layer.</p>
<p>Now, just mask that layer: Right Click-&gt; Mask.</p>
<p>Our Thumbnail loader is created and ready to load our picture.</p>
<p>&nbsp;</p>
<h2><strong>Step 4 &#8211; Make changes on the trigger command</strong></h2>
<p>Go to our main stage, on the first frame actions and open actions panel. On this panel we need to make some changes to our movie.</p>
<p>The first thing to have in mind is that we will load our movieclip with all the thumbnails distributed over the screen area, and we will also have a button to play a slide show with those pictures. This is already made, so we need only to create a button to load the slide show, and on the very first start it will be stopped. So, for that we will add a variable called SLIDE_ON to control the slide state. Just add this on the top of the script declarations:</p>
<pre>var SLIDE_ON:Boolean=false;

var THUMBS_HIDDEN=false;</pre>
<p>The we need to avoid slid to start, just go to the function onXmlComplete() and replace this:</p>
<pre>onTime(new TimerEvent(TimerEvent.TIMER)); //load first;</pre>
<p>with this:</p>
<pre>if(SLIDE_ON) onTime(new TimerEvent(TimerEvent.TIMER)); //load first;</pre>
<p>This will stop slide from loading, but the lines and the loader will appear, we just want them to disappear, for that just do this function:</p>
<p>&nbsp;</p>
<h2><strong>Step 5 &#8211; Code a function to hide/stop the slide</strong></h2>
<pre> function hideSlide():void {
	LT.alpha=0;
	LB.alpha=0;
	preloader.alpha=0;
}</pre>
<p>and call it on the onXmlComplete function on the else instruction, making it appear like this:</p>
<pre>function onXmlComplete(evt:Event):void {
 IMAGES = xml2Array(evt.target.data); //load images into array
 if(SLIDE_ON) onTime(new TimerEvent(TimerEvent.TIMER)); //load first;
 else hideSlide();
 }</pre>
<p>&nbsp;</p>
<h2 style="text-align: left;"><strong>Step 6 &#8211; Create a button to switch between slide/thumbnails presentation</strong></h2>
<p>Now the slide is ready to load our pictures into the thumbs and spread the randomly overt the screen, but first lets create a start/stop slide button. Grab this archive and extract those two pictures some place, then in flash create a new MovieClip name it slideControl and the import those two extracted images to stage: File-&gt; Import -&gt; Import to stage. Create two frames and on the first frame put the &#8220;screen&#8221; image and on the second one the &#8220;folder/thumbs&#8221; image. Make sure they are placed on the exactly same position: x=0 and y=0. On the first layer actions write down</p>
<pre>stop();</pre>
<p>Now, just go back to stage, double click on the galControls movieClip and then just drop from the library our recently created slideControl movie clip. Put it on the left aligned with the existing ones.</p>
<div style="width: 740px; text-align: center;"><span style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignright" src="https://www.thetechlabs.com/wp-content/uploads/2010/11/4.jpg" alt="1" width="139" height="48" /></span></div>
<p>Name it&#8217;s instance as btnSlide and go back to main stage. The in the actions write this down on bottom of the existing code:</p>
<p>&nbsp;</p>
<h2><strong>Step 7 &#8211; Code the slide switch button actions</strong></h2>
<pre>galControls.btnSlide.buttonMode=true;
galControls.btnSlide.useHandCursor=true;
galControls.btnSlide.addEventListener(MouseEvent.CLICK, switchSlide);</pre>
<p>After this we will need to create this switchSlide function but not for now&#8230;</p>
<p>&nbsp;</p>
<h2><strong>Step 8 &#8211; Creating the thumb loader function</strong></h2>
<p>Now, we need to create a function to load all our thumbnails and spread them over the screen, just create these functions:</p>
<pre>		var thumb:polaroidMC;
      var thumbLoader:Loader;function loadThumbs():void {
      //let's define stage container size to distribute thumbs
     for(var h:int=0; h&lt;IMAGES.length; h++) {

      thumb=new polaroidMC();
      thumb.lbl.text=IMAGES[h].imageName;
      thumb.x=-70;
      thumb.y=stage.stageHeight+100;
      thumb.name="thumb-"+IMAGES[h].imageName;
      thumb.id=IMAGES[h].imageName; thumbLoader=new Loader();
      thumbLoader.x=0;
      thumbLoader.y=0;

      thumb.img.addChild(thumbLoader);

      thumbLoader.name="loader-"+h;

      addChild(thumb);

      thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onThumbDone);
      var link:String=HOST+IMAGES[h].imageThumb;
      thumbLoader.load(new URLRequest(link));

      loadEvents(thumb, true);

      /*****************************************************/
      //var tmb:polaroidMC = (evt.target as polaroidMC);
      var max_x:Number=stage.stageWidth-70;
      var max_y:Number=stage.stageHeight-70;
      var min_x=0;
      var min_y=0; var rndX:Number=Math.ceil(Math.random() * (max_x - 0 + 1)) + (0 - 1);
      var rndY:Number=Math.ceil(Math.random() * (max_y - 0 + 1)) + (0 - 1);
   var rot:Number=Math.ceil(Math.random() * (45 - 0 + 1)) + (0 - 1)
      thumb.rotation=rot;

      TweenLite.to(thumb,1,{x:rndX, y:rndY});

      }
      }</pre>
<p>This function will load all thumbs as polaroidMC&#8217;s, and add them a Loader as child to load the thumbnail image.</p>
<p>&nbsp;</p>
<h2><strong>Step 9 &#8211; The thumb load complete event</strong></h2>
<p>When the thumb image is finished downloading, just open it and spread it over the screen:</p>
<pre>function onThumbDone(evt:Event):void {
   var tmb:polaroidMC = (evt.target as polaroidMC);
   var max_x:Number=stage.stageWidth;
   var max_y:Number=stage.stageHeight;
   var min_x=0;
   var min_y=0;
	 var rndX:Number=Math.ceil(Math.random() * (max_x - 0 + 1)) + (0 - 1);
   var rndY:Number=Math.ceil(Math.random() * (max_y - 0 + 1)) + (0 - 1);

 	TweenLite.to(tmb,1,{x:rndX, y:rndY});
   }</pre>
<p>&nbsp;</p>
<h2><strong>Step 10 &#8211; Thumb Mouse Interaction Switcher</strong></h2>
<p>It calls also a function to load the events on it. It will act as a switcher allowing to load/unload these properties on each polaroidMC:</p>
<pre>function loadEvents(mc:polaroidMC, opt:Boolean):void {
 if(opt==true) {
 mc.buttonMode=true;
 mc.useHandCursor=true;
 mc.addEventListener(MouseEvent.MOUSE_OVER, onThumbOver);
 mc.addEventListener(MouseEvent.MOUSE_OUT, onThumbOut);
 mc.addEventListener(MouseEvent.CLICK, onThumbClick);
 }
 else {
 mc.buttonMode=false;
 mc.useHandCursor=false;
 mc.removeEventListener(MouseEvent.MOUSE_OVER, onThumbOver);
 mc.removeEventListener(MouseEvent.MOUSE_OUT, onThumbOut);
 mc.removeEventListener(MouseEvent.CLICK, onThumbClick);
 }
 }</pre>
<p>&nbsp;</p>
<h2><strong>Step 11 &#8211; The thumb event handlers</strong></h2>
<p>Now we need to create the events for the thumbs, just add some fade in/out effects and call the image to open when thumb is clicked:</p>
<pre>function onThumbOver(evt:MouseEvent):void {
   (evt.currentTarget as polaroidMC).alpha=0.75;
   }
   function onThumbOut(evt:MouseEvent):void {
   (evt.currentTarget as polaroidMC).alpha=1;
   }</pre>
<p>When a user click on the thumb we will hide all the existing thumbs and make the animation to load the selected image:</p>
<pre>function onThumbClick(evt:MouseEvent):void {
   hideThumbs(loadImage, HOST+"/"+(evt.currentTarget as polaroidMC).id);
   ldr.addEventListener(MouseEvent.CLICK, onLDRClick);
   }</pre>
<p>&nbsp;</p>
<h2><strong>Step 12 &#8211; The hide thumbs function</strong></h2>
<p>For hide the thumbs we will code this that will search for all the stage child this the thumb name and hide them:</p>
<pre>function hideThumbs(onComplete:Function=null, arg:String=null):void {
   for(var g:int=0; g&lt;numChildren; g++) {
 if(getChildAt(g).name.toString().indexOf("thumb-")&gt;-1)  {
 TweenLite.to(getChildAt(g),1,{alpha:0, onComplete:hiden, onCompleteParams:[getChildAt(g)] });
 loadEvents((getChildAt(g) as polaroidMC), false);
 }
 }
 THUMBS_HIDDEN=true;
 if(onComplete!=null &amp;&amp; arg!=null) onComplete(arg);
 else if(onComplete!=null) onComplete();
 }</pre>
<p>This function is a little special, it will receive as argument a new function and it&#8217;s function arguments, meaning the is possible to call any specific function that we can input to act as a onComplete function, this is very useful cause after all the thumbs are hidden we need to open the selected image.</p>
<p>The function acts like this:</p>
<p>Find all the stage children&#8217;s that have on it&#8217;s name the &#8220;thumb&#8221; word, then Tween them alpha=0; then call the function loadEvents() that will unload the thumb mouse interaction and on the end of this tween call the function provided by the function arguments.</p>
<pre>function hiden(mc:polaroidMC):void {
   mc.visible=false;
   }</pre>
<p>We need this function also to make visible=false all the thumbs because if they have only the alpha=0; they will still clickable and we do not want this.</p>
<p>&nbsp;</p>
<h2><strong>Step 13 &#8211; The show thumbs function</strong></h2>
<p>We need also to create a function to show our thumbs again when the loader is licked and the displayed picture closed, write this down:</p>
<pre>function showThumbs():void {
 trace("showing thumbs");
 for(var g:int=0; g&lt;numChildren; g++) {
 if(getChildAt(g).name.toString().indexOf("thumb-")&gt;-1 &amp;&amp; getChildAt(g).visible==false )  {
 TweenLite.to(getChildAt(g),1,{alpha:1});
 getChildAt(g).visible=true;
 loadEvents((getChildAt(g) as polaroidMC), true);
 }
 }
 THUMBS_HIDDEN=false;
 }</pre>
<p>&nbsp;</p>
<h2><strong>Step 14 &#8211; The loader click handler</strong></h2>
<p>This is the listener of loader clicks (when user click on the main photo loaded the image will close and the thumbs will appear again):</p>
<pre>function onLDRClick(evt:MouseEvent):void {
 resetLines();
 ldr.removeEventListener(MouseEvent.CLICK, onLDRClick);
 preloader.visible=false;
 LT.alpha=0;
 LB.alpha=0;
 IMAGE_LOADED=false;
  }</pre>
<p>&nbsp;</p>
<h2><strong>Step 15 &#8211; The slide Switcher</strong></h2>
<p>Well it&#8217;s almost done, just need to create a function to switch to slide mode:</p>
<pre>function switchSlide(evt:MouseEvent=null):void {
 if(SLIDE_ON==false) {
 hideThumbs();
 SLIDE_ON=true;
 LT.visible=true;
 LB.visible=true;
 preloader.visible=true;
 LT.alpha=1;
 LB.alpha=1;
 preloader.alpha=1;

 timex.start();
 galControls.btnSlide.gotoAndStop(2);
 }
 else {
 SLIDE_ON=false;
 timex.stop();
 resetLines();
 LT.alpha=0;
 LB.alpha=0;
 preloader.alpha=0;
 preloader.visible=false;
 //preloader.alpha=0;
 galControls.btnSlide.gotoAndStop(1);</pre>
<pre> }
   }</pre>
<pre>function swapThumbs(evt:MouseEvent):void {
 if(THUMBS_HIDDEN==true) showThumbs();
 else hideThumbs();
 }</pre>
<p>&nbsp;</p>
<h2><strong>Step 16 &#8211; Replacing thumbs on screen resize</strong></h2>
<p>And it&#8217;s almost done, just need to create a function to reload all the thumbs into new screen positions when the user switch&#8217;s to full screen. Write this function down:</p>
<pre>function reloadPos():void {
 for(var g:int=0; g&lt;numChildren; g++) {
 if(getChildAt(g).name.toString().indexOf("thumb-")&gt;-1)  {
 getChildAt(g).x=stage.stageWidth+150;
 getChildAt(g).y=stage.stageHeight+150;

 var max_x:Number=stage.stageWidth-70;
 var max_y:Number=stage.stageHeight-70;
 var min_x=0;
 var min_y=0;</pre>
<pre> var rndX:Number=Math.ceil(Math.random() * (max_x - 0 + 1)) + (0 - 1);
   var rndY:Number=Math.ceil(Math.random() * (max_y - 0 + 1)) + (0 - 1);</pre>
<pre>   var rot:Number=Math.ceil(Math.random() * (45 - 0 + 1)) + (0 - 1)
   getChildAt(g).alpha=1;
   if(IMAGE_LOADED==false) getChildAt(g).visible=true;

   getChildAt(g).rotation=rot;

   TweenLite.to(getChildAt(g),1,{x:rndX, y:rndY});

   loadEvents((getChildAt(g) as polaroidMC), true);
   }
   }
   }</pre>
<p>A function to reload thumbs position, this will be called on screen resize.</p>
<pre>function replaceThumbs():void {
   hideThumbs(reloadPos);
   }</pre>
<p>&nbsp;</p>
<h2><strong>Step 17 &#8211; Updating the code</strong></h2>
<p>Now just need to make some minor changes to the part I tutorial code;</p>
<p>On the onXmlComplete() function write on bottom:</p>
<pre>loadThumbs();</pre>
<p>then on function resetLines() replace the bottom line :</p>
<pre> else TweenLite.to(preloader, 1, {alpha:1});</pre>
<p>with this one:</p>
<pre> else TweenLite.to(preloader, 1, {alpha:1, onComplete:showThumbs});</pre>
<p>On the reloadLines() function, write on bottom:</p>
<pre> if(SLIDE_ON==false) replaceThumbs();</pre>
<p>On the animateToImage() function just replace the</p>
<pre>timex.start()</pre>
<p>with</p>
<pre>if(SLIDE_ON==true) timex.start();</pre>
<p>And finally on the onImageComplete() function, find the lines:</p>
<pre>if(FIRST_RUN==true) { //if is the first run
 timex.start(); //if it's first run, activate the timer to load next images.
 FIRST_RUN=false; //now it's not the first run
 }</pre>
<p>And replace them with</p>
<pre>if(FIRST_RUN==true) { //if is the first run
   if(SLIDE_ON==true) timex.start(); //if it's first run, activate the timer to load next images.
   FIRST_RUN=false; //now it's not the first run
   }</pre>
<p>This will avoid loading slideshow on first movie run.</p>
<p>Well, that&#8217;s all&#8230; save your project and run it! Nice ha?</p>
<p>So, I hope you liked this tutorial! Don&#8217;t forget to comment, subscribe to our RSS feed and follow us on Twitter. If you have any doubts, just sign up on our <a title="TheTechLabs Forum" href="https://www.thetechlabs.com/forum/" target="_blank">forum</a> and ask for help.</p><p>The post <a href="https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/">Create an intelligent XML image Gallery & Slideshow in Flash CS4 (+PHP) – Part II/II</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Getting Started With BetweenAS3</title>
		<link>https://www.thetechlabs.com/tech-tutorials/flash/getting-started-with-betweenas3/</link>
					<comments>https://www.thetechlabs.com/tech-tutorials/flash/getting-started-with-betweenas3/#comments</comments>
		
		<dc:creator><![CDATA[Devon]]></dc:creator>
		<pubDate>Tue, 21 Jul 2009 12:00:44 +0000</pubDate>
				<category><![CDATA[Effects]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Latest]]></category>
		<category><![CDATA[Tech Tutorials]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[betweeas3]]></category>
		<guid isPermaLink="false">https://www.thetechlabs.com/?p=1458</guid>

					<description><![CDATA[<p>There are many popular open source tweening engines in the Flash community today. Numbered among these are Tweener, TweenLite/Tweenmax, Tweensy, and GTween. This is a short look at the capabilities of newcomer to the scene: BetweenAS3. BetweenAS3 is the tweening engine brainchild of Yoshihiro (yossy) Shindo and is available as part of the Spark project (i.e. it is brought to us by one of the same group that brought the world the FLARToolkit for Augmented Reality in Flash and countless other goodies).</p>
<p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/getting-started-with-betweenas3/">Getting Started With BetweenAS3</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">There are many popular open source tweening engines in the Flash community today. Numbered among these are Tweener, TweenLite/Tweenmax, Tweensy, and GTween. This is a short look at the capabilities of newcomer to the scene: BetweenAS3. BetweenAS3 is the tweening engine brainchild of Yoshihiro (yossy) Shindo and is available as part of the Spark project (i.e. it is brought to us by one of the same group that brought the world the FLARToolkit for Augmented Reality in Flash and countless other goodies).</p>
<h2>Requirements</h2>
<p style="text-align: justify;">To go through the code examples presented here, you will, of course, need the BetweenAS3 library added to your class path. The library can be downloaded from the .svn depository <a href="http://www.libspark.org/svn/as3/BetweenAS3/trunk/" target="_blank">here</a>. You&#8217;ll notice that there are two branches to the library &#8211; one for Flash Player 9 and one for Flash Player 10. Although the syntax for the two branches is the same, I&#8217;ve used the Flash Player 10 branch for the examples here. I&#8217;ve also written the examples here as a pure Actionscript project, so something that can compile actionscript projects, such as FlashBuilder/Flexbuilder or FlashDevelop plus the Flex SDK is also required. Flash CS4 can also be used if each example class is used as a .fla document class. The included download contains all actionscript files plus the FlashDevelopment project file.</p>
<p style="text-align: center;"><a href="https://www.thetechlabs.com/wp-content/uploads/2009/07/downloads.zip"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-466" style="border: 0pt none;" title="Download Source Files" src="https://www.thetechlabs.com/wp-content/uploads/2009/04/sourcefiles.jpg" alt="Download Source Files" width="246" height="93" /></a></p>
<h2>Pre-Requisites</h2>
<p style="text-align: justify;">As the name BetweenAS3 implies, all code presented will be in Actionscript 3. While it would be helpful (and is assumed) that the reader has at least a basic working knowledge of Actionscript 3, this isn&#8217;t 100% necessary.</p>
<h2>Basic Syntax and Functionality</h2>
<p style="text-align: justify;">Primarily, BetweenAS3 relies on several static method calls. Each of these static methods will return an instance of an ITween interface. Because of this, BetweenAS3 offers a great deal of flexibility as each of these static methods may nest any number of additional methods thereby building extremely complex tweens from relatively simple syntax.</p>
<p style="text-align: justify;">In its most simple form, a basic BetweenAS3 tween may look like this:</p>
<pre style="text-align: justify;">var tween:ITween = BetweenAS3.tween(targetObject, toObject, fromObject, time, easingMethod);</pre>
<p style="text-align: justify;">Once created, the tween can be started using the play() method, stopped using the stop() method or controlled with the Movieclip like methods gotoAndPlay(time) or gotoAndStop(time). You can determine the length of the tween in seconds with the duration property, the current time of the tween with the position property and can determine whether or not the tween is playing at any given moment with the aptly named isPlaying property.</p>
<p style="text-align: justify;">Like all good tweening engines, with BetweenAS3 you are able to trigger actionscript methods when the tween starts, stops, updates or completes. Unlike most tweening engines, though, BetweenAS3 offers two ways of doing this. You can either use the standard AS3 event model and listen for a BetweenEvent, or you can use a more AS2 style approach and add callback methods to the tween instance. For example, say you wanted to call the method named tweenDone when a tween completes. You could say:</p>
<pre>tween.addEventListener(BetweenEvent.COMPLETE, tweenDone);

private function tweenDone(event:BetweenEvent):void {
	// the tween is complete
}</pre>
<p style="text-align: justify;">Or, instead, you could say:</p>
<pre>tween.onComplete = tweenDone;

private function tweenDone():void {
	// the tween is complete
}</pre>
<p style="text-align: justify;">Using this latter approach, it is also possible to pass parameters to the callback method by passing an array of parameters to the tween instance&#8217;s onCompleteParams property like so:</p>
<pre>tween.onComplete = tweenDone;
tween.onCompleteParams = ["hello", 3];

private function tweenDone(param1:String, param2:int):void {
	trace(param1, param2);
}</pre>
<p style="text-align: justify;">Now that we are armed with some basic knowledge of how BetweenAS3 operates, let&#8217;s take a look at some specific examples of this powerful tweening engine in action.</p>
<h2>The Basic Tween</h2>
<p style="text-align: justify;">Before diving straight into examples, let&#8217;s first create a couple simple class files that we can reuse throughout this tutorial. The first thing we&#8217;ll want is a target to tween. For this we&#8217;ll simply extend the Sprite object and use its graphics property to draw a small grey square. This then is our TweenTarget class:</p>
<pre>package  {

	import flash.display.Sprite;

	/**
	 * Simple DisplayObject to demonstrate BetweenAS3
	 */
	public class TweenTarget extends Sprite {

		public function TweenTarget() {
			graphics.beginFill(0x999999);
			graphics.drawRect(0, 0, 25, 25);
			graphics.endFill();
		}
	}
}</pre>
<p style="text-align: justify;">The second bit of code we&#8217;ll want to get out of the way is a template that we can use with each example. This class will just create an of a textfield (that simply says to click to start or stop the tween), and a tween instance class property. It will also contain a toggleTween method that, using the methods mentioned above, will allow our ITween instance to start or stop by clicking the stage. Once our template is made, the only things that will change from example to example are the name of the class (unless you&#8217;d like to overwrite each example), the initTween method which creates our class property tween instance, perhaps the easing method imports, and possibly a few other small details. The general template, then will look like this:</p>
<pre>package  {

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Expo;
	import org.libspark.betweenas3.tweens.ITween;

	[SWF(width='540', height='200', backgroundColor='#000000', frameRate='60')]
	public class TweenExample extends Sprite {

		private var _tween:ITween;
		private var _tf:TextField;

		public function TweenExample() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(event:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);

			initText();
			initTween();

			stage.addEventListener(MouseEvent.CLICK, toggleTween);
		}

		private function initText():void {
			var fmt:TextFormat = new TextFormat("_sans", 12, 0xFFFFFF);
			_tf = new TextField();
			_tf.selectable = false;
			_tf.mouseEnabled = false;
			_tf.autoSize = TextFieldAutoSize.LEFT;
			_tf.defaultTextFormat = fmt;
			_tf.text = "Click to start/stop tween.";
			_tf.x = Math.round(stage.stageWidth * .5 - _tf.width * .5);
			_tf.y = Math.round(stage.stageHeight - _tf.height - 10);
			addChild(_tf);
		}

		private function initTween():void {
			// will change from example to example
		}

		private function toggleTween(event:MouseEvent):void {
			// if the tween is playing, stop it
			if (_tween.isPlaying) {
				_tween.stop();
			} else {
				// otherwise if the tween is at the end, start it over
				if (_tween.position == _tween.duration) {
					_tween.gotoAndPlay(0);
				// if it's not at the end, simply play the tween
				} else {
					_tween.play();
				}
			}
		}
	}
}</pre>
<p style="text-align: justify;">Now that we are armed with these basic items, let&#8217;s roll up our sleeves and dig into a concrete example of BetweenAS3 in action. As mentioned earlier, the syntax for creating a basic tween looks like this:</p>
<pre>_tween = BetweenAS3.tween(target, toObject, fromObject, time, easing);</pre>
<p style="text-align: justify;">In more detail, the target is the obejct whose property or properties we wish to tween, the toObject is an object containing properties and their corresponding ending values. Likewise, the fromObject is an object containing the same properties as the toObject, but with their beginning value. Time is the duration of the tween in seconds, and easing is an IEasing interface instance which we can get from the org.libspark.betweenas3.easing package. In our initTween method, then, let&#8217;s create a TweenTarget instance, add it to the display list and use it as the target of our tween instance. So initTween becomes:</p>
<pre>private function initTween():void {
	var targ:TweenTarget = new TweenTarget();
	targ.x = 20;
	targ.y = 60;
	addChild(targ);
	_tween = BetweenAS3.tween(targ, { x:500 }, null, 2.0, Expo.easeOut);
}</pre>
<p style="text-align: justify;">Notice that we passed a null in place of a fromObject. By doing so, we are telling BetweenAS3 to use the tween target&#8217;s current properties. We already created the toggleTween method which will play the tween when you click the stage, so go ahead and compile the .swf. You should get something like the example below:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/basictween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="basictween" /><param name="name" value="basictween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/basictween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<h2>Delaying a Tween</h2>
<p style="text-align: justify;">As mentioned, complex tweens can be built with BetweenAS3 by nesting various static methods of the class. So far we have looked at only one of those methods, tween. Let&#8217;s look at another, now, delay. Like the tween method, delay returns an instance of an ITween interface. The delay method syntax looks like this:</p>
<pre>var tween:ITween = BetweenAS3.delay(ITweenToDelay, delayTime, postDelayTime);</pre>
<p style="text-align: justify;">Here, the ITweenToDelay is a tween instance we wish to delay, the delay time is how many seconds the tween should be delayed before the tween starts and the postDelayTime is how many seconds the tween should be delayed before the next tween starts. The postDelayTime defaults to 0.0 and, in this example, we will leave it so.</p>
<p style="text-align: justify;">So, let&#8217;s go back to our TweenExample template and change the initTween method to look like this:</p>
<pre>private function initTween():void {
	var targ:TweenTarget = new TweenTarget();
	targ.x = 20;
	targ.y = 60;
	addChild(targ);
	var t:ITween = BetweenAS3.tween(targ, { x:500 }, null, 2.0, Expo.easeOut);
	_tween = BetweenAS3.delay(t, 1.0);
}</pre>
<p style="text-align: justify;">Now, when we compile our example, we see that when we click on the stage, there is a one second delay before the tween target tweens its way across the stage like below.</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/delaytween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="delaytween" /><param name="name" value="delaytween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/delaytween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<h2>Parallel and Serial Tweens</h2>
<p style="text-align: justify;">The next static methods of the BetweenAS3 class we&#8217;ll consider are parallel and serial. The parallel method lets you run any number of tween instances at the same time. Similarly, the serial method allows you to run any number of tween instances in a row (one after another). Syntactically, both methods are identical, you simply pass any number of ITween instances as parameters.</p>
<p style="text-align: justify;">For our parallel example, let&#8217;s change our initTween method to look like this:</p>
<pre>private function initTween():void {
	var targ1:TweenTarget = new TweenTarget();
	targ1.x = 20;
	targ1.y = 25;
	addChild(targ1);

	var targ2:TweenTarget = new TweenTarget();
	targ2.x = 20;
	targ2.y = 60;
	addChild(targ2);

	var t1:ITween = BetweenAS3.tween(targ1, { x:500 }, null, 2.0, Expo.easeOut);
	var t2:ITween = BetweenAS3.tween(targ2, { x:500 }, null, 2.0, Expo.easeOut);
	_tween = BetweenAS3.parallel(t1, t2);
}</pre>
<p style="text-align: justify;">Once compiled, that will look like this:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/paralleltween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="paralleltween" /><param name="name" value="paralleltween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/paralleltween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<p style="text-align: justify;">And for our serial example, try this for the initTween method:</p>
<pre>private function initTween():void {
	var targ1:TweenTarget = new TweenTarget();
	targ1.x = 20;
	targ1.y = 25;
	addChild(targ1);

	var targ2:TweenTarget = new TweenTarget();
	targ2.x = 20;
	targ2.y = 60;
	addChild(targ2);

	var t1:ITween = BetweenAS3.tween(targ1, { x:500 }, null, 2.0, Elastic.easeOut);
	var t2:ITween = BetweenAS3.tween(targ2, { x:500 }, null, 2.0, Elastic.easeOut);
	_tween = BetweenAS3.serial(t1, t2);
}</pre>
<p style="text-align: justify;">Note that we&#8217;ve tried a different easing method here which means a different easing method will need to be imported from the org.libspark.betweenas3.easing package before compiling. Once compiled, though, you&#8217;ll see something like this:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/serialtween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="serialtween" /><param name="name" value="serialtween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/serialtween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<p style="text-align: justify;">At this point it should start to be obvious what was meant when it was stated that very complex tweens could be built up by nesting simpler tweens. For example, you could easily pass two parallel tweens and a delayed tween to the BetweenAS3 serial method and so on.</p>
<h2>Reversing and Repeating Tweens</h2>
<p style="text-align: justify;">The next two static methods we&#8217;ll look at are reverse and repeat. The reverse method, as its name suggests, reverses a tween and takes two parameters, the tween to reverse and a boolean indicating whether or not to reverse the tween&#8217;s position. Most often you would simply leave this boolean set to its default state of true. The repeat method, true to it&#8217;s name, repeats a specified tween. Repeat accepts two arguments: the tween instance to repeat and the number of times it should repeat.</p>
<p style="text-align: justify;">This time our initTween method will be a little bit trickier and we&#8217;ll really start to see the power of nesting BetweenAS3 calls. We&#8217;ll begin by creating a basic tween that moves our TweenTarget instance across the stage with a nice elasticity. Nothing new there. Then, though, we&#8217;ll create a repeated tween that repeats four times. That repeated tween will be passed an instance of a serial tween that tweens first the basic tween then the reverse of the basic tween. Our initTween method then will look like this:</p>
<pre>private function initTween():void {
	var targ1:TweenTarget = new TweenTarget();
	targ1.x = 20;
	targ1.y = 60;
	addChild(targ1);
	var t1:ITween = BetweenAS3.tween(targ1, { x:500 }, { x:targ1.x }, 2.0, Elastic.easeInOut);
	_tween = BetweenAS3.repeat(BetweenAS3.serial(t1, BetweenAS3.reverse(t1)), 4);
}</pre>
<p style="text-align: justify;">Compiled, you should get a result such as this:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/reversetween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="reversetween" /><param name="name" value="reversetween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/reversetween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<h2>Adding and Removing Children</h2>
<p style="text-align: justify;">One of the interesting benefits of using BetweenAS3 is the ability to add and remove child display objects as a tween using the static methods addChild and removeFromParent respectively. The addChild method expects two arguments: the child to add and the parent the child should be added to. The removeFromParent accepts only a single argument, the child to remove. Both of these methods, again, return ITween instances and can be nested into other BetweenAS3 methods to build up complex tween sequences.</p>
<p style="text-align: justify;">In this example, we&#8217;ll instantiate three TweenTarget instances, use the BetweenAS3.addChild method to add them to the display list with a .5 second delay, tween them all across the stage in parallel, then use the removeFromParent method to get remove them from the display list. This time our initTween method looks like this:</p>
<pre>private function initTween():void {
	var targ1:TweenTarget = new TweenTarget();
	targ1.x = 20;
	targ1.y = 25;

	var targ2:TweenTarget = new TweenTarget();
	targ2.x = 20;
	targ2.y = 60;

	var targ3:TweenTarget = new TweenTarget();
	targ3.x = 20;
	targ3.y = 95;

	var t1:ITween = BetweenAS3.delay(BetweenAS3.addChild(targ1, this), .5);
	var t2:ITween = BetweenAS3.delay(BetweenAS3.addChild(targ2, this), .5);
	var t3:ITween = BetweenAS3.delay(BetweenAS3.addChild(targ3, this), .5, .5);
	var t4:ITween = BetweenAS3.tween(targ1, { x:500 }, null, 2.0, Elastic.easeOut);
	var t5:ITween = BetweenAS3.tween(targ2, { x:500 }, null, 2.0, Elastic.easeIn);
	var t6:ITween = BetweenAS3.tween(targ3, { x:500 }, null, 2.0, Elastic.easeInOut);
	var t7:ITween = BetweenAS3.parallel(t4, t5, t6);
	var t8:ITween = BetweenAS3.delay(BetweenAS3.removeFromParent(targ1), .5);
	var t9:ITween = BetweenAS3.delay(BetweenAS3.removeFromParent(targ2), .5);
	var t10:ITween = BetweenAS3.delay(BetweenAS3.removeFromParent(targ3), .5);

	_tween = BetweenAS3.serial(t1, t2, t3, t7, t8, t9, t10);
}</pre>
<p style="text-align: justify;">Note that for the sake of legibility, I created several single ITween instances, but if you really wanted to, you could actually create the _tween instance in a single line like so:</p>
<pre>_tween = BetweenAS3.serial(BetweenAS3.delay(BetweenAS3.addChild(targ1, this), .5), BetweenAS3.delay(BetweenAS3.addChild(targ2, this), .5), BetweenAS3.delay(BetweenAS3.addChild(targ3, this), .5, .5), BetweenAS3.parallel(BetweenAS3.tween(targ1, { x:500 }, null, 2.0, Elastic.easeOut), BetweenAS3.tween(targ2, { x:500 }, null, 2.0, Elastic.easeIn), BetweenAS3.tween(targ3, { x:500 }, null, 2.0, Elastic.easeInOut)), BetweenAS3.delay(BetweenAS3.removeFromParent(targ1), .5), BetweenAS3.delay(BetweenAS3.removeFromParent(targ2), .5), BetweenAS3.delay(BetweenAS3.removeFromParent(targ3), .5));</pre>
<p style="text-align: justify;">Such is the power of nesting tween methods in BetweenAS3.</p>
<p style="text-align: justify;">Whichever method you choose to create your tween instance, the compiled .swf will look like the example below:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/addchildtween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="addchildtween" /><param name="name" value="addchildtween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/addchildtween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<h2>Color Tweening</h2>
<p style="text-align: justify;">In addition to nesting ITween instances it is also possible with BetweenAS3 to nest property objects to build complex tweens. In this example we&#8217;ll take a look at how to tween the properties of the colorTransform property of the transform property of the TweenTarget instance. This time in our initTween method, we&#8217;ll enlarge our TweenTarget instance, then tween its color. Our initTween method will look like this:</p>
<pre>private function initTween():void {
	var targ:TweenTarget = new TweenTarget();
	targ.x = 235;
	targ.y = 40;
	targ.scaleX = 3;
	targ.scaleY = 3;
	addChild(targ);
	_tween = BetweenAS3.tween(targ, { transform:{colorTransform:{ redOffset:-255, greenOffset:-255, blueOffset:255 }} }, null, 4.0, Expo.easeOut);
}</pre>
<p style="text-align: justify;">Compiled, you should see something like the below:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/colortween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="colortween" /><param name="name" value="colortween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/colortween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<h2>Filter Tweening</h2>
<p style="text-align: justify;">Again, by nesting property objects, BetweenAS3 can also be used to tween DisplayObject filters. In this quick example, we&#8217;ll take a look at tweening a glow filter back and forth. Before we begin though, there is one other property of the ITween interface to take a look at: the stopOnComplete property. This property is a boolean that tells the tween to stop when it is finished. If set to false, as it will be in this example, the tween will run indefinitely starting at it&#8217;s beginning each time it completes. In this example, we&#8217;ll again enlarge our TweenTarget instance, add a GlowFilter object to its filters property, then, finally tween that filter. Our initTween method will look like this:</p>
<pre>private function initTween():void {
	var targ:TweenTarget = new TweenTarget();
	targ.x = 235;
	targ.y = 40;
	targ.scaleX = 3;
	targ.scaleY = 3;
	addChild(targ);
	targ.filters = [new GlowFilter(0xFFFF00, 1, 0, 0, 2, 3)];
	var t1:ITween = BetweenAS3.tween(targ, { _glowFilter: { blurX:32, blurY:32 } }, { _glowFilter: { blurX:0, blurY:0 }},  1.0, Expo.easeOut);
	_tween = BetweenAS3.serial(t1, BetweenAS3.reverse(t1));
	_tween.stopOnComplete = false;
}</pre>
<p style="text-align: justify;">Compiled our glow filter example will look like this:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/filtertween.swf" type="application/x-shockwave-flash" width="540" height="200"><param name="quality" value="high" /><param name="id" value="filtertween" /><param name="name" value="filtertween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/filtertween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<p style="text-align: justify;">In case you&#8217;re wondering where that &#8220;_glowFilter&#8221; property came from, BetweenAS3 will, by default, recognize the following filter properties: &#8220;_bevelFilter&#8221;, &#8220;_blurFilter&#8221;, &#8220;_colorMatrixFilter&#8221;, &#8220;_convolutionFilter&#8221;, &#8220;_displacementMapFilter&#8221;, &#8220;_dropShadowFilter&#8221;, &#8220;_glowFilter&#8221;, &#8220;_gradientBevelFilter&#8221;, &#8220;_gradientGlowFilter&#8221;, and &#8220;_shaderFilter&#8221;.</p>
<h2>Tweening Array Members</h2>
<p style="text-align: justify;">Possibly one of my favorite features of BetweenAS3 is its ability to tween the members of Array instances just like they were properties of an object (which, when you think about it, they are). Why would you want to tween array members, you ask. Well, one possible example is that you want to tween an image from &#8220;normal&#8221; to &#8220;embossed&#8221; and back again. You can easily emboss an image using a ConvolutionFilter, but to tween the transition will require tweening an array.</p>
<p style="text-align: justify;">If you&#8217;re not familiar with the ConvolutionFilter object, you create one using a matrix array. Creating a ConvolutionFilter with an array like this (0,0,0,0,1,0,0,0,0), will not affect the image to which it&#8217;s applied. Using an array like this however, (-2,-1,0,-1,1,1,0,1,2), will emboss the image.</p>
<p style="text-align: justify;">So, in this example, we will embed an image, create a tween that tweens the members of the array that change and then tweens them back, and add an event listener to that tween so as the tween updates, a ConvolutionFilter has its matrix property updated then the filter is applied to our image.</p>
<p style="text-align: justify;">Because this script is so completely different from all the others, I will present it in its entirety below:</p>
<pre>package  {

	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.ConvolutionFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	import org.libspark.betweenas3.BetweenAS3;
	import org.libspark.betweenas3.easing.Quad;
	import org.libspark.betweenas3.events.BetweenEvent;
	import org.libspark.betweenas3.tweens.ITween;

	[SWF(width='540', height='450', backgroundColor='#000000', frameRate='60')]
	public class MatrixTween extends Sprite {

		[Embed(source = "../assets/prague.jpg")]
		private var JPG:Class;

		private var _image:Sprite;
		private var _tween:ITween;
		private var _tf:TextField;

		private var _matrixArray:Array = [ 0, 0, 0, 0, 1, 0, 0, 0, 0];
		private var _convFilter:ConvolutionFilter = new ConvolutionFilter(3, 3, _matrixArray);

		// IDENTITY ARRAY:	(0,0,0,0,1,0,0,0,0)
		// EMBOSS ARRAY:	(-2,-1,0,-1,1,1,0,1,2);

		public function MatrixTween() {
			_image = new Sprite();
			_image.addChild(new JPG());
			addChild(_image);

			initText();
			initTween();

			stage.addEventListener(MouseEvent.CLICK, toggleTween);
		}

		private function initText():void {
			var fmt:TextFormat = new TextFormat("_sans", 12, 0xFFFFFF);
			_tf = new TextField();
			_tf.selectable = false;
			_tf.mouseEnabled = false;
			_tf.autoSize = TextFieldAutoSize.LEFT;
			_tf.defaultTextFormat = fmt;
			_tf.text = "Click to start/stop tween.";
			_tf.x = Math.round(stage.stageWidth * .5 - _tf.width * .5);
			_tf.y = Math.round(stage.stageHeight - _tf.height - 10);
			addChild(_tf);
		}

		private function initTween():void {
			var t1:ITween = BetweenAS3.tween(_matrixArray, { 0: -2, 1: -1, 3: -1, 4:1, 5:1, 7:1, 8:2 }, { 0:0, 1:0, 3:0, 4:1, 5:0, 7:0, 8:0 }, 2.0, Quad.easeInOut);
			_tween = BetweenAS3.serial(t1, BetweenAS3.reverse(t1));
			_tween.addEventListener(BetweenEvent.UPDATE, applyFilter);
		}

		private function applyFilter(event:BetweenEvent):void {
			_convFilter.matrix = _matrixArray;
			_image.filters = [_convFilter];
		}

		private function toggleTween(event:MouseEvent):void {
			if (_tween.isPlaying) {
				_tween.stop();
			} else {
				if (_tween.position == _tween.duration) {
					_tween.gotoAndPlay(0);
				} else {
					_tween.play();
				}
			}
		}
	}
}</pre>
<p style="text-align: justify;">Notice how the index numbers of the array members are used as property names. Compiling the .swf will yield the results below:</p>
<p><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/matrixtween.swf" type="application/x-shockwave-flash" width="540" height="450"><param name="quality" value="high" /><param name="id" value="matrixtween" /><param name="name" value="matrixtween" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/matrixtween.swf" /><param name="bgcolor" value="#000000" /></object></p>
<p style="text-align: justify;">In conclusion, even though still in version 0.00 (Preview) at the time of writing this, BetweenAS3 is already a powerful tween engine addition to any actionscript coder&#8217;s arsenal. As always, I always recommend using the right tool for the job and BetweenAS3 may certainly not be right for every time a tween is required, but at the cost of a measly 14k or so, it is definitely worth keeping handy. For more information regarding BetweenAS3, check out <a href="http://www.be-interactive.org/works/20090428/slide_betweenas3.html" target="_blank">this slide show</a> created by the engine&#8217;s author.</p><p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/getting-started-with-betweenas3/">Getting Started With BetweenAS3</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.thetechlabs.com/tech-tutorials/flash/getting-started-with-betweenas3/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Create an intelligent XML image Gallery &#038; Slideshow in Flash CS4 (+PHP) &#8211; Part I/II</title>
		<link>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/</link>
					<comments>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/#comments</comments>
		
		<dc:creator><![CDATA[Mario Santos]]></dc:creator>
		<pubDate>Mon, 13 Jul 2009 11:30:14 +0000</pubDate>
				<category><![CDATA[Effects]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Latest]]></category>
		<category><![CDATA[Server Side]]></category>
		<category><![CDATA[Tech Tutorials]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[Flash Catalyst]]></category>
		<category><![CDATA[Flickr]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[web-development]]></category>
		<guid isPermaLink="false">https://www.thetechlabs.com/?p=1439</guid>

					<description><![CDATA[<p>In this article you will learn how to build an image gallery that will load images from a web server. I decide to call it "Intelligent" because you don't need to configure any XML or flash file. Just put the Flash movie and the images on a server and they will be loaded automatically. Nice ah?</p>
<p>The post <a href="https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/">Create an intelligent XML image Gallery & Slideshow in Flash CS4 (+PHP) – Part I/II</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">In this article you will learn how to build an image gallery that will load images from a web server. I decide to call it &#8220;Intelligent&#8221; because you don&#8217;t need to configure any XML or flash file. Just put the Flash movie and the images on a server and they will be loaded automatically. Nice ah?</p>
<p style="text-align: justify;">So, why the XML term in title? Easy, the gallery will work also with a xml if you want to, just change two lines of code and it is working with a XML file.</p>
<p style="text-align: justify;">And the PHP? If you want the gallery to auto load and discover the photos, you will need to have two simple php files on any web/local server (php support is mandatory). One of this files will automatically discover the images in folder and create the XML with them, when this creation is done it informs flash of it&#8217;s location.</p>
<p><center><script type="text/javascript">// <![CDATA[
google_ad_client = "pub-7847584538700437"; /* 300x250, created 5/7/10 - The Tech Labs */ google_ad_slot = "0549771992"; google_ad_width = 300; google_ad_height = 250;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">// <![CDATA[

// ]]&gt;</script></center>&nbsp;</p>
<h2><strong>Final Result:</strong></h2>
<p><strong><object data="https://www.thetechlabs.com/wp-content/uploads/2009/07/gallery.swf" type="application/x-shockwave-flash" width="545" height="394"><param name="quality" value="autohigh" /><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="true" /><param name="scale" value="showall" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/gallery.swf" /></object><br />
</strong></p>
<p style="text-align: justify;">This gallery will have some cool final result features, lets take a brief look:</p>
<ul>
<li>Auto find images in folder (works with PNG,JPEG,JPG)</li>
<li>Write an XML file automatically</li>
<li>Can work only with a XML file and without php</li>
<li>Have a full screen option</li>
<li>Fit&#8217;s automatically the screen center.</li>
<li>Can customize the speed of slideshow.</li>
<li>Automatically generate thumbnails of images in folder *</li>
<li>Spread the thumbnails automatically on the screen *</li>
<li>Make the slideshow static (only open&#8217;s in thumbnail click) *</li>
<li>Can be configured without any XML (with flash vars) *</li>
</ul>
<p style="text-align: justify;">This project will be divided into two parts, on the first we will focus the first 6 topics, and on the second part the other ones.</p>
<p style="text-align: center;"><strong><a href="https://www.thetechlabs.com/wp-content/uploads/2009/07/imagegal_slideshow.zip"><img loading="lazy" decoding="async" class="size-full wp-image-466 aligncenter" style="border: 0pt none;" title="Download Source Files" src="https://www.thetechlabs.com/wp-content/uploads/2009/04/sourcefiles.jpg" alt="Download Source Files" width="246" height="93" /></a><br />
</strong></p>
<h2><strong>Requirements.</strong></h2>
<p>&nbsp;</p>
<ul style="text-align: justify;">
<li>Have Flash CS4</li>
<li>A amp server (or similar like <a href="http://www.wampserver.com/" target="_blank" rel="nofollow">wampserver</a>), any online hosting with php support works to.</li>
<li>The TweenLite engine that you can download <a href="http://blog.greensock.com/tweenliteas3/" target="_blank" rel="nofollow">here</a></li>
</ul>
<p><strong><br />
</strong></p>
<h2><strong>Pre Requirements</strong></h2>
<p>&nbsp;</p>
<ul style="text-align: justify;">
<li>Know a little of PHP</li>
<li>Understand the concept of constraint layout in flash (auto position content)</li>
<li>A good knowledge of Flash, especially Action Script 3</li>
</ul>
<p><strong><br />
</strong></p>
<h2><strong>Getting started</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">Keep in mind that this is a complex tutorial and you will need to pay some attention to details, so&#8230; if you are following this tutorial or if you got the source and have any doubts you should not ignore any step&#8230; follow them carefully.</p>
<p><strong><br />
</strong></p>
<h2><strong>Step 1 &#8211; Setting up PHP</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">Make sure you got an installed php server, go to your web server root (if local and using wamp server, something like c:/wamp/www) and create a folder called gallery, inside it create two php files named<strong> discover.php</strong> and <strong>imageHandler.php</strong> these files will handle any request from flash, discover the image files in folder, create a <strong>images.xml</strong> file and output his name to flash.</p>
<p>Write down this code on <strong>imageHandler.php</strong>:</p>
<pre>&lt;?php

  class imageHandler {
  	public function getImageList($path="") {
	  		if(file_exists($path))
	  		{
			  $i1="jpg";
			  $i2="png";
			  $i3="jpeg";
			  foreach(array_diff(scandir($path),array('.','..')) as $f) {
				  if(is_file($path.'/'.$f) &amp;&amp; (($i1)?ereg($i1.'$',$f):1) ||
					(($i2)?ereg($i2.'$',$f):1) || (($i3)?ereg($i3.'$',$f):1) ) $l[]=$f;
				 }
			  return $l;
		   }
		  else return "Path do not Exists!";
		}

		public function ary2xml($arr, $d=0, $forcetag='', $file_name='') {

		  $data="&lt;?xml version="1.0" encoding="utf-8"?&gt;rn";
		  $data.="&lt;images&gt;rn";
		  for($h=0; $h&lt;count($arr); $h++) {
			  $data.="&lt;image nameI="".$arr[$h]."" thumb="".$arr[$h]."" /&gt;rn";
		  }
		  $data.="&lt;/images&gt;";

		  if($file_name!='') {
			  @unlink($file_name);
			  $myFile = $file_name;
			  $fh = fopen($myFile, 'w');
			  fwrite($fh, $data);
			  fclose($fh);
			  return $file_name;
		  }
		  else return $data;
   	}
  }
?&gt;</pre>
<p style="text-align: justify;">This PHP Class has two different functions, one is to discover all the JPG, JPEG and PNG files and output them in an array, the second one is a function to create an images.xml file, that will output a XML file something like this:</p>
<pre>&lt;images&gt;
	&lt;image nameI="adv2.jpg" thumb="adv2.jpg" /&gt;
	&lt;image nameI="logo-trans.png" thumb="logo-trans.png" /&gt;
	&lt;image nameI="logo.png" thumb="logo.png" /&gt;
	&lt;image nameI="preview.jpg" thumb="preview.jpg" /&gt;
	&lt;image nameI="pub.png" thumb="pub.png" /&gt;
	&lt;image nameI="stocks-20090608.jpg" thumb="stocks-20090608.jpg" /&gt;
	&lt;image nameI="ttl_contributer.png" thumb="ttl_contributer.png" /&gt;
&lt;/images&gt;</pre>
<p style="text-align: justify;">On the second part of this tutorial we will change a little the php class to create and write down the images thumbnails in here, for now only the structure.</p>
<p style="text-align: justify;">On the other php document, discover.php, write this down:</p>
<pre>&lt;?php
  include_once("imageHandler.php");

  $tm=new imageHandler();

  $data=$tm-&gt;getImageList("./");

  echo($tm-&gt;ary2xml($data,0,'',"images.xml"));
?&gt;</pre>
<p style="text-align: justify;">This will call the getImageList function, then with the images array we call the function to write down the images.xml, this last function returns the filename when done: images.xml.</p>
<p style="text-align: justify;">That&#8217;s all, just put some pictures in this folder, we will need them to continue in flash.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 2 &#8211; Creating a new project in Flash</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g1.jpg" alt="1" width="537" height="244" /></p>
<p style="text-align: justify;">This is quite simple, create a new project and define his stage size 850x470px. The stage size is not important because our flash gallery will automatically fetch the stage area, so you do not need to respect this size&#8230;but make it similar&#8230;</p>
<p style="text-align: justify;">On our timeline, create 4 layers, name the top one &#8220;actions&#8221;, the second &#8220;masker&#8221;, the third masker and the bottom one &#8220;imageLoader&#8221;. This is all that we need. After creating this layers, you should have something link this:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g2.jpg" alt="1" width="540" height="118" /></p>
<p style="text-align: justify;">These layers disposition is very important, in the controls layer we will put a custom preloader, and a movieclip with two icons to control the normal/full screen mode and the speed of our slideshow. In the masker layer, we will simply put a movieclip to mask the imageLoader (to create the mask effect). On the imageLoader we will put a movieclip that will hold the loader to load our images and on the actions layer we will write down our code.</p>
<p style="text-align: justify;">First of all lets create the preloader, the mask and the imageLoader movieClip&#8217;s.</p>
<p style="text-align: justify;">Save your file.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 3 &#8211; Creating the image preloader</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">The image preloader is very simple, just create a new empty movieclip and name it preloader (Menu Insert-&gt;New Symbol or CTRL+F8), After this on our movieclip create 3 layers, name the top one &#8220;Loader&#8221; the middle one &#8220;Mask&#8221; and the bottom one &#8220;Bar&#8221;. On the &#8220;Loader&#8221; layer create a static text and write &#8220;Loading&#8230;&#8221; And on the mask layer create a rectangle with 104&#215;15, and color like #CCCCCC then put it behind the Loading Text.. size the loading text field to fit this rectangle&#8230;</p>
<p style="text-align: justify;">On the last layer, the Bar, create another rectangle, color it #999999 and put it on the left side of the loading text and convert it into a symbol (name it masker_bar), after these steps you must have the things like this:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g3.jpg" alt="1" width="540" height="106" /></p>
<p style="text-align: justify;">Now, extend the 3 layers till the frame 100 (click on each layer frame 100 and right-click-&gt;Insert key frame). This will allow us to make a animation from 0 to 100, creating the loading effect.</p>
<p style="text-align: justify;">On the bottom layer, the bar one, right click on frame 10/15 and select Create Classic Tween, then select the frame 100 of this layer, then select the Left masker_bar symbol and put it over the loading area, make sure it covers it all, something like this:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g4.jpg" alt="1" width="540" height="106" /></p>
<p style="text-align: justify;">This will create a smooth move animation, the final part is to put some stop actions on the start and end frames, click on frame one of the Mask layer, then click F9 (actions) and write stop(); do the same on layer 100. Then mask the bar: Right-click on the mask layer and then select Mask.</p>
<p style="text-align: justify;">We have finished our image preloader:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g5.jpg" alt="1" width="540" height="83" /></p>
<p style="text-align: justify;">Time to save your project.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 4 &#8211; Creating the image loader</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">The image loader is quite simple, if still inside the preloader, go back main stage, select menu Insert-&gt;New Symbol then name it &#8220;imageLoader&#8221;. After this, do nothing inside the imageLoader, leave it empty&#8230; we need this that was so we can add a loader into it as child, that will load our image.</p>
<p style="text-align: justify;">Go back to main stage.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 5 &#8211; Creating a mask movieClip.</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">Do the same steps to create a new movieClip, but name this one &#8220;masker&#8221; and inside him, on the first layer and frame simply draw a small rectangle&#8230;10x15px is enough. This rectangle movieCLip will be used as mask, we will resize it according to each image size, so it masks the image correctly.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 6 &#8211; Creating the animation lines</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">Another very simple step. Insert a new movieClip, name it Liner but this time export it to action script, we will need this to call the lines into Action Script code, the MovieClip properties should be like this (it&#8217;s in French, but you will easy understand when looking at the options):</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g6.jpg" alt="1" width="540" height="305" /></p>
<p style="text-align: justify;">Then in this movieClip select the line tool and make a long horizontal line, with +- 2500px, make sure it starts on the x=0 and y=0 coordinates, like this:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g7.jpg" alt="1" width="540" height="68" /></p>
<p style="text-align: justify;">This is done, save it and go back to main stage.</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 7 &#8211; Creating the control buttons</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">For this step, you will need my images that can be downloaded <a href="https://www.thetechlabs.com/wp-content/uploads/2009/07/buttons.zip">here</a>, take those two png images (max.png and speed2.png) and import them into flash; File-&gt;Import to stage, and select those two images. On the stage, just put the two images side-by-side and then convert them into a &#8220;slideControls&#8221; movieClip.</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g8.jpg" alt="1" width="540" height="101" /></p>
<p style="text-align: justify;">Open this movieclip and here we need to do some stuff.</p>
<p style="text-align: justify;">Click on the arrows image, and then convert it onto a movieClip named &#8220;fullScreen&#8221;, and do the same to the other left icon and name it &#8220;speed&#8221;. On the properties of each movieClip on the instance name write down &#8220;fullscreen&#8221; for the fullScreen button and &#8220;speedBtn&#8221; for the speed button. This will allow us to identify this clips in action script.</p>
<p style="text-align: justify;">Now, double Click on the speed button, we will make a static image click able on the small arrows, for this inside the speed button, create a new layer, name it backBtns, and on this one create a small rectangle, color it #CCCCCC and with +- the size of each small arrow, then convert it into a backBtn movieClip. Copy a new instance of it from library and put them over the small arrows, like this:</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g9.jpg" alt="1" width="540" height="66" /></p>
<p style="text-align: justify;">Name the top instance on properties panel of &#8220;up&#8221; and the bottom one &#8220;down&#8221;. Go to right panel, choose style, and alpha property equal to 0.</p>
<p style="text-align: justify;">This is now ready to receive some code.</p>
<p style="text-align: justify;">Now, create a new Layer above the existent, name it actions and go to panel actions to write this down:</p>
<pre>	up.useHandCursor=true;
  up.buttonMode=true;
  up.addEventListener(MouseEvent.CLICK, onClick);
	down.useHandCursor=true;
  down.buttonMode=true;
  down.addEventListener(MouseEvent.CLICK, onClick);

	function onClick(evt:MouseEvent):void {
	  if(evt.target.name.toString()=="up") {
  	//go up
		  dispatchEvent(new Event("speedUp"));
  	}
  	else {
  	//go down
  	dispatchEvent(new Event("speedDown"));
  	}
 }

stop();</pre>
<p style="text-align: justify;">This will dispatch two custom events that we will listen on main stage to perform the speed change action. The events names are &#8220;speedUp&#8221; when user clicks to increase speed and &#8220;speedDown&#8221; to decrease.</p>
<p style="text-align: justify;">Go back inside the slideControls movieClip, add a new layer on top, name it &#8220;actions&#8221; and in the panel actions write this down:</p>
<pre>	fullScreen.buttonMode=true;
  fullScreen.useHandCursor=true;
  fullScreen.addEventListener(MouseEvent.CLICK, onFullMouse);
  fullScreen.addEventListener(MouseEvent.MOUSE_OVER, onFullMouse);
  fullScreen.addEventListener(MouseEvent.MOUSE_OUT, onFullMouse);

	function onFullMouse(evt:MouseEvent):void {
	  if(evt.type==MouseEvent.CLICK) {
  	(stage.displayState==StageDisplayState.NORMAL) ?
		stage.displayState=StageDisplayState.FULL_SCREEN :
		stage.displayState=StageDisplayState.NORMAL;
	  }
   else if(evt.type==MouseEvent.MOUSE_OVER)
		{
  	fullScreen.alpha=0.5;
  	}
  else {
		fullScreen.alpha=1;
  }
}</pre>
<p style="text-align: justify;">This will make our fullScreen image behave as a button, and add 3 listeners on it. In this case i use only one function to handle the 3 events, because they have something in common, the argument is on the 3 cases a MouseEvent, so i use only one function and compare the event type. If it&#8217;s a CLICK the flash checks if the displayState is in full screen and turn it on normal state or do the inverse.</p>
<p style="text-align: justify;">The stage.displayState = StageDisplayState.FULL_SCREEN transform flash in full screen, but only if we make a small transformation on the publishing argument &#8220;allowFullScreen&#8221; of the HTML to true. We will see this later.</p>
<p style="text-align: justify;">Well, save your project again.</p>
<p style="text-align: justify;">
<h2><strong>Step 8 &#8211; Place movieClip&#8217;s on stage.</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">It&#8217;s now time to put all things on our stage. Because all of our stuff will be automatically sized and placed on stage, we do not really need to concern about the position of elements, just make sure you set up the good instance names and put them on the correct layers.</p>
<p style="text-align: justify;">So, go to main stage, click on the layer &#8220;controls&#8221; and drag and drop the &#8220;preloader&#8221; and &#8220;slideControls&#8221; movieClip&#8217;s from the library into the stage, the place does not matters. Click now on the preloader movieclip and name it&#8217;s instance &#8220;preloader&#8221;, do the same on slideControls movieClip and name it&#8217;s instance to &#8220;galControls&#8221;.</p>
<p style="text-align: justify;">Click now on layer masker, and drag the masker movieClip from library into stage, name it&#8217;s instance &#8220;masker&#8221;.</p>
<p style="text-align: justify;">Finally click on &#8220;imageLoader&#8221; layer and drag the &#8220;imageLoader&#8221; movieclip into stage (because it&#8217;s an empty movieClip pay some attention to the place and the small round circle, this is where your imageLoader is) and name the instance as &#8220;imageLoader&#8221;.</p>
<p style="text-align: justify;"><strong>Note:</strong> Naming these instances is very important, or you will get some errors while accessing to the movieClip&#8217;s from Action Script.</p>
<p style="text-align: justify;">Now you just need to mask the layer mask; Right-click on it and select Mask.</p>
<p style="text-align: justify;">You should get something like this&#8230;</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g10.jpg" alt="1" width="540" height="97" /></p>
<p style="text-align: justify;">Well&#8230; we are almost done, now is time to code&#8230; but before&#8230;</p>
<p style="text-align: justify;"><strong><br />
</strong></p>
<h2><strong>Step 9 &#8211; Understanding stage constraint</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">When, the things might be a little confusing, but this image will help you out, we will have a image (box) on screen and we need to center it, easy, but if the stage size changes (when going to full screen) the center of the stage changes, so we need to reset it&#8217;s position. We simply add an event to listen resizeEvents on stage to reposition the box on screen center, so.. look at the following image, it will help you out on the code.</p>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="size-medium wp-image-1057 alignnone" title="Flash Catalyst IDE" src="https://www.thetechlabs.com/wp-content/uploads/2009/07/g11.jpg" alt="1" width="540" height="400" /></p>
<p style="text-align: justify;">So, now that we learn a little more about the layout, lets take a quick view on the tasks we have to make (from top to bottom order):</p>
<ul>
<li>Setup elements positions on screen.</li>
<li>Call the discover service (discover.php) and wait for it&#8217;s response.</li>
<li>Read the xml file returned from the discover service.</li>
<li>Transform the xml data to an array.</li>
<li>Preload first photo</li>
<li>Animate and show first photo, load the timer to loa next photos</li>
</ul>
<p>These are the main things we have to do in Action Script, so lets begin.</p>
<p><strong><br />
</strong></p>
<h2><strong>Step 10 &#8211; Declare all the variables and imports</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">So, click the actions layer and on frame one actions write this down and make sure you got the gs folder of TweenLite in the same folder of your flash file:</p>
<pre>import gs.TweenLite; //tween classes
import gs.plugins.*; //tweenlite sizePlugin

  //variables
  var HOST:String="http://www.msdevstudio.com/mywork/gallery/"; //gallery host
  var CUR_PHOTO:int=-1; //actual photo
  var FIRST_RUN:Boolean=true; //first run
  var IMAGE_LOADED:Boolean=false; //is there a loaded image?
  var IMAGES:Array = new Array(); //images array
  var SPEED:Number=3000;

	var timex:Timer = new Timer(SPEED); //timer to change photos
  var LT:Liner = new Liner(); //our lines
  var LB:Liner = new Liner();

	var ldr:Loader = new Loader(); //our image loader
  var PhpLoader:URLLoader = new URLLoader(); //the php loader / discover service
  var XmlLoader:URLLoader = new URLLoader(); //xml loader

	//file loaders, discover.php and the XML result file
	PhpLoader.addEventListener(Event.COMPLETE, onPhpComplete); //php discover
  XmlLoader.addEventListener(Event.COMPLETE, onXmlComplete); //php loader

 	//stage properties, align left and no scale
  stage.scaleMode = StageScaleMode.NO_SCALE;
  stage.align = StageAlign.TOP_LEFT;

	//activate the tweenLite setSize() plugin
  TweenPlugin.activate([SetSizePlugin]);

	//add the loader to imageLoader and set his alpha to 0;
  imageLoader.addChild(ldr);
  imageLoader.alpha=0;

	//galLoader events
  galControls.speedBtn.addEventListener("speedUp", changeSpeed);
  galControls.speedBtn.addEventListener("speedDown", changeSpeed);

  //out image loader listeners
  ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageComplete)
  ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);

  //Add Resize listener
  stage.addEventListener(Event.RESIZE, onResizeS);

  //timer event for image transitions
  timex.addEventListener(TimerEvent.TIMER, onTime);</pre>
<p style="text-align: justify;">The main declarations are many, you will find comments on code that will help you out, you just have to change the path for your server on the HOST variable (make sure to add a ending slash.) If you want, you can leave it like that&#8230; well, at least it will work on your localhost.</p>
<p style="text-align: justify;">Now we need to create the functions to handle all this stuff&#8230;</p>
<p><strong><br />
</strong></p>
<h2><strong>Step 11 &#8211; Create handling functions</strong></h2>
<p>&nbsp;</p>
<p>These are the functions that will handle all the events and requests of our code, you will get comments on each one, and what for it&#8217;s used.</p>
<p>Write this next to previous step code:</p>
<pre>/*** function to increase/decrease speed ***/

function changeSpeed(evt:Event):void {
	if(evt.type.toString()=="speedUp") {
		SPEED+=1000; //+1 second
	}
	else SPEED-=1000;
	if(SPEED&lt;1000) SPEED=1000; //minimum speed;
	timex.delay=SPEED; //change our timer speed
}

/*** image load progress, used to set the preloader animation state ***/
function onProgress(evt:ProgressEvent):void {
	var percentLoadede:Number = evt.bytesLoaded/evt.bytesTotal;
	var percent:Number = Math.round(percentLoadede * 100); //percentage loaded
	preloader.gotoAndStop(percent); //set the correct frame of preloader anim.
	if(percent==100) preloader.gotoAndStop(1); //if complete, goto to first frame
}

/****************Setup the lines at screen center ********************/
function setLines():void {
	LT.width=stage.stageWidth; //total screen size
	LT.y=(stage.stageHeight/2)-7.5; //middle - 7.5px the loader has 15px height
	LT.x=0; //at 0

	LB.width=stage.stageWidth;
	LB.y=(stage.stageHeight/2)+7.5;
	LB.x=0;

	addChild(LT); //add lines as stage childs.
	addChild(LB);
}

/*****called when image loading process is complete ********************/
function onImageComplete(evt:Event):void {
	TweenLite.to(preloader,1,{alpha:0}); //hide the preloader with smooth alpha effect 

  imageLoader.height=ldr.height; //change size of the imageloader according to image size
  imageLoader.width=ldr.width;

  imageLoader.x=(stage.stageWidth/2)-(imageLoader.width/2); //imageLoader on center x
  imageLoader.y=(stage.stageHeight/2)-(imageLoader.height/2); //imageLoader on center y

  imageLoader.alpha=1; //show the imageLoader MC
  IMAGE_LOADED=true; //the image is loaded
  CUR_PHOTO++; //increese photo loaded;

  if(FIRST_RUN==true) { //if is the first run
  	timex.start(); //if it's first run, activate the timer to load next images.
 		FIRST_RUN=false; //now it's not the first run
  }
  AnimateToImage(); //animate the mask and lines to make the appear effect
}

/*********** function to reset imageLoader to orignial screen center position ****/
function fixLoader():void {
	imageLoader.height=ldr.height; //fetch the imageloader size to image size
	imageLoader.width=ldr.width;

	imageLoader.x=(stage.stageWidth/2)-(imageLoader.width/2); //imageLoader center x
	imageLoader.y=(stage.stageHeight/2)-(imageLoader.height/2); //imageLoader center y
	masker.width=stage.stageWidth;
	masker.x=0;
	masker.y=(stage.stageHeight/2)-(imageLoader.height/2);
	masker.height=(imageLoader.height/2);
}

/******************* function to load separated images *********************/
function loadImage(img:String=null):void {
	setPreload(); //set the preloader original position
	TweenLite.to(preloader,1,{alpha:1}); //make it appear
	ldr.load(new URLRequest(img)); //laod the requested image
}

/***** Animate the lines and mask to show the image loaded *******/
function AnimateToImage():void {

  TweenLite.to(imageLoader, 1, {alpha:1}); //alpha the imageLoader
  TweenLite.to(masker, 1, {setSize:{height:imageLoader.height}, y:masker.y-(imageLoader.height/2)+7.5}); //resize the mask
	//make lines close the image to original position
  TweenLite.to(LT, 1, {y:imageLoader.y, setSize:{width:stage.stageWidth, height:1}});
  TweenLite.to(LB, 1, {y:imageLoader.y+imageLoader.height, setSize:{width:stage.stageWidth, height:1}});
  //animation is done, so lets start the timer again
  timex.start();
 }

/*** put preloader at center position *********/
  function setPreload():void {
      preloader.x=(stage.stageWidth/2)+4;
  	preloader.y=(stage.stageHeight/2)+7.5;
 }

/****** set the controls on bottom ****/
  function setControls():void {
	    galControls.x=stage.stageWidth-(galControls.width+20);
  	galControls.y=stage.stageHeight-(galControls.height+20);
 }

/*** Set mask original position ****/
  function setMasker():void {
  	masker.width=stage.stageWidth;
  	masker.x=0;
  	masker.y=(stage.stageHeight/2)-7.5;
  	masker.height=15;
 }

/*** Set the imageLoader original position **/
  function setLoader():void {
  	imageLoader.width=stage.stageWidth;
  	imageLoader.x=0;
  	imageLoader.y=(stage.stageHeight/2)-7.5;
  	imageLoader.height=15;
}

/*********** Called on Resize, reset the lines at center screen **/
function ReloadLines():void {
	//if the is an image loaded
	if(IMAGE_LOADED==true)
	{
		//position the lines to center screen
		TweenLite.to(LT, 1, {y:(stage.stageHeight/2)-(imageLoader.height/2), setSize:{width:stage.stageWidth, height:1}, overwrite:0});
		TweenLite.to(LB, 1, {y:(stage.stageHeight/2)+(imageLoader.height/2), setSize:{width:stage.stageWidth, height:1}, overwrite:0});
		TweenLite.to(imageLoader,1,{x:(stage.stageWidth/2)-(imageLoader.width/2), y:(stage.stageHeight/2)-(imageLoader.height/2), overwrite:0})
		TweenLite.to(masker,1,{x:0, y:(stage.stageHeight/2)-(masker.height/2),overwrite:0, setSize:{width:stage.stageWidth}})
	}
	else
	{
		//Kill existing tween, if a tween is running, force stop at the end of effect
		TweenLite.killTweensOf(LT, true);
	 	TweenLite.killTweensOf(LB, true);
		TweenLite.killTweensOf(imageLoader, true);
		TweenLite.killTweensOf(masker, true);
	 	//animate the lines to original "closed" position
		TweenLite.to(LT, 1, {y:(stage.stageHeight/2)-7.7, setSize:{width:stage.stageWidth, height:1},overwrite:0});
		TweenLite.to(LB, 1, {y:(stage.stageHeight/2)+7.5, setSize:{width:stage.stageWidth, height:1},overwrite:0});
		TweenLite.to(masker, 1, {x:0, y:(stage.stageHeight/2)-7.5, setSize:{width:stage.stageWidth, height:15},overwrite:0});
		TweenLite.to(imageLoader, 1, {y:(stage.stageHeight/2)-7.5, setSize:{width:stage.stageWidth, height:15},overwrite:0});
		//we run this to fix a bug founded when passing to fullscreen during a transition.. this resets all this to original position;
		//do not ask me why this happens, but it happens some times, maybe because a tweenlite bug!
		TweenLite.killTweensOf(LT, true);
	 	TweenLite.killTweensOf(LB, true);
		TweenLite.killTweensOf(imageLoader, true);
		TweenLite.killTweensOf(masker, true);
	}
	//move controls and loader to new position.
	TweenLite.to(galControls,1,{x:stage.stageWidth-(galControls.width+20), y:stage.stageHeight-(galControls.height+20), overwrite:0})
	TweenLite.to(preloader,1,{x:(stage.stageWidth/2)+4,y:(stage.stageHeight/2)+7.5, overwrite:0})
}

/******* on screen resize ***/
function onResizeS(evt:Event):void {
	ReloadLines();
}

/**** send lines back to original position, close effect ****/
  function resetLines(loadNext:String=null):void {
		TweenLite.to(imageLoader, 1, {alpha:0});
  	TweenLite.to(masker, 1, {setSize:{height:15}, y:(stage.stageHeight/2)-7.5});

		setPreload();

		TweenLite.to(LT, 1, {y:(stage.stageHeight/2)-7.5, setSize:{width:stage.stageWidth, height:1}});
		TweenLite.to(LB, 1, {y:(stage.stageHeight/2)+7.5, setSize:{width:stage.stageWidth, height:1}});

	 if(loadNext!=null) {
  	TweenLite.to(preloader, 1, {alpha:1, onComplete:loadImage, onCompleteParams:[HOST+"/"+IMAGES[CUR_PHOTO+1].imageName]});
  }
  else  TweenLite.to(preloader, 1, {alpha:1});
}

/******* On time function, load next image ***/
function onTime(evt:TimerEvent):void {
	timex.stop(); //stop the timer so images don't load befor that previous load is complete
	if((CUR_PHOTO+1)&gt;(IMAGES.length-1)) CUR_PHOTO=-1; //if it's the final photo, load next

	if(IMAGE_LOADED==true) { //if it is loaded, reset the lines and load photo after that
		IMAGE_LOADED=false;
		resetLines(HOST+"/"+IMAGES[CUR_PHOTO+1].imageName); //load image after reseting lines
	}
	else {
		loadImage(HOST+"/"+IMAGES[CUR_PHOTO+1].imageName);
	}
}

/*** on php discover response ****/
function onPhpComplete(evt:Event):void {
 	 XmlLoader.load(new URLRequest(HOST+"/"+PhpLoader.data))
}

/*** on xml loaded, build images array ***/
function onXmlComplete(evt:Event):void {
  IMAGES = xml2Array(evt.target.data); //load images into array
  onTime(new TimerEvent(TimerEvent.TIMER)); //load first;
}

/*** tranform xml response into array ****/
function xml2Array(dados:String):Array {
			var menuXML:XML = new XML(dados);
			//just in case
			menuXML.ignoreWhitespace = true;
			//get XML item's entrys
			var XMLItems = menuXML.descendants("image");
			//load all items into an array
			var itemsArray:Array = new Array();
			var itemObj:Object;
			for(var i in XMLItems)
			{
				itemObj=new Object();
				itemObj.imageName=XMLItems[i].@nameI; //save image path into imageName
				itemObj.imageThumb=XMLItems[i].@thumb; //save image thumb path
				itemObj.itemID="image-"+i;
				itemsArray.push(itemObj);
			}
		return itemsArray;
}</pre>
<p>Almost done! The main function are all done, we just need to initialize the things up.</p>
<p><strong><br />
</strong></p>
<h2><strong>Step 12 &#8211; Writing initialization code</strong></h2>
<p>&nbsp;</p>
<p>Just add this after all this code:</p>
<pre>setLines();
setControls();
setPreload();
setMasker();
setLoader();

var req:URLRequest = new URLRequest(HOST+"discover.php");
PhpLoader.load(req);
stop();</pre>
<p style="text-align: justify;">This will start all the slide and gallery process, you should not get any errors, but if you find some one just say.</p>
<p style="text-align: justify;">Save your file and run your movie.</p>
<p><strong><br />
</strong></p>
<h2><strong>Step 13 &#8211; Allowing fullScreen on HTML</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">Full screen will into work, we need to make some changes into the published HTML, first of all Publish your project; File-&gt;Publish</p>
<p style="text-align: justify;">After this, you will get an HTML file with the same name of your project, you just need to browse the source code of that HTML file, and find (usually) the 3 &#8220;allowFullScreen&#8221; parameters in the embed code, set all these 3 to &#8220;true&#8221;;</p>
<p style="text-align: justify;">Save your HTML File, and load it on a browser! Now you have full screen mode available, just click in the arrow&#8217;s on bottom.</p>
<p><strong><br />
</strong></p>
<h2><strong>Final Notes</strong></h2>
<p>&nbsp;</p>
<p style="text-align: justify;">The first part of this tutorial is now complete, you will have some time to understand the code and why not suggest improvements, some things could be simplified, maybe&#8230; but this is up to you. Want to test with your own pictures? Just change the HOST path, and put some pictures on that folder.</p>
<p style="text-align: justify;">If you want the slideshow to read the XML instead auto-discovering the images, just go to the end of the code, and replace this:</p>
<pre>var req:URLRequest = new URLRequest(HOST+"discover.php");
req.method = URLRequestMethod.GET;
PhpLoader.load(req);</pre>
<p>by this:</p>
<pre>var req:URLRequest = new URLRequest(HOST+"images.xml");
XmlLoader.load(req);</pre>
<p style="text-align: justify;">And make sure you have the same structure that i have on the XML file. (Step 1).</p>
<p><center><script type="text/javascript">// <![CDATA[
google_ad_client = "pub-7847584538700437"; /* 300x250, created 5/7/10 - The Tech Labs */ google_ad_slot = "0549771992"; google_ad_width = 300; google_ad_height = 250;
// ]]&gt;</script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript">// <![CDATA[

// ]]&gt;</script></center></p>
<h2>Create an intelligent XML image Gallery &amp; Slideshow in Flash CS4 (+PHP) &#8211; Part II/II</h2>
<p>Here is the second part: <a href="https://www.thetechlabs.com/tech-tutorials/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iiii/" target="_blank">Create an intelligent XML image Gallery &amp; Slideshow in Flash CS4 (+PHP) &#8211; Part II/II</a></p><p>The post <a href="https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/">Create an intelligent XML image Gallery & Slideshow in Flash CS4 (+PHP) – Part I/II</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.thetechlabs.com/xml/create-an-intelligent-xml-image-gallery-slideshow-in-flash-cs4-php-part-iii/feed/</wfw:commentRss>
			<slash:comments>30</slash:comments>
		
		
			</item>
		<item>
		<title>Build a Creative &#8220;Swirl Animated Menu&#8221; with Flash CS4</title>
		<link>https://www.thetechlabs.com/tech-tutorials/flash/build-a-creative-swirl-animated-menu-with-flash-cs4/</link>
					<comments>https://www.thetechlabs.com/tech-tutorials/flash/build-a-creative-swirl-animated-menu-with-flash-cs4/#comments</comments>
		
		<dc:creator><![CDATA[Mario Santos]]></dc:creator>
		<pubDate>Wed, 01 Jul 2009 12:00:35 +0000</pubDate>
				<category><![CDATA[Effects]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Latest]]></category>
		<category><![CDATA[Tech Tutorials]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[swirls]]></category>
		<category><![CDATA[web-design]]></category>
		<guid isPermaLink="false">https://www.thetechlabs.com/?p=1313</guid>

					<description><![CDATA[<p>Flash it's a powerful application and can be really complex, but even beginners can create a cool menu for demonstration or for use in a personal site. The menu that we will create is simple, but the swirl animation is something that you don't see everywhere, for that I've decided to explain one way to make an animation of growing swirls without any Action Script code.You will also learn how to import artwork from illustrator where I've pre-made the graphics, the work is very simple and the result will be very cool.</p>
<p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/build-a-creative-swirl-animated-menu-with-flash-cs4/">Build a Creative “Swirl Animated Menu” with Flash CS4</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></description>
										<content:encoded><![CDATA[<p style="text-align: justify;">Flash it&#8217;s a powerful application and can be really complex, but even beginners can create a cool menu for demonstration or for use in a personal site. The menu that we will create is simple, but the swirl animation is something that you don&#8217;t see everywhere, for that I&#8217;ve decided to explain one way to make an animation of growing swirls without any Action Script code.You will also learn how to import artwork from illustrator where I&#8217;ve pre-made the graphics, the work is very simple and the result will be very cool.</p>
<h3>Final Result</h3>
<p style="text-align: justify;">The final result of this tutorial is a growing swirl effect in a simple menu, take a look.</p>
<p style="text-align: justify;"><object width="540" height="300" data="https://www.thetechlabs.com/wp-content/uploads/2009/07/menu.swf" type="application/x-shockwave-flash"><param name="quality" value="autohigh" /><param name="scale" value="exactfit" /><param name="src" value="https://www.thetechlabs.com/wp-content/uploads/2009/07/menu.swf" /><param name="align" value="top" /></object></p>
<h3>Pre-Requisites</h3>
<p style="text-align: justify;">We will use a Adobe Illustrator file that I&#8217;ve made with the graphical elements. <span style="text-decoration: underline;"><strong><a title="Download Ai files" href="https://www.thetechlabs.com/wp-content/uploads/2009/06/menubig-ai.zip" target="_self">Grab it here</a></strong></span> and don&#8217;t worry if you don&#8217;t work with Illustrator, you do not need to open it.</p>
<p style="text-align: justify;">You will need Flash CS4 (but it will work also in previous versions).</p>
<p style="text-align: justify;">You should feel fine about developing in Adobe Flash and Action Script 3.</p>
<p style="text-align: center;"><a title="Download Source Files" href="https://www.thetechlabs.com/wp-content/uploads/2009/06/tutorial-swirls-sources.zip" target="_self"><img loading="lazy" decoding="async" class="size-full wp-image-466 aligncenter" title="Download Source Files" src="https://www.thetechlabs.com/wp-content/uploads/2009/04/sourcefiles.jpg" alt="Download Source Files" width="246" height="93" /></a></p>
<h3>Step 1 &#8211; Setup Flash Environment</h3>
<p style="text-align: justify;">The very first thing is to create a new Action Script 3 Project! Please ignore the OS in French, this is how I work. The things should be easy to follow.</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-1.jpg" border="0" alt="" width="440" height="230" /></p>
<p style="text-align: justify;">On properties, change the dimensions to:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-2.jpg" border="0" alt="" width="540" height="189" /></p>
<p style="text-align: justify;">In here setup the speed to 70 frames/second to make the animation faster. We got now our flash stage prepared, now is time to work, but before save it as menu.fla.</p>
<h3>Step 1 &#8211; Import Illustrator artwork into Flash</h3>
<p style="text-align: justify;">If you do not work with illustrator you should! Illustrator it&#8217;s a great tool, not only for print design, but also for web. One of the cool features is the possibility to transform illustrator elements into movie clips without exit illustrator. In our case, this is already done, so you do not need to open the menuBig.ai file, just download the <a title="Download Ai files" href="https://www.thetechlabs.com/wp-content/uploads/2009/06/menubig-ai.zip" target="_self">zip file</a> and extract it to any place.</p>
<p style="text-align: justify;">Go to flash menu File, then select Import and Import into stage (CTRL+R) and browse to the location where you have extracted the Illustrator menuBig.ai file, then select it and choose Open. A new window will now open with all of illustrator elements, and if you take a closer look, you will find all elements with movie clips icon&#8217;s, these are the converted artwork from illustrator, so, select all the elements like this:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-3.jpg" border="0" alt="" width="540" height="241" /></p>
<p style="text-align: justify;">Now click OK, the artwork should be placed correctly into the stage, like this:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-4.jpg" border="0" alt="" width="540" height="245" /></p>
<p>So, everything is ready to use.</p>
<h3>Step 2 &#8211; Isolate each button elements.</h3>
<p style="text-align: justify;">We need to isolate each button because each one is different, for that follow these steps:</p>
<ul style="text-align: justify;">
<li>Select the Green button circle, the green swirl and the Home label. (to select more that one element press shift while selecting)</li>
<li>Right-Click on those elements, and select Convert to Symbol.</li>
<li>Name the Movie Clip myButtonGreen and click ok.</li>
</ul>
<p style="text-align: justify;">Repeat these 3 steps for both red and blue elements but on the third one, change the name to myButtonRed for the red one and myButtonBlue for the blue one.</p>
<p style="text-align: justify;">Now each button elements are on his own Movie Clip.</p>
<p style="text-align: justify;">The next thing to do, is to name each button instance, this is extremely important! Click on each button, go to to panel properties, and on the instance name write myButtonGreen, myButtonRed and myButtonBlue on each one of the buttons. This will allow us to access them via action script.</p>
<h3 style="text-align: justify;">Step 3 &#8211; Distribute the menus to layers.</h3>
<p style="text-align: justify;">Now that we have all the artwork successfully imported into the stage, each button is created and for clean organization we will need to separate all the things into layers, that process is very easy, will all selected (CRTL+A), Right-Click on one of the menu items and select Distribute to Layers, that will create some new layers with separated artwork, like these ones:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-5.jpg" border="0" alt="" width="540" height="119" /></p>
<p style="text-align: justify;">This will give us more control on each element.</p>
<p style="text-align: justify;">The next thing to do is to create on each swirl an animation. This is the next step</p>
<h3 style="text-align: justify;">Step 4 &#8211; Creating the growing animation</h3>
<p style="text-align: justify;">This animation almost impossible to achieve in action script code, so the work should be made in pure frame-by-frame animation. We will create a mask that will show is contents along with some few frames. We could create a rectangle to mask, put it outside the swirl area and making it move over the swirl to make it appear&#8230; but that is to much automatic, so we need to make it seems more real, but how to do this?</p>
<p style="text-align: justify;">Easy! Instead the rectangle, we will use the pencil with a small circular brush. Let me explain.</p>
<p style="text-align: justify;">First, we will start with the green button. Double click on it and then double click on the swirl Movie Clip. Now you can see the full swirl in an unique layer right?</p>
<p style="text-align: justify;">Create now a new layer and name it mask. With this layer selected go to the tools panel and select the pencil tool, the one on the small picture here. <img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-6.jpg" border="0" alt="" width="19" height="19" /></p>
<p style="text-align: justify;">Then go bottom on the tools panel, and on the pencil size, choose the third one counting from top.</p>
<p style="text-align: justify;">Now on the selected layer click with mouse to draw a point over the swirl near the button green limits, on a &#8220;visible area&#8221;, i mean on the area that will be visible on the swirl, because some parts of the swirl will be behind the green circle we do not need to mask them (if you cannot see well the circle limits make a zoom on stage to 200%), after that create a new keyframe on this layer and put one or two new &#8220;brush points&#8221;, create a third layer and continue with the same steps and some more &#8220;brushes points&#8221; to cover all the &#8220;visible&#8221; swirl area, you can guide yourself by the back green circle. I will explain the first three steps, then the middle and the final completed mask elements. This mask fill should be made progressive to demonstrate the grow effect.</p>
<p style="text-align: justify;">Se what I&#8217;m talking about:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-7.jpg" border="0" alt="" width="540" height="300" /></p>
<h3>Step 5 &#8211; Creating the fade-out animation</h3>
<p>Now we will create a fade-out transition next to the last frame (on my case the frame 46), create a keyframe on the bottom layer on frame 46 (or on your case the last one) then on the frame 56 create a new keyframe.<br />
Now right-click on one of the middle frames, one between frame 46 and 56 and select Create Classic Animation, a arrow will fill the frames, like this:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-8.jpg" border="0" alt="" width="453" height="63" /></p>
<p style="text-align: justify;">Now we need to put the alpha equal to 0 on our swirl clip on the final frame, just click on the last frame, then click on the swirl movie clip the go to right panel, color effects and select style as alpha. Choose 0%.</p>
<p style="text-align: justify;">Our clip has now also a fade-out effect, just need to extend also the mask to it, for that click on frame 56 from the mask layer and insert a keyframe there (F6). Now our animation is complete, just need to avoid that the grow and fade out animation starts. Just create a new layer on top of them, name it actions and insert 3 keyframes, one on the first frame and other on the frame before the fade-out animation (in this case 45) and the last one at the frame 46. Click on the first frame  and go to actions panel and just write:</p>
<pre style="text-align: justify;">stop();</pre>
<p style="text-align: justify;">Do the same thing at the frame 45 on the layers action. It&#8217;s almost done.</p>
<p style="text-align: justify;">The last thing to do is to make this swirl invisible to the first frame (i don&#8217;t want it to be visible at start, just on Mouse Over action) so, Click on the first frame of the mask, then press SHIFT key and then click the last frame of the bottom layer (where is the swirl), this will select the 2 layers frames. Now drag the mouse to your right till the frames are positioned on frame 2, this will insert a empty frame at the beginning on both layers that will make the swirl and the mask invisible at first frame that is what we want, it should stay stopped there (stop();) and showing nothing (empty frames). He should only show the grow animation when we send it to play at frame two, and the fade-out animation when we send it play the frame 47 (48 because we moved all the stuff one frame right). Click on the frame 47/48 on the layer actions and name the frame &#8220;fade&#8221; (without the &#8220;&#8221; ). With this we will be able to call the gotoAndPlay(&#8220;fade&#8221;) to fadeout the swirl.</p>
<p style="text-align: justify;">Finally, Right-Click the layer mask and select Mask.</p>
<p style="text-align: justify;">Check if all the layers are similar:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-9.jpg" border="0" alt="" width="540" height="88" /></p>
<p style="text-align: justify;">Swirl animation it&#8217;s done! If you run the application, it will remain as this:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-10.jpg" border="0" alt="" width="514" height="232" /></p>
<h3>Step 6 &#8211; Create how many menu items you want</h3>
<p style="text-align: justify;">Because we got 3 menu items, you will need to do the same animation procedure to both Red an Blue items, the same &#8220;Step 4&#8221; steps, is not mandatory the number of frames to be equal, but longer the frame animation, longer the animation smooth effect. Remember, enter the clip, then enter the swirl clip, create a layer mask, draw the progressive mask effect, create a fade-out, create a layer actions, make them stop at the correct layers, move them to right one layer, name the fade layer as &#8220;fade&#8221; and save all this.</p>
<p style="text-align: justify;">The procedure is the same for how many menu items you want even if in my case I&#8217;ve only used 3.</p>
<p style="text-align: justify;">Now we got all this ready to rock, but because i want the click  area be only the size of the circle, we need to do something about it, that lead us to the next step.</p>
<h3>Step 7 &#8211; Preparing the menu items.</h3>
<p style="text-align: justify;">Because i want that the label color changes when the user put the mouse over, i need to create a second state for each label, i will explain the first and then you do the other two. First thing to do is to double click on the buttonGreen, then double click again in the label home. You are now inside label home movie clip. Transform the &#8220;Home&#8221; text into a new movie clip called home, then on the same layer  create a keyframe on the second frame. The label movie clip will be automatically copied, now just need to click on the &#8220;About&#8221; in the second frame, the go to right panel and on color effects choose tint and choose a white color. It&#8217;s done!</p>
<p style="text-align: justify;">Just one more thing, add a second layer on top name it actions and write on it:</p>
<pre style="text-align: justify;">stop();</pre>
<p style="text-align: justify;">Do this step in buttonAbout and buttonContact.</p>
<p style="text-align: justify;">Now we need to make a circle with the same area as the button circle; Exit the label movie clip, and create a new layer on top, name it buttonBack, and draw a circle  with the ellipse tool over the green circle without border color, something like this:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-11.jpg" border="0" alt="" width="500" height="155" /></p>
<p style="text-align: justify;">Then convert it to movie clip and name it buttonBack, then name the instance name as buttonBackGreen.</p>
<p style="text-align: justify;">Go to right panel and make his style as alpha at 0%. This will serve as button, and it&#8217;s important that his instance name is buttonBackGreen.</p>
<p style="text-align: justify;">Got to the other buttons and make the same process, create a new layer and this time import the buttonBack movie clip from the library, and put it over the button and name it buttonBackRed and buttonBlackBlue on both buttons and with alpha at 0%.</p>
<p style="text-align: justify;">Well, our buttons are ready to be animated. Go back to main stage and name the greenButton instance as: btnGreenBig, the red as btnRedBig and the blue one as btnBlueBig.</p>
<h3 style="text-align: justify;">Step 8 &#8211; Create a status area</h3>
<p style="text-align: justify;">On any of those layers create a dynamic text field and name his instance Mstatus. This will show our menu mouse interactions, like Over, Out or Click. This is not very important but to make it similar to mine do it anyway.</p>
<h3 style="text-align: justify;">Step 9 &#8211; Writing some code</h3>
<p style="text-align: justify;">This is the final step, just use the empty layer that already exists in main stage, drag it to top of all layers, name it actions:</p>
<p><img loading="lazy" decoding="async" title="Step 0 - Getting Started" src="https://www.thetechlabs.com/wp-content/uploads/2009/06/sw-12.jpg" border="0" alt="" width="506" height="96" /></p>
<p style="text-align: justify;">Now write this code on the layer actions:</p>
<pre>loadButtons(); //load the listeners

function loadButtons():void {
	btnGreenBig.buttonBackGreen.useHandCursor=true;
	btnGreenBig.buttonBackGreen.buttonMode=true;

	btnRedBig.buttonBackRed.useHandCursor=true;
	btnRedBig.buttonBackRed.buttonMode=true;

	btnBlueBig.buttonBackBlue.useHandCursor=true;
	btnBlueBig.buttonBackBlue.buttonMode=true;

	btnGreenBig.buttonBackGreen.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
	btnGreenBig.buttonBackGreen.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
	btnGreenBig.buttonBackGreen.addEventListener(MouseEvent.CLICK, onMouseClick);

	btnBlueBig.buttonBackBlue.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
	btnBlueBig.buttonBackBlue.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
	btnBlueBig.buttonBackBlue.addEventListener(MouseEvent.CLICK, onMouseClick);

	btnRedBig.buttonBackRed.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
	btnRedBig.buttonBackRed.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
	btnRedBig.buttonBackRed.addEventListener(MouseEvent.CLICK, onMouseClick);
}

//the glow filters to apply the swirl
var glR:GlowFilter = new GlowFilter(0xcc0000,1,50,50,2.5);
var glG:GlowFilter = new GlowFilter(0x91e600,1,50,50,2);
var glB:GlowFilter = new GlowFilter(0x0033ff,1,50,50,3.5);

//mouse over handler
function onMouseOver(evt:MouseEvent):void {
	switch(evt.currentTarget.name) { //this is one way to find if the mouseOver is dispatched from the buttonBack MC
		case "buttonBackGreen":
			btnGreenBig.homeOverSwirl.gotoAndPlay(2); //animate the swirl grow
			btnGreenBig.homeLabel.gotoAndStop(2); //put the label on white
			btnGreenBig.homeOverSwirl.filters=[glG]; //applay filters to the swirl
			Mstatus.text="mouseOver Home!"; //update button status text
			startTimer(btnGreenBig); //start the timer to animate the cricular move of button
		break;
		case "buttonBackBlue":  //same as on the green button
			btnBlueBig.contactOverSwirl.gotoAndPlay(2);
			btnBlueBig.contactLabel.gotoAndStop(2);
			btnBlueBig.contactOverSwirl.filters=[glB];
			Mstatus.text="mouseOver Contact!";
			startTimer(btnBlueBig);
		break;
		case "buttonBackRed": //same as on the green button
			btnRedBig.aboutOverSwirl.gotoAndPlay(2);
			btnRedBig.aboutLabel.gotoAndStop(2);
			btnRedBig.aboutOverSwirl.filters=[glR];
			Mstatus.text="mouseOver About!";
			startTimer(btnRedBig);
		break;
	}
}

//mouse out handler
function onMouseOut(evt:MouseEvent):void {
	switch(evt.target) { //this is another way to check if the event is dispatched from buttonBack MC
		case btnGreenBig.buttonBackGreen:
			btnGreenBig.homeOverSwirl.gotoAndPlay("fade"); //play the fade effect
			btnGreenBig.homeLabel.gotoAndStop(1); //return label to his original color
			Mstatus.text="mouseOut Home!"; //update status text
			stopTimer(btnGreenBig); //stop the circular move
		break;
		case btnBlueBig.buttonBackBlue: //sabe as green button
			btnBlueBig.contactOverSwirl.gotoAndPlay("fade");
			btnBlueBig.contactLabel.gotoAndStop(1);
			Mstatus.text="mouseOut Contact!";
			stopTimer(btnBlueBig);
		break;
		case btnRedBig.buttonBackRed: //sabe as green button
			btnRedBig.aboutOverSwirl.gotoAndPlay("fade");
			btnRedBig.aboutLabel.gotoAndStop(1);
			stopTimer(btnRedBig);
			Mstatus.text="mouseOut About!";
		break;
	}
}

//click handler
function onMouseClick(evt:MouseEvent):void {
	switch(evt.currentTarget.name) {
		case "buttonBackGreen":
			Mstatus.text="mouseClick Home!";
		break;
		case "buttonBackBlue":
			Mstatus.text="mouseClick Contact!";
		break;
		case "buttonBackRed":
			Mstatus.text="mouseClick About!";
		break;
	}
}

/***circular animation ***/
var distance:Number = 0.4; //circular distance
var speed:Number=20; //more hight, less speed

//button timers to do the circular move
var time:Timer = new Timer(speed); //green one
var timerBlue:Timer = new Timer(speed); //blue
var timerRed:Timer = new Timer(speed); //red
//listeners to update button position
time.addEventListener(TimerEvent.TIMER, moveCircle);
timerRed.addEventListener(TimerEvent.TIMER, moveRed);
timerBlue.addEventListener(TimerEvent.TIMER, moveBlue);

//current rotation angle position
var angle:Number=0;
var angleB:Number = 0;
var angleR:Number = 0;

//green circular function
function moveCircle (e:TimerEvent):void {
	btnGreenBig.x = btnGreenBig.x + (Math.cos(angle) * distance);
	btnGreenBig.y = btnGreenBig.y + (Math.sin(angle) * distance)
	angle += 0.1;
}

//red circular function
function moveRed (e:TimerEvent):void {
	btnRedBig.x = btnRedBig.x + Math.cos(angleR) * distance;
	btnRedBig.y = btnRedBig.y + Math.sin(angleR) * distance;
	angleR += 0.1;
}

//blue circular function
function moveBlue(e:TimerEvent):void {
	btnBlueBig.x = btnBlueBig.x + Math.cos(angleB) * distance;
	btnBlueBig.y = btnBlueBig.y + Math.sin(angleB) * distance;
	angleB += 0.1;
}

//start timer/circular anim on the provided movieclip.
function startTimer(it:MovieClip):void {
	if(it==btnGreenBig) time.start();
	if(it==btnRedBig) timerRed.start();
	if(it==btnBlueBig) timerBlue.start();
}
//stop timer/circular anim
function stopTimer(it:MovieClip):void {
	if(it==btnGreenBig) time.stop();
	if(it==btnRedBig) timerRed.stop();
	if(it==btnBlueBig) timerBlue.stop();
}</pre>
<p>Well, this code is enough.</p>
<h3>Step 10 &#8211; Finishing our application</h3>
<p>Change background color to black then save and run the project! This step is quite simple!</p>
<p>Nice ah?</p>
<h3>Final considerations!</h3>
<p style="text-align: justify;">Take some time to read the code, I&#8217;ve made some comments that will help you out.</p>
<p style="text-align: justify;">Some of the code could be even more simplified, but i did not do that because this way the things get easy to understand. The timer could be replaced by a Enter Frame event but some times that will overload the menu, these three timers can be replaced only for one, saving you a few lines of code, but this is your work right?</p>
<p style="text-align: justify;">Hope you like it! And again! Don&#8217;t forget to <strong><a title="Follow Us on Twitter" href="http://twitter.com/thetechlabs" rel="nofollow" target="_blank">follow us on twitter</a></strong> and <strong><a title="Subscribe" href="http://feeds2.feedburner.com/the_tech_labs" rel="nofollow" target="_blank">subscribe to our RSS feed</a></strong>!</p><p>The post <a href="https://www.thetechlabs.com/tech-tutorials/flash/build-a-creative-swirl-animated-menu-with-flash-cs4/">Build a Creative “Swirl Animated Menu” with Flash CS4</a> first appeared on <a href="https://www.thetechlabs.com">TheTechlabs.com</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.thetechlabs.com/tech-tutorials/flash/build-a-creative-swirl-animated-menu-with-flash-cs4/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Object Caching 101/228 objects using Redis
Page Caching using Disk: Enhanced (SSL caching disabled) 
Lazy Loading (feed)
Minified using Disk

Served from: www.thetechlabs.com @ 2026-06-05 15:31:14 by W3 Total Cache
-->