Event means action, as Mouse Clicks, Mouse Moves, Error occurs , File loads. Whatever happens means event occurs. Flash have its own events like MouseEvent, KeyboardEvent, IOErrorEvent etc.

   While migrating AS 2.0 to AS 3.0 you can see you have lot of control on events. Then why to create your own event? I had that question. I always think, if I write little bit complex logic I will get output. But I got my answer. Custom event gives you power to control your own actions.

I am not theoretical guy so not able to explain you. Let’s see it in my practical way… with example….. 

I created an example for loading bulk of images serially.

For that,

1) I created my own event (BulkImageLoaderEvent) who tells me that all images are loaded or one image loaded and also it passes me that loaded data.

2) I created an object for loading all images where I wrote my business logic for loading bulk images one by one. Also assigns my BulkImageLoaderEvent to this object. Means my custom event controls actions in my custom class.

3) I have some code on timeline to pass raw data.


 BulkImageLoaderEvent Class

 This is my custom event. Which helps in loading bulk of  images.

It will tell me that all images are loaded also single image is loaded.

BulkImageLoaderEvent.as

package

{

      import flash.events.Event;

      import flash.display.Bitmap

     

      public class BulkImageLoaderEvent extends Event

      {

 

                  public static const ALL_LOAD_COMPLETE:String="AllLoadComplete";

                                         

                  public static const SINGLE_LOAD_COMPLETE:String="SingleLoadComplete";

                  public var paramBit;

                  public var paramArr;

                 

                  public function BulkImageLoaderEvent($type:String,$paramArr:Array,$paramBit:Bitmap,$bubbles:Boolean = false, $cancelable:Boolean = false)

                  {

                              super($type,$bubbles,$cancelable)

                              this.paramBit=$paramBit

                              this.paramArr=$paramArr;

                  }

                  public override function clone():Event

                  {

                              return new BulkImageLoaderEvent(type,paramArr,paramBit,bubbles,cancelable);

                  }

                  public override function toString():String

                  {

            return formatToString("BulkImageLoaderEvent", "paramArr", "bitmap","type", "bubbles", "cancelable");

        }

      }

}