Here is your code modified to use the EventDispatcher:
import mx.events.EventDispatcher; // import the event dispatcher
class com.boa.projects.iqrcgenerator.components.AdminData{
public var addEventListener:Function; // Set the functions
public var removeEventListener:Function; // Set the functions
private var dispatchEvent:Function; // Set the functions
private var userData:Object;
// I'm sure you have a different constructor, but you need
// to add that line to it if you want to use the eventdispatcher
public function AdminData(){
mx.events.EventDispatcher.initialize(this); // add this
to constructor
}
public function wsUserDataByLOB(lobDbId:Number):Void{
var getUserListResult:Object = new Object();
getUserListResult =
generatorWebService.GetUserList(lobDbId);
var r = this; // To get this in onResult
getUserListResult.onResult = function(oUser){
r.dispatchEvent({type:"eventOnResult",
user:oUser}); // Dispatch the event
}
}
// I may just take this function out all together since the
event can
// autommatically send them the data.
public function getUserData():Object{
return userData;
}
}
Then in your other class you can do something like:
//myAdminData is an instance of the class above
var r = this;
r.eventOnResult= function(evtObj:Object){
trace("user: " + evtObj.user); // Should return the oUser
object
}
// addEventListener takes the event name, and who you want to listen
myAdminData.addEventListener("eventOnResult", r);
Does that help? I obviously can't test the code, but I think everything
is right... I have trouble with scope, which is why I use a lot of 'r'
values instead of 'this'... Just easier for me... Probably not a good
coding standard :)
-Dan
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: Friday, February 16, 2007 9:03 AM
To: Flashcoders mailing list
Subject: [Flashcoders] Events for custom classes?
OK, I'm pretty good at Actionscript 2.0, but something I never really
understood and now need to.
Core question: How do I make an event in a custom class, and how do I
make a listener in another class listen for the event?
EventBroadcaster in the help docs seems to only show how to use it with
Adobe classes and components. Docs on listener are the same. I know how
to set up listeners for other events, like keypresses and mouse
rollovers. Easy enough. But my problem is this (see comments in code
below):
class com.boa.projects.iqrcgenerator.components.AdminData{
private var userData:Object;
public function wsUserDataByLOB(lobDbId:Number):Void{
var getUserListResult:Object = new Object();
getUserListResult =
generatorWebService.GetUserList(lobDbId);
getUserListResult.onResult = function(oUser){
//this works fine,
//I can capture this event result here,
//but how do I notify another class?
//also what about scope here?
//how to set userData as oUser result?
//can I fire an event in my AdminData
//class from here?
}
}
public function getUserData():Object{
//can't let user get this data
//until Webserive event is done.
return userData;
}
}
Thanks,
Jason Merrill
Bank of America
Learning & Organizational Effectiveness
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
This e-mail and its attachments are intended only for the use of the
addressee(s) and may contain privileged, confidential or proprietary
information. If you are not the intended recipient, or the employee or agent
responsible for delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution, displaying, copying, or
use of this information is strictly prohibited. If you have received this
communication in error, please inform the sender immediately and delete and
destroy any record of this message. Thank you.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com