For a start you are going to need a constructor. You will also need
member properties for the items you want to add to the event..
package events
{
import flash.events.Event;
public class recordEvent extends Event
{
public static const RECORD_EVENT:String = "recordEvent";
public var record:myRecordObject;
public var action:String;
public function recordEvent(type:String, record:myRecordObject,
action:String, bubbles:Boolean=true, cancelable:Boolean=true)
//Constructor
{
super(type);
this.record = record;
this.action = action;
}
override public function clone():Event
{
return new recordEvent(type, record, action, bubbles,
cancelable);
}
}
}
For a new event of your type...
dispatchEvent(new recordEvent(recordEvent.RECORD_EVENT, myRecord,
"delete"));
And for an eventListener you can use...
addEventListener(recordEvent.RECORD_EVENT, onRecordEvent);
private function onRecordEvent(event:recordEvent):void
{
var action:String = event.action;
var record:myRecordObject = event.record;
}
NB: Typed off the top of my head so may have mistakes. Generally, I
would use private member variables with getters and setters but this
should give you a starting point.
HTH
Steve
--- In [email protected], "secrit.service" <secrit-serv...@...>
wrote:
>
>
> Hi all,
>
> The last couple of weeks I wrote my first application in Flex. Today I
> want to refactor it, meaning : using custom classes and custom events.
>
> I have following :
>
> I created an application with a couple of buttons and with a custom
> component (myCustomComp) in it. This custom component is based on a
> Vbox an contains :
> - an HBox (mySearchbar) with a textfield and button
> - a datagrid which contains data from a database
> - an HBox (myToolbar) with a button and a label
>
> The buttons are used for adding, modifying and deleteing records of
the
> database. SO I was thinking of creating a custom event
(myCustomEvent).
>
> The code I have so far is following :
>
> package events {
>
> import flash.events.Event;
>
> public class myCustomEvent extends Event {
>
> public function SpellEvent(type:String) {
> super(type);
> }
>
> override public function clone():Event{
> var evt:myCustomEvent = new
myCustomEvent(type);
> return evt;
> }
>
> }
>
> }
>
> I was thinking of adding event listners to my buttons. For example my
> button to add a new record will have a addRecordEventListener. In this
> listener I create a new instance of myCustEvent and pass my new record
> as a parameter.
> The same I will do with my button to delete a record.
>
> My question is where and how I should make the difference between the
2
> operations.
> I suppose I have to create a new instance of my event and besides my
new
> record I also need to pass the type of operation : something like new
> myCustomEvent(newRecord, "addRecord") or new myCustomEvent(newRecord,
> "deleteRecord"). But in this case, how do I process the different
> operations?
>
> I'm lost and hoping for a clear answer.
>
> Thanks
>