Friday, May 16, 2008

Custom Event Creation and Data Passing

Passing Data With Custom Event


As being an event driven language Action Script provides the mechanism of sending any kind of object with
the event.The concept is more important when we are supposing to get value of any varialbe of mxml into
any another mxml which is far enough in the structure(Folder Structure)of our Application. It is very simple
to create any custom event for the occurence of any particular event.Within the same parent folder in which
your mxml containing the variable create a folder (let suppose with name ‘event’).In mxml let's suppose
variable of arrayCollecton ‘myCollection’ is defined and it is already assigned some data.
Now we will create a custom event ‘CustomEvent’ in the folder where your mxml(which is having that arrayCollection)is present.

Just create one action Script class file Copy and Paste the code below.
——————————————————————————————–
package myPro.events
{
import flash.events.Event;

public class CustomEvent extends Event
{

public var mybool:Boolean=true;
public var myCollection:ArrayCollection;

public function PropertyThumbEvent (type:String,myCollection,mybool:Boolean=true):void
{
super(type);
this.myArrayCollection = myArrayCollection;
this.b=b ;
}

override public function clone():Event
{
return new CustomEvent(type,myCollection,mybool);
}

}
}
——————————————————————————————–

Now at this mxml where ‘myCollection’ is present First add Metadata as below :-
——————————————————————————————–

[Event(name="myCustomEvent",type="myPro.events.myCustomEvent")]

——————————————————————————————–

Again from the same mxml just dispatch one event i.e. as:-

——————————————————————————————–
dispatchEvent(new CustomEvent(”myCustomEvent”,myCollection,true));

——————————————————————————————–
we can use it as follows:-

trace(event.myCollection)

No comments:

About Me