List Info

Thread: RE: Events for custom classes?




RE: Events for custom classes?
country flaguser name
United States
2007-02-16 13:35:55
Daniel, try as I may, I can't get your code to work.  I have
one class,
which has a combobox.  I can get the event to fire when the
combobox
changes just fine, but I can't get it to "hear"
the firing of the data
capture from the webservice in the other class.

So basically, in pseudocode, I need to do this:

class A{
	make comboBox
	make datagrid
	when comboBox changes, use Class B
		to get data from webservice
	when webservice result received, 
        		update datagrid with new data

}

class B{
	connect to webservice	
	when requested, return data to requesting class
}

Reason I want these two classes to be separate is because I
want other
classes to call Class B to get data as well.  So, I can do
all of those
things just fine, they are all working, except for the last
part, "when
requested, return data to requesting class" - I figure
since the
webservice is asynchronous, I need to capture the received
event, which
is fine, I can do, that works.  But I need to tell Class A
to update the
datagrid with the new data when it gets it from Class B - so
an event
model is required.  

in your code, you have a var r in both the "Class
A" and "Class B" - I'm
confused about that.  Thanks for any help.


Jason Merrill
Bank of America 
Learning & Organizational Effectiveness
 
 
 
 
 
 

>>-----Original Message-----
>>From: flashcoders-bounceschattyfig.figleaf.com 
>>[mailto:flashcoders-bounceschattyfig.figleaf.com] On
Behalf 
>>Of Holth, Daniel C.
>>Sent: Friday, February 16, 2007 10:36 AM
>>To: Flashcoders mailing list
>>Subject: RE: [Flashcoders] Events for custom
classes?
>>
>>
>>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&quo
t;, 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: flashcoders-bounceschattyfig.figleaf.com
>>[mailto:flashcoders-bounceschattyfig.figleaf.com] 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
>>
>>
>>
>>
>>_______________________________________________
>>Flashcoderschattyfig.figleaf.com
>>To change your subscription options or search the
archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.c
om
>>
>>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.
>>_______________________________________________
>>Flashcoderschattyfig.figleaf.com
>>To change your subscription options or search the
archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.c
om
>>
_______________________________________________
Flashcoderschattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om

Re: Events for custom classes?
country flaguser name
United States
2007-02-16 13:48:20
do you have a reference to the class that is broadcasting
the event in the 
class that's listening for the event?

meaning, when you write your addEventListener in your
Receiving class, you 
should have:

referenceToBroadcastingClass.addEventListener("myEvent&
quot;,myHandler);
----- Original Message ----- 
From: "Merrill, Jason" <jason.merrillbankofamerica.com>
To: "Flashcoders mailing list" <flashcoderschattyfig.figleaf.com>
Sent: Friday, February 16, 2007 2:35 PM
Subject: RE: [Flashcoders] Events for custom classes?


> Daniel, try as I may, I can't get your code to work.  I
have one class,
> which has a combobox.  I can get the event to fire when
the combobox
> changes just fine, but I can't get it to
"hear" the firing of the data
> capture from the webservice in the other class.
>
> So basically, in pseudocode, I need to do this:
>
> class A{
> make comboBox
> make datagrid
> when comboBox changes, use Class B
> to get data from webservice
> when webservice result received,
>        update datagrid with new data
>
> }
>
> class B{
> connect to webservice
> when requested, return data to requesting class
> }
>
> Reason I want these two classes to be separate is
because I want other
> classes to call Class B to get data as well.  So, I can
do all of those
> things just fine, they are all working, except for the
last part, "when
> requested, return data to requesting class" - I
figure since the
> webservice is asynchronous, I need to capture the
received event, which
> is fine, I can do, that works.  But I need to tell
Class A to update the
> datagrid with the new data when it gets it from Class B
- so an event
> model is required.
>
> in your code, you have a var r in both the "Class
A" and "Class B" - I'm
> confused about that.  Thanks for any help.
>
>
> Jason Merrill
> Bank of America
> Learning & Organizational Effectiveness
>
>
>
>
>
>
>
>>>-----Original Message-----
>>>From: flashcoders-bounceschattyfig.figleaf.com
>>>[mailto:flashcoders-bounceschattyfig.figleaf.com] On Behalf
>>>Of Holth, Daniel C.
>>>Sent: Friday, February 16, 2007 10:36 AM
>>>To: Flashcoders mailing list
>>>Subject: RE: [Flashcoders] Events for custom
classes?
>>>
>>>
>>>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: flashcoders-bounceschattyfig.figleaf.com
>>>[mailto:flashcoders-bounceschattyfig.figleaf.com] 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
>>>
>>>
>>>
>>>
>>>_______________________________________________
>>>Flashcoderschattyfig.figleaf.com
>>>To change your subscription options or search
the archive:
>>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>>
>>>Brought to you by Fig Leaf Software
>>>Premier Authorized Adobe Consulting and
Training
>>>http://www.figleaf.com http://training.figleaf.c
om
>>>
>>>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.
>>>_______________________________________________
>>>Flashcoderschattyfig.figleaf.com
>>>To change your subscription options or search
the archive:
>>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>>
>>>Brought to you by Fig Leaf Software
>>>Premier Authorized Adobe Consulting and
Training
>>>http://www.figleaf.com http://training.figleaf.c
om
>>>
> _______________________________________________
> Flashcoderschattyfig.figleaf.com
> To change your subscription options or search the
archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.c
om 

_______________________________________________
Flashcoderschattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om

RE: Events for custom classes?
country flaguser name
Canada
2007-02-16 14:01:29
Jason,

So if I understand clearly what you want to do is :

>From Class A : (pseudo code following)

class ClassA {
	private var instClassB:ClassB;
	make comboBox
	make datagrid
	function ClassA() {
		instClassB = new ClassB();
		comboBox.onChange = Delegate.create(this,
cbChangeHandler);
		instClassB.addEventListener("webServiceResult",
this);
	}

	function cbChangeHandler(e){
		instClassB.getWSdata(e.value);
	}

	function webServiceResult(evtObj:Object) {
		update datagrid with evtObj.newData
	}

}

class ClassB {
	Decorate with EventDispatcher methods
	dispatchEvent, addEventListener, removeEventListener

	function ClassB() {
		EventDispatcher.initialize(this);
	}
	
	function getWSdata(val) {
		get data from web service
		wsInstance.onResult = Delegate.create(this,
wsResulthandler);
	}
	
	function wsResulthandler(data) {
		this.dispatchEvent({type:"webServiceResult",
newData:data})
// add anything you want to pass in the object
	}
}

Now you have them both communication the way you want

Have fun !

Alain

-----Original Message-----
From: flashcoders-bounceschattyfig.figleaf.com
[mailto:flashcoders-bounceschattyfig.figleaf.com] On
Behalf Of Merrill,
Jason
Sent: 16 février 2007 14:36
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Events for custom classes?

Daniel, try as I may, I can't get your code to work.  I have
one class,
which has a combobox.  I can get the event to fire when the
combobox changes
just fine, but I can't get it to "hear" the firing
of the data capture from
the webservice in the other class.

So basically, in pseudocode, I need to do this:

class A{
	make comboBox
	make datagrid
	when comboBox changes, use Class B
		to get data from webservice
	when webservice result received, 
        		update datagrid with new data

}

class B{
	connect to webservice	
	when requested, return data to requesting class }

Reason I want these two classes to be separate is because I
want other
classes to call Class B to get data as well.  So, I can do
all of those
things just fine, they are all working, except for the last
part, "when
requested, return data to requesting class" - I figure
since the webservice
is asynchronous, I need to capture the received event, which
is fine, I can
do, that works.  But I need to tell Class A to update the
datagrid with the
new data when it gets it from Class B - so an event model is
required.  

in your code, you have a var r in both the "Class
A" and "Class B" - I'm
confused about that.  Thanks for any help.


Jason Merrill
Bank of America
Learning & Organizational Effectiveness
 
 
 
 
 
 

>>-----Original Message-----
>>From: flashcoders-bounceschattyfig.figleaf.com
>>[mailto:flashcoders-bounceschattyfig.figleaf.com] On
Behalf Of Holth, 
>>Daniel C.
>>Sent: Friday, February 16, 2007 10:36 AM
>>To: Flashcoders mailing list
>>Subject: RE: [Flashcoders] Events for custom
classes?
>>
>>
>>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&quo
t;, 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: flashcoders-bounceschattyfig.figleaf.com
>>[mailto:flashcoders-bounceschattyfig.figleaf.com] 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
>>
>>
>>
>>
>>_______________________________________________
>>Flashcoderschattyfig.figleaf.com
>>To change your subscription options or search the
archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.c
om
>>
>>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.
>>_______________________________________________
>>Flashcoderschattyfig.figleaf.com
>>To change your subscription options or search the
archive:
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs
>>
>>Brought to you by Fig Leaf Software
>>Premier Authorized Adobe Consulting and Training 
>>http://www.figleaf.com http://training.figleaf.c
om
>>
_______________________________________________
Flashcoderschattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om


-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.412 / Virus Database: 268.18.0/689 - Release
Date: 2007-02-15
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.412 / Virus Database: 268.18.0/689 - Release
Date: 2007-02-15
 

_______________________________________________
Flashcoderschattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcode
rs

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.c
om

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )