You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by CodeGirl <Mi...@yahoo.com> on 2014/12/06 22:15:37 UTC

Bubbling to a Grandparent

I have created mxml files which contain datagrids for my web service data
tables.   for this question, we are going to call these files parent files. 
I have also created AS files to hold the data and the service calls to
obtain the data.  For this question, we are going to call these files child
files.   When I design a screen, I create a mxml file which instantiates
multiple of the mxml files which contain the datagrids I wish for this view. 
For this question, we are going to call these files Grandparent files.
 
So, I have a "GrandParent" mxml file which contains an instance of a second
mxml file:

<fx:Metadata>
	[Event(name="tripChanged", type="events.ChangeTrip")]
</fx:Metadata>
	
<fx:Script>
<![CDATA[
protected function tripsDG_tripChangedHandler(event:ChangeTrip):void
{
	tripLegsDG.tripID = event.tripID;
}
			
<s:VGroup width="100%" height="75%">
		
		<dg:TripsDG id="tripsDG"
					 width="100%" height="66%"
					 tripChanged="tripsDG_tripChangedHandler(event)"
					 />

In the "Parent" mxml file called TripDG I have the change event for the
datagrid:

			protected function tripsDG_changeHandler(event:ListEvent):void
			{
				var eventObject:ChangeTrip = new ChangeTrip("tripChanged",
tripsDG.selectedItem.id);
				dispatchEvent(eventObject);
			}
			
Also in the "Parent" mxml file when a new item is entered and it is saved to
the webservice and the result is returned and the result event is triggered
then I dispatched another changeTrip event to reflect the newly assigned id
which is assigned by the Database when a new record is saved.

When this was all I had, this was working fine.   But when I moved the
datalist and the service calls to my "Child" AS file, this is when things
stopped working.

At first, I realized when I dispatched the event in the AS file, it was not
being seen by the "Parent" MXML file.   And so I bubbled the event and sure
enough, it was bubbled to the "parent"   Except when I was debugging, I
noticed the new id was not available yet in the result event which I am not
sure why but evidently this was no problem when the result function was in
the mxml file because it was bound by probably some pointer and so when the
lastresult was finally available then the datagrid was updated and then
evidently somehow the "GrandParent" was being updated as well.  

Here is the "Child" AS :

		protected function setTripResult_resultHandler(event:ResultEvent):void
		{
			if (event.result != null)
			{
				var thisDTO:TripDTO = setTripResult.lastResult;
				if (dataList[indx].id == 0)
				{
					dataList[indx] = thisDTO;
					var eventObject:ChangeTrip = new ChangeTrip("tripChanged", thisDTO.id,
true);
					var dispatch:EventDispatcher = new EventDispatcher();
					dispatch.dispatchEvent(eventObject);
				}
				if (thisDTO.archived != null)
				{
					dataList.removeItemAt(indx);
				}
				Alert.show(updateSuccessMessage);
			}
		}
	
So, it looks like the "Child" as file is bubbling up the tripChanged event
to the "Parent" MXML file except at that moment, it only has the id as 0
instead of the return id value.   But since the event is no longer in the
"Parent" mxml file, it seems as if the link is broke some how and the event
and data is not bubbled up the "GrandParent".   I discovered this because I
put a break point to test it and it never triggered.   So, with all this
said, Does anyone know how I can make the connections so when the result
event is triggered in the "Child" As file that the tripChange event is then
fired in the "GrandParent" mxml file?




--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by CodeGirl <Mi...@yahoo.com>.
I have it working.   Maybe not bubbling though, I am having to repeat it in
the parent.   but I am not sure what I did to get it to work.   I will play
around and see if I can figure out what it was I did to get it to work and
post back the answer.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9102.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by CodeGirl <Mi...@yahoo.com>.
In my example, I am not using a web service, but in my real code I am.   the
problem with dispatching the event in the mxml file is that there is no
guarantee the web service has returned the new id when creating a new
record.   hence why I have it being dispatched in the aAs.as file when
supposedly, the new id number should be returned on the result event.  
Though for some reason, its not there like it should and how it was when I
did everything in the mxml file prior to moving my code to the actionscript
file hence why there is a second question posted as to why my result does
not contain the result.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9039.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by Prabhu Moorthy <Pr...@symphonysummit.com>.
You can remove the change event listener from A.mxml file. Listen the event
in Grandparent Example.mxml file as
/asDG.aAs.addEventListener(ChangeA.CHANGED, asDG_aChangedHandler);/

But in A.mxml file dispatch the same event when datagrid change. Once again
you need to add event listener in Grandparent Example.mxml file as
/asDG.addEventListener(ChangeA.CHANGED, asDG_aChangedHandler);/

Better don't dispatch event from As.as. Use As.as as Data model add or
update the data. Dispatch all events from A.mxml. So one event listener is
enough in Grandparent Example.mxml file as
/asDG.addEventListener(ChangeA.CHANGED, asDG_aChangedHandler);/

Change below method in A.mxml file as
protected function aUpdateBtn_clickHandler(event:MouseEvent):void
{
      if (asDG.selectedIndex > -1)
     {
	aAs.setA(asDG.selectedIndex);
             dispacthChangeEvent(aAs.getID());//get id from As.as
      }
}

protected function asDG_changeHandler(event:ListEvent):void
{
     dispacthChangeEvent(asDG.selectedItem.id);
}

private function dispacthChangeEvent(id:int):void
{
     dispatchEvent(new ChangeA("aChanged", id));
}
			



-----
Thanks & Regards,
M.Prabhu
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9025.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by CodeGirl <Mi...@yahoo.com>.
Why do I need to keep the repeater in A.mxml?   I thought bubbling would go
all the way to the Grandparent Example.mxml.   Or is there a better way?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9017.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by CodeGirl <Mi...@yahoo.com>.
Thanks for the answer.  Is there any hit to doing this?   Do you know why
they didnt just do this as default?   I take it the mxml files have this by
default



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9016.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

RE: Bubbling to a Grandparent

Posted by Prabu Moorthy <Pr...@symphonysummit.com>.
Hi,

Change the dispatch event code in As.as.

public class As  extends EventDispatcher
{
.
.
.
.
		public function setA(ndx:int):void
		{
			this.indx = ndx;
			aDTO = new ADTO();
			aDTO.id = 502;
			aDTO.name = "Saved Item";
			dataList[indx] = aDTO;
			var thisDTO:ADTO = dataList[indx];
			var eventObject:ChangeA = new ChangeA("aChanged", thisDTO.id, true);
			/*var dispatch:EventDispatcher = new EventDispatcher();
			dispatch.dispatchEvent(eventObject);*/
			dispatchEvent(eventObject);
			//Alert.show(updateSuccessMessage);
                                             //setAResult.token = service.storeA(aDTO);
		}
.
.
.

}

Thanks & Regards,
M.Prabhu

-----Original Message-----
From: CodeGirl [mailto:MichelleNicholes@yahoo.com] 
Sent: Monday, December 08, 2014 4:17 AM
To: users@flex.apache.org
Subject: Re: Bubbling to a Grandparent

example.zip
<http://apache-flex-users.2333346.n4.nabble.com/file/n9004/example.zip>  

Here is an example of what I am doing and the issue I am trying to solve with the latest of what I have.

When the app loads, hit the new button and then the update button.   Notice
that the Bs does not update to an empty Datagrid.   This shows the
GrandParent is not being called.   Any help getting this to work would be
appreciated.

I created the Actionscript files for reusability as displayed in the lookup names.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9004.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Bubbling to a Grandparent

Posted by mprabhu <Pr...@symphonysummit.com>.
Hi,

Extend the class from EventDispatcher and dispatch the event.

public class As  extends EventDispatcher { .
.
.
.
		public function setA(ndx:int):void
		{
			this.indx = ndx;
			aDTO = new ADTO();
			aDTO.id = 502;
			aDTO.name = "Saved Item";
			dataList[indx] = aDTO;
			var thisDTO:ADTO = dataList[indx];
			var eventObject:ChangeA = new ChangeA("aChanged", thisDTO.id, true);
			/*var dispatch:EventDispatcher = new EventDispatcher();
			dispatch.dispatchEvent(eventObject);*/
			dispatchEvent(eventObject);
			//Alert.show(updateSuccessMessage);
                                             //setAResult.token =
service.storeA(aDTO);
		}
.
.
.

}




-----
Thanks & Regards,
M.Prabhu
--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9007.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Bubbling to a Grandparent

Posted by mprabhu33 <Pr...@symphonysummit.com>.
example_working.zip
<http://apache-flex-users.2333346.n4.nabble.com/file/n9005/example_working.zip>  

See the attachment.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9005.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Bubbling to a Grandparent

Posted by CodeGirl <Mi...@yahoo.com>.
example.zip
<http://apache-flex-users.2333346.n4.nabble.com/file/n9004/example.zip>  

Here is an example of what I am doing and the issue I am trying to solve
with the latest of what I have.

When the app loads, hit the new button and then the update button.   Notice
that the Bs does not update to an empty Datagrid.   This shows the
GrandParent is not being called.   Any help getting this to work would be
appreciated.

I created the Actionscript files for reusability as displayed in the lookup
names.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-tp8997p9004.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Bubbling to a Grandparent

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

I assume you're setting bubbles to true.  Does your event class have a clone method?

Justin

Re: Bubbling to a Grandparent

Posted by Alex Harui <ah...@adobe.com>.
Hi,

I’m not sure I fully got it, but I noticed one thing:  Bubbled events
rarely, if ever, get dispatched again.  It looks like a ChangeTrip event
gets dispatched by Child and then again by Parent.  Bubbles bubble to the
top, so dispatching once from Child should bubble through the Parent and
then on to the GrandParent.

Even with that, you may also be facing timing issues around the way
components react to change events.  Properties like
selectedIndex/selectedItem may not be updated the instant you change the
datalist.  The DG  may need to call validateNow() on itself to fully
update before the grandparent gets the event.

HTH,
-Alex

On 12/6/14, 1:15 PM, "CodeGirl" <Mi...@yahoo.com> wrote:

>I have created mxml files which contain datagrids for my web service data
>tables.   for this question, we are going to call these files parent
>files. 
>I have also created AS files to hold the data and the service calls to
>obtain the data.  For this question, we are going to call these files
>child
>files.   When I design a screen, I create a mxml file which instantiates
>multiple of the mxml files which contain the datagrids I wish for this
>view. 
>For this question, we are going to call these files Grandparent files.
> 
>So, I have a "GrandParent" mxml file which contains an instance of a
>second
>mxml file:
>
><fx:Metadata>
>	[Event(name="tripChanged", type="events.ChangeTrip")]
></fx:Metadata>
>	
><fx:Script>
><![CDATA[
>protected function tripsDG_tripChangedHandler(event:ChangeTrip):void
>{
>	tripLegsDG.tripID = event.tripID;
>}
>			
><s:VGroup width="100%" height="75%">
>		
>		<dg:TripsDG id="tripsDG"
>					 width="100%" height="66%"
>					 tripChanged="tripsDG_tripChangedHandler(event)"
>					 />
>
>In the "Parent" mxml file called TripDG I have the change event for the
>datagrid:
>
>			protected function tripsDG_changeHandler(event:ListEvent):void
>			{
>				var eventObject:ChangeTrip = new ChangeTrip("tripChanged",
>tripsDG.selectedItem.id);
>				dispatchEvent(eventObject);
>			}
>			
>Also in the "Parent" mxml file when a new item is entered and it is saved
>to
>the webservice and the result is returned and the result event is
>triggered
>then I dispatched another changeTrip event to reflect the newly assigned
>id
>which is assigned by the Database when a new record is saved.
>
>When this was all I had, this was working fine.   But when I moved the
>datalist and the service calls to my "Child" AS file, this is when things
>stopped working.
>
>At first, I realized when I dispatched the event in the AS file, it was
>not
>being seen by the "Parent" MXML file.   And so I bubbled the event and
>sure
>enough, it was bubbled to the "parent"   Except when I was debugging, I
>noticed the new id was not available yet in the result event which I am
>not
>sure why but evidently this was no problem when the result function was in
>the mxml file because it was bound by probably some pointer and so when
>the
>lastresult was finally available then the datagrid was updated and then
>evidently somehow the "GrandParent" was being updated as well.
>
>Here is the "Child" AS :
>
>		protected function setTripResult_resultHandler(event:ResultEvent):void
>		{
>			if (event.result != null)
>			{
>				var thisDTO:TripDTO = setTripResult.lastResult;
>				if (dataList[indx].id == 0)
>				{
>					dataList[indx] = thisDTO;
>					var eventObject:ChangeTrip = new ChangeTrip("tripChanged",
>thisDTO.id,
>true);
>					var dispatch:EventDispatcher = new EventDispatcher();
>					dispatch.dispatchEvent(eventObject);
>				}
>				if (thisDTO.archived != null)
>				{
>					dataList.removeItemAt(indx);
>				}
>				Alert.show(updateSuccessMessage);
>			}
>		}
>	
>So, it looks like the "Child" as file is bubbling up the tripChanged event
>to the "Parent" MXML file except at that moment, it only has the id as 0
>instead of the return id value.   But since the event is no longer in the
>"Parent" mxml file, it seems as if the link is broke some how and the
>event
>and data is not bubbled up the "GrandParent".   I discovered this because
>I
>put a break point to test it and it never triggered.   So, with all this
>said, Does anyone know how I can make the connections so when the result
>event is triggered in the "Child" As file that the tripChange event is
>then
>fired in the "GrandParent" mxml file?
>
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/Bubbling-to-a-Grandparent-t
>p8997.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.