Pages

Monday, August 1, 2011

AS3: A class to control 'About ...' movieclip

It is well known fact that, each and every software or program has atleast About <software_name> dialogue box. Similarly if an application is made-up in flash, it should have an About ... dialogue-box.

I usually prefer to show it over top of the application as a message box with a faded or dark background.
To achieve this in flash, there is an About ... movieclip. It should be of size that covers the whole stage.

There are 2 movieclips inside About ... movieclip:
  1. shows message related to About ... content
  2. fades or darkens the are behind About ... content

By default this About ... movieclip will remain hidden. And on certain predefined mouse-click it'll show up. But after that as soon as user will click on the dark background area, the About ... will disappear.

So this functionality requires only on movieclip inside the About ... movieclip to be linked with mouse-click event, which is the bas or background movieclip.

CODE
 package   
 {  
  import flash.display.MovieClip;   
  import flash.events.Event;  
  import flash.events.MouseEvent;  
  /**  
   * @file CAbout.as  
   * @author Abhishek Kumar  
   */  
  public class CAbout  
  {  
   private var Container:MovieClip = null;  
   public function CAbout(iReference:MovieClip)  
   {  
    Container = iReference;  
    initializeAssets();  
   }  
   private function initializeAssets():void  
   {  
    hide();  
   }  
   public function initializeEvents():void  
   {  
    Container.base.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);  
   }  
   public function destroyEvents():void  
   {  
    Container.base.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);  
   }  
   private function onMouseUp(me:MouseEvent):void  
   {  
    hide();  
    destroyEvents();  
   }  
   public function hide():void  
   {  
    Container.visible = false;  
   }  
   public function show():void  
   {  
    Container.visible = true;  
    initializeEvents();  
   }  
  }  
 }  

No comments:

Post a Comment