300x250 AD TOP

Showing posts with label Flash. Show all posts
Showing posts with label Flash. Show all posts

Tuesday, 6 March 2012

Tagged under:

Build a Creative “Swirl Animated Menu” with Flash CS4



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.

Final Result

The final result of this tutorial is a growing swirl effect in a simple menu, take a look.

Pre-Requisites

We will use a Adobe Illustrator file that I’ve made with the graphical elements. Grab it here and don’t worry if you don’t work with Illustrator, you do not need to open it.
You will need Flash CS4 (but it will work also in previous versions).
You should feel fine about developing in Adobe Flash and Action Script 3.
Download Source Files

Step 1 – Setup Flash Environment

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.

On properties, change the dimensions to:

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.

Step 1 – Import Illustrator artwork into Flash

If you do not work with illustrator you should! Illustrator it’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 zip file and extract it to any place.
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’s, these are the converted artwork from illustrator, so, select all the elements like this:

Now click OK, the artwork should be placed correctly into the stage, like this:

So, everything is ready to use.

Step 2 – Isolate each button elements.

We need to isolate each button because each one is different, for that follow these steps:
  • Select the Green button circle, the green swirl and the Home label. (to select more that one element press shift while selecting)
  • Right-Click on those elements, and select Convert to Symbol.
  • Name the Movie Clip myButtonGreen and click ok.
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.
Now each button elements are on his own Movie Clip.
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.

Step 3 – Distribute the menus to layers.

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:

This will give us more control on each element.
The next thing to do is to create on each swirl an animation. This is the next step

Step 4 – Creating the growing animation

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… but that is to much automatic, so we need to make it seems more real, but how to do this?
Easy! Instead the rectangle, we will use the pencil with a small circular brush. Let me explain.
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?
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.
Then go bottom on the tools panel, and on the pencil size, choose the third one counting from top.
Now on the selected layer click with mouse to draw a point over the swirl near the button green limits, on a “visible area”, 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 “brush points”, create a third layer and continue with the same steps and some more “brushes points” to cover all the “visible” 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.
Se what I’m talking about:

Step 5 – Creating the fade-out animation

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.
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:

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%.
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:
stop();
Do the same thing at the frame 45 on the layers action. It’s almost done.
The last thing to do is to make this swirl invisible to the first frame (i don’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 “fade” (without the “” ). With this we will be able to call the gotoAndPlay(“fade”) to fadeout the swirl.
Finally, Right-Click the layer mask and select Mask.
Check if all the layers are similar:

Swirl animation it’s done! If you run the application, it will remain as this:

Step 6 – Create how many menu items you want

Because we got 3 menu items, you will need to do the same animation procedure to both Red an Blue items, the same “Step 4″ 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 “fade” and save all this.
The procedure is the same for how many menu items you want even if in my case I’ve only used 3.
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.

Step 7 – Preparing the menu items.

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 “Home” 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 “About” in the second frame, the go to right panel and on color effects choose tint and choose a white color. It’s done!
Just one more thing, add a second layer on top name it actions and write on it:
stop();
Do this step in buttonAbout and buttonContact.
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:

Then convert it to movie clip and name it buttonBack, then name the instance name as buttonBackGreen.
Go to right panel and make his style as alpha at 0%. This will serve as button, and it’s important that his instance name is buttonBackGreen.
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%.
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.

Step 8 – Create a status area

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.

Step 9 – Writing some code

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:

Now write this code on the layer actions:
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();
}
Well, this code is enough.

Step 10 – Finishing our application

Change background color to black then save and run the project! This step is quite simple!
Nice ah?

Final considerations!

Take some time to read the code, I’ve made some comments that will help you out.
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?
Tagged under:

Creating a Gallery in Flash Using the Moto CMS Component

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 CMS – an advanced content management system for Flash. The CMS is considered as today’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.
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).

Results of Moto CMS Component:

Today I would like to show you what can be done with the help of the Moto CMS component. So, for creating a Flash photo gallery we will use two abstract classes.
Final Result:
Moto CMS - CMS Photo Gallery
Moto CMS - CMS Photo Gallery

1. FLA file settings For Moto CMS Gallery

Let’s start by opening Flash and creating a new FLA file. We’ll name it thumbnailsModule.fla in this tutorial. It should be put in the same folder where the “src” folder is placed. Now we’ll open the Publish Settings (Ctrl+Shift+F12), open the ActionScript settings, and set the classpath “./src”:

2. Creating the ThumbnailsModule Symbol CMS Photo Gallery

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.
Drag the Photo Gallery Thumbnails component to the stage, give it the instance name “preview”, and press F8 to convert it to Symbol. Let’s name it ThumbnailsModule; use the same name for the Class name, and set the Base class: modules.photoGalleryModules.ThumbnailsModule
This class is not created yet, so we should create it before clicking OK. Let’s go to srcmodulesphotoGalleryModules and create ThumbnailsModule.as. We’ll add the script later.
Now let’s get back to the FLA, click OK, and select the created Movie Clip on the stage. We set its instance name to thumbnailsModule.
Open the ThumbnailsModule Movie Clip. Let’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’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.
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.

3. Creating navigation controls with Moto CMS

Open the galleryHolder Movie Clip and insert a new layer. Let’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.
As we draw the white arrow in this example, we change the Backgrond Color of the flash document to grey.
Let’s convert this arrow to Symbol. The name and the Class name will be ThumbnailsNavigationBtn, and the Base class will be: modules.photoGalleryModules.ThumbnailsNavigationBtn
Let’s also set the Registration in the center.
We should create ThumbnailsNavigationBtn.as in srcmodulesphotoGalleryModules before clicking OK. We’ll leave the class empty for now.
Then we open the ThumbnailsNavigationBtn Movie Clip and convert the arrow to Symbol again. Let’s name it “clip”, and give its instance the same name. The Registration should be set in the center.
We should convert this Movie Clip to Symbol once again. This time it will be named “icon”. Registration: center. So now we have two Movie Clips inside the ThumbnailsNavigationBtn – “icon” and “clip”. We have created this structure to easily handle the button properties with the help of the script.
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’s dimensions, make it transparent, and convert it to Symbol. Let’s name it “back”. The instance name should be “back” as well.
CMS Photo Gallery
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 “icon”.
Moto CMS
Now we’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.
Let’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’ move it to the right and select Modify – Transform – Flip Horizontal. It will be the next button. Let’s give the buttons instance names prevBtn and nextBtn, respectively.
So, we have created the thumbnails controls.

4. Creating the Moto CMS item class

Now we should create the thumbnail class (item renderer), which will be used by the script for every new thumbnail. Let’s get back to the main timeline of the FLA document and drag the Moto CMS Image Loader component to the stage. Let’s give it the instance name “image”. We should also open the Parameters tab and set the Scaling Mode: fill.
Then we convert it to Symbol and name it imageHolder. Don’t forget to set the Move Clip Registration to the top left corner, as it was by default.
Moto CMS
Now we convert it to Symbol again. It will be the item renderer class, so we’ll check the “Export for ActionScript” box, and specify the class names:
We set Base class: modules.photoGalleryModules.ThumbnailItemRenderer
This class is not created yet, so we go to srcmodulesphotoGalleryModules and create an empty ThumbnailItemRenderer.as.
Now we can open the ThumbnailItemRenderer Movie Clip and animate the imageHolder. We should set the frame labels to “show”, “over”, and “out”. 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).
We put the “stop();” 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:
Let’s also create the preloader. We insert a new layer, and create a Movie Clip with an instance name “preloader”. You can create any preloading animation insde this Movie Clip.
The item renderer is ready.

5. Creating the thumbnail cover with Moto CMS

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.
Let’s get to to the main timeline and create a Movie Clip inside moto cms with a transparent shaped object. It’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:
Base class: modules.photoGalleryModules.ThumbnailItemRendererCover
Same as before, we should go to srcmodulesphotoGalleryModules and create an empty ThumbnailItemRendererCover.as.
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: “show”, “over”, and “out”. 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.
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.

6. Creating the CMS Photo Gallery ThumbnailsModule class

Now it’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’s start from the main class – ThumbnailsModule.as. We add the class constructor with the main imports:
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();

  }

 }
}
Then we create the necessary variables:
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();

  }

 }
}
Let’s also add MovieClip to imports: import flash.display.MovieClip;
Then we should assign the variables to the created elements, and specify the next/previous buttons:
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;
  }

 }
}
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.
  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;
   }
  }
We should also add PropertyVO to imports:
import com.moto.template.shell.model.vo.PropertyVO;
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.
  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();
    }
   }
  }
Let’s also import Event:


import flash.events.Event;
The next method which we are going to override is setSize. This method contains the logic of resizing and positioning.
  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;
   }
  }
We should add OrientationEnum to imports:
import com.moto.template.common.view.OrientationEnum;
Finally we override the show and hide methods to add tweens.
  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} );
  }
We add the Tweener class to imports:
import caurina.transitions.Tweener;

7. Creating the ThumbnailItemRenderer class

When the ThumbnailsModule class is ready, we can switch over to ThumbnailItemRenderer.as. The class constructor will be:
package modules.photoGalleryModules
{

 public class ThumbnailItemRenderer extends AbstractThumbnailItemRenderer
 {

  public function ThumbnailItemRenderer()
  {
   super();

  }

 }
}
Then we create variables for image and preloader and import the needed classes.
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();

  }

 }
}
Now we assign the variables to the elements in the class constructor.
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;
  }

 }
}
Then we override the updateRenderer method. We specify the image path and add listeners for successful complete and error events.
These classes should be added to imports:
import com.moto.template.common.events.MediaLoaderErrorEvent;
import flash.events.Event;

  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});
  }
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.
  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;
   }

  }
Let’s also import the Tweener class:
import caurina.transitions.Tweener;
The next step will be overriding the setSize method and adding the resizing logic.
  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;
  }
The getDimensions method passes the actual size of the element. So, we override it and return a rectangle of image dimensions.
  override public function getDimensions():Rectangle
  {
   return new Rectangle(0, 0, _image.width, _image.height);
  }
Rectangle should be added to imports:
import flash.geom.Rectangle;

8. Creating the ThumbnailItemRendererCover class

Right after the ThumbnailItemRenderer class we are going to write a script for its “cover” – ThumbnailItemRendererCover.as. Let’s start with adding the basic code:
package modules.photoGalleryModules
{
 import com.moto.template.modules.gallery.GalleryThumbnailCover;
 import flash.display.MovieClip;

 public class ThumbnailItemRendererCover extends GalleryThumbnailCover
 {

  public function ThumbnailItemRendererCover()
  {
   super();

  }

 }
}
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.
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)
  }

 }
}
Let’s also add Sprite and Event classes to imports:
import flash.display.Sprite;
import flash.events.Event;

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.
  private function addedToStageHandler(event:Event):void
  {
   removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);

   show();
   gotoAndPlay(showLabel);
  }
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.
  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;
   }
  }
We also add PropertyVO and Rectangle to imports:
import com.moto.template.shell.model.vo.PropertyVO;
import flash.geom.Rectangle;

Then we add getter and setter for the stroke thickness property.
  public function get strokeThickness():uint {
   return _strokeThickness;
  }

  public function set strokeThickness(value:uint):void {
   _strokeThickness = value;
  }
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.
  public function showOverState():void {
   over();
  }
Then we override over and out methods and add tweens for mouseover and mouseout animation.
  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]} );
  }
Let’s also import the Tweener class:
import caurina.transitions.Tweener;
The ThumbnailItemRendererCover class is ready.

9. Creating the ThumbnailsNavigationBtn class

Now we proceed to the only class left – ThumbnailsNavigationBtn. Let’s add the basic code.
package modules.photoGalleryModules
{
 import common.AbstractNavigationBtn;

 public class ThumbnailsNavigationBtn extends AbstractNavigationBtn
 {

  public function ThumbnailsNavigationBtn()
  {
   super();

  }

 }
}
Then we create new variables which will be used in the script.
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();

  }

 }
}
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.
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();

  }

 }
}
Then we override the updateProperty method and handle the buttons’ properties, such as color and transparency level.
  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;
   }
  }
Finally we override over and out methods. We add tweens and set them to colour the buttons on mouseover and mouseout.
  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} );
  }
So we have created all the needed classes.

10. Initializing the module

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’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:
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;
}
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’s and its cover’s library linkage names. Lines 54-57 contain the module’s width, height, and coordinates. You can adjust these values to your needs.
Let’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.

11. Creating the Moto CMS gallery XML file.

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:
<?xml version="1.0" encoding="utf-8"?>
<simpleGalleryModule>
 <configuration>
 <option id="previewPropertyID">
 <value>1</value>
 </option>
 <option id="thumbnailPropertyID">
 <value>2</value>
 </option>
 <option id="thumbnailWidth">
 <value>299</value>
 </option>
 <option id="thumbnailHeight">
 <value>217</value>
 </option>
 <option id="maxRootItems">
 <value>0</value>
 </option>
 </configuration>
 <structure>
 <properties>
 <property id="1" type="media">
 <name><![CDATA[Preview]]></name>
 <parameters>
 <image>true</image>
 <flash>true</flash>
 <video>true</video>
 </parameters>
 </property>
 <property id="2" type="image">
 <name><![CDATA[Thumbnail]]></name>
 </property>
 <property id="3" type="link">
 <name><![CDATA[Link]]></name>
 </property>
 </properties>
 <template>
 <properties>
 <item propertyType="1"/>
 <item propertyType="2"/>
 <item propertyType="3"/>
 </properties>
 </template>
 </structure>
 <data>
 <item id="1" order="1"><properties><item propertyType="1"><![CDATA[images/image1_big.jpg]]></item><item propertyType="2"><![CDATA[images/image1_small.jpg]]></item><item propertyType="3"><![CDATA[]]></item></properties></item>
 <item id="2" order="2"><properties><item propertyType="1"><![CDATA[images/image2_big.jpg]]></item><item propertyType="2"><![CDATA[images/image2_small.jpg]]></item><item propertyType="3"><![CDATA[]]></item></properties></item>
 <item id="3" order="3"><properties><item propertyType="1"><![CDATA[images/image3_big.jpg]]></item><item propertyType="2"><![CDATA[images/image3_small.jpg]]></item><item propertyType="3"><![CDATA[]]></item></properties></item>
 </data>
</simpleGalleryModule>
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 “item” node to add as many elements as you need. Please note that every new item must have the unique “id” and “order” attributes.
This post on Moto CMS was brought to you by Paul Flores. He currently works with the Moto CMS components and develops Flash websites on the basis of Moto CMS and Moto Flash templates.
Thank you for reading the Moto CMS tutorial! I hope you liked it. Your comments will be highly appreciated.