RE: [flexcoders] Matt: Event Propogation - how to bubble up through components??

2006-12-03 Thread Matt Chotin
Well, here's a simple example that demonstrates.  See how the Button is
contained by the application?  This means that the button is a child of
the application in the hierarchy, which means bubbling should go up to
the application.  So a bubbling event will reach the application, and I
have an event listener added to the application.  Voila, everything
works.

 

?xml version=1.0 encoding=utf-8?

mx:Application xmlns:mx=http://www.adobe.com/2006/mxml;
layout=vertical creationComplete=addMeListeners()

mx:Script

![CDATA[

import com.me.MeEvent;

private function addMeListeners():void

{

 
this.addEventListener(MeEvent.REMOTE, meHandler);

}



private function meHandler(event:MeEvent):void

{

out.text += event\n;

}

]]

/mx:Script



mx:Button label=click click=dispatchEvent(new
MeEvent(MeEvent.REMOTE)) /



mx:TextArea id=out /





/mx:Application

 

Even if I add more containers around the button the bubbling still
works.

 

mx:VBox

mx:Panel

mx:Button label=click
click=dispatchEvent(new MeEvent(MeEvent.REMOTE)) /

/mx:Panel

/mx:VBox

 

That's about it!

 

Matt



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of {reduxdj}
Sent: Friday, December 01, 2006 11:15 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Matt: Event Propogation - how to bubble up
through components??

 

Matt:

Am I doing something wrong because my event listeners aren't triggering 
anything... the code is all
the way at the bottom.

If you have a moment. Thanks

Patrick

Matt Chotin wrote:

 If you're using UIComponents then it should work, the events should
 bubble.

 -Original Message-
 From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
mailto:flexcoders%40yahoogroups.com 
 [mailto:flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com  
 mailto:flexcoders%40yahoogroups.com] On
 Behalf Of {reduxdj}
 Sent: Monday, November 27, 2006 8:36 PM
 To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
mailto:flexcoders%40yahoogroups.com
 Subject: Re: [flexcoders] Event Propogation - how to bubble up through
 components??

 Matt:

 I'm adding UIComponents to the display list - I guess that wouldn't
work

 this way.
 What's the best way to propagate a method to UIComponents?

 Can I just create new UIObjects and add them as children to my display
 list or do I have to create class files
 and extend my classes that way?

 As you see I'm relatively new to flex and I thank you for your time.

 patrick

 Matt Chotin wrote:
 
  Is the whole parent hierarchy DisplayObjects? Bubbling will only go
  through UI objects, if you had something that didn't extend
  DisplayObject in there it won't bubble up (all of the Flex visual
  components are DisplayObjects)
 
 
 --
 
  *From:* flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com  
 mailto:flexcoders%40yahoogroups.com 
 [mailto:flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com
mailto:flexcoders%40yahoogroups.com]

  *On Behalf Of [EMAIL PROTECTED] mailto:%2Adj%40reduxdj.org
mailto:%2Adj%40reduxdj.org
  *Sent:* Monday, November 27, 2006 5:39 PM
  *To:* flexcoders@yahoogroups.com
mailto:flexcoders%40yahoogroups.com
mailto:flexcoders%40yahoogroups.com
  *Subject:* [flexcoders] Event Propogation - how to bubble up through
  components??
 
  I'm using bubbling, or at least i think i am to capture an event...
  I've extended the event class to make my own event mechanism. the
  events are being dispatched, however the problem is, that
  I'm adding an event listener to my custom mxml component to receive
  the events and nothing happens. I've probably got something
  backwards...
 
  Isn't there a way to listen to events from the parent document?
 
  Doesn't bubbling set to true allow the event
  to be captured by any component in the order that they are created?
 
  my code is as follows:
 
  var evt:MeEvent = new MeEvent(MeEvent.REMOTE,true);
  dispatchEvent(evt);
 
  ---
 
  package com.me
  {
  import flash.events.Event;
 
  public class MeEvent extends Event
  {
 
 
  public static const REMOTE:String = remote;
 
  public var realTarget:*;
 
  public function MeEvent(type:String, bubbles:Boolean=true,
  cancelable:Boolean=false)
  {
  super(type, bubbles, cancelable);
  }
  }
  }
 
  --
  And inside my custom component this is the event listener.
 
  private function

Re: [flexcoders] Matt: Event Propogation - how to bubble up through components??

2006-12-01 Thread {reduxdj}
Matt:

Am I doing something wrong because my event listeners aren't triggering 
anything... the code is all
the way at the bottom.

If you have a moment.  Thanks

Patrick


Matt Chotin wrote:

 If you're using UIComponents then it should work, the events should
 bubble.

 -Original Message-
 From: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com 
 [mailto:flexcoders@yahoogroups.com 
 mailto:flexcoders%40yahoogroups.com] On
 Behalf Of {reduxdj}
 Sent: Monday, November 27, 2006 8:36 PM
 To: flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
 Subject: Re: [flexcoders] Event Propogation - how to bubble up through
 components??

 Matt:

 I'm adding UIComponents to the display list - I guess that wouldn't work

 this way.
 What's the best way to propagate a method to UIComponents?

 Can I just create new UIObjects and add them as children to my display
 list or do I have to create class files
 and extend my classes that way?

 As you see I'm relatively new to flex and I thank you for your time.

 patrick

 Matt Chotin wrote:
 
  Is the whole parent hierarchy DisplayObjects? Bubbling will only go
  through UI objects, if you had something that didn't extend
  DisplayObject in there it won't bubble up (all of the Flex visual
  components are DisplayObjects)
 
 
 --
 
  *From:* flexcoders@yahoogroups.com 
 mailto:flexcoders%40yahoogroups.com 
 [mailto:flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com]

  *On Behalf Of [EMAIL PROTECTED] mailto:%2Adj%40reduxdj.org
  *Sent:* Monday, November 27, 2006 5:39 PM
  *To:* flexcoders@yahoogroups.com mailto:flexcoders%40yahoogroups.com
  *Subject:* [flexcoders] Event Propogation - how to bubble up through
  components??
 
  I'm using bubbling, or at least i think i am to capture an event...
  I've extended the event class to make my own event mechanism. the
  events are being dispatched, however the problem is, that
  I'm adding an event listener to my custom mxml component to receive
  the events and nothing happens. I've probably got something
  backwards...
 
  Isn't there a way to listen to events from the parent document?
 
  Doesn't bubbling set to true allow the event
  to be captured by any component in the order that they are created?
 
  my code is as follows:
 
  var evt:MeEvent = new MeEvent(MeEvent.REMOTE,true);
  dispatchEvent(evt);
 
  ---
 
  package com.me
  {
  import flash.events.Event;
 
  public class MeEvent extends Event
  {
 
 
  public static const REMOTE:String = remote;
 
  public var realTarget:*;
 
  public function MeEvent(type:String, bubbles:Boolean=true,
  cancelable:Boolean=false)
  {
  super(type, bubbles, cancelable);
  }
  }
  }
 
  --
  And inside my custom component this is the event listener.
 
  private function init():void{
  this.addEventListener(MeEvent.REMOTE, handleEvent);
  }
 
  Thanks for your time,
  Patrick
 
 

 --
 Flexcoders Mailing List
 FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt 
 http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.com 
 http://www.mail-archive.com/flexcoders%40yahoogroups.com
 Yahoo! Groups Links