[flexcoders] Re: Custom event--please help me

2008-12-16 Thread Amy
--- In flexcoders@yahoogroups.com, Josh McDonald dzn...@... wrote:

 Don't call new EventDispatcher(), it won't be any real use. The main
 reason you would want to create an instance of EventDispatcher itself 
is
 when you're building a class that is an IEventDispatcher, but 
inherits from
 a base class that is not an IEventDispatcher, because we don't have 
multiple
 inheritance in AS3. When you do that, you need to use something like:
 
 private var myEventDispatcher : IEventDispatcher  = new
 EventDispatcher(this);

My experience with this is that occasionally that will run before the 
constructor and you'll get an error--it seems to be safer to put the 
assignment statement inside the constructor, even though it makes it a 
PIA to have boilerplate IEventDispatcher code that you copy in when you 
want to add event dispatching.



Re: [flexcoders] Re: Custom event--please help me

2008-12-16 Thread Josh McDonald
Well yeah, I don't actually instantiate it like that (as it will always run
before the constructor), I was just showing an example. I have the whole lot
in a .inc file and include it:

http://pastie.textmate.org/340790

-Josh

On Wed, Dec 17, 2008 at 12:17 AM, Amy amyblankens...@bellsouth.net wrote:

 --- In flexcoders@yahoogroups.com, Josh McDonald dzn...@... wrote:
 
  Don't call new EventDispatcher(), it won't be any real use. The main
  reason you would want to create an instance of EventDispatcher itself
 is
  when you're building a class that is an IEventDispatcher, but
 inherits from
  a base class that is not an IEventDispatcher, because we don't have
 multiple
  inheritance in AS3. When you do that, you need to use something like:
 
  private var myEventDispatcher : IEventDispatcher  = new
  EventDispatcher(this);

 My experience with this is that occasionally that will run before the
 constructor and you'll get an error--it seems to be safer to put the
 assignment statement inside the constructor, even though it makes it a
 PIA to have boilerplate IEventDispatcher code that you copy in when you
 want to add event dispatching.


 

 --
 Flexcoders Mailing List
 FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Alternative FAQ location:
 https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
 Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
 Links






-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

Like the cut of my jib? Check out my Flex blog!

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: j...@gfunk007.com
:: http://flex.joshmcdonald.info/
:: http://twitter.com/sophistifunk


[flexcoders] Re: Custom event--please help me

2008-12-15 Thread nathanleewei
BasePanel uses another EventDispatcher instance which is inherit from 
UIComponent.


So U can try 
var basePanel:BasePanel = your BasePanel instance;
basePanel.dispatchEvent(ev); 

instead 

var dipsatcher:EventDispatcher = new EventDispatcher();
dispatcher.dispatchEvent(ev);

And U should have a look at;
http://tech.groups.yahoo.com/group/flexcoders/message/66101
http://www.helihobby.com/html/alon_desingpattern.html
also CairngormEventDispatcher


--- In flexcoders@yahoogroups.com, lorenzo.boaro lore...@... 
wrote:

 Hi
 
 i've a problem..anibody can help me?
 
 i created this class:
 
 public class CompleteEvent extends Event
   {
   private var array:ArrayCollection
 
   public function CompleteEvent(type:String, 
array:ArrayCollection)
   {
   super(type);
   this.array = array;
   }
 
   public override function clone():Event {
   return new CompleteEvent(type, array);
   }
 }
 
 the main class create the array through a socket connection within 
the
 socket listeners for Socket.DATA...in the method listeners dispatch
 the event...
 
 [Event(name=newEvent, type=CompleteEvent)]
 
 public class MainApp{
 
 socket.addEventListeners(ProgressEvent.SOCKET_DATA, socketData);
 ...
 private function socketData(event:Event):void {
 
 ...some code to create array from server data...
   //dispatch event
 var dipsatcher:EventDispatcher = new EventDispatcher();
 var ev:CompleteEvent = new CompleteEvent(newEvent, array);
 
 dispatcher.dispatchEvent(ev);
   }
 }
 
 and this other class listens for the event
 
 public class BasePanel extends Panel
   {
 
   private function dataEventHandler():void {
   trace(Array retrieved);
   }
 
   public function BasePanel()
   {
   super();
   this.addEventListener(newEvent, 
dataEventHandler);
   }
 }
 
 but not working the BasePanel class doesn't listen for the event..
 
 thanks a lot 
 
 Regards 
 Lorenzo






Re: [flexcoders] Re: Custom event--please help me

2008-12-15 Thread Josh McDonald
Don't call new EventDispatcher(), it won't be any real use. The main
reason you would want to create an instance of EventDispatcher itself is
when you're building a class that is an IEventDispatcher, but inherits from
a base class that is not an IEventDispatcher, because we don't have multiple
inheritance in AS3. When you do that, you need to use something like:

private var myEventDispatcher : IEventDispatcher  = new
EventDispatcher(this);

and then you proxy all your implementations of IEventDispatcher methods to
use that, ie:

public function dispatchEvent(event:Event):Boolean
{
return myEventDispatcher.dispatchEvent(event);
}

But the important part is that you create it with the (this) parameter so
the internal stuff knows who is actually the dispatcher of the event in
question, which is important in order to perform the bubble and capture
stages. Without it, nobody will ever be able to catch the events without
having a reference to the instance of EventDispatcher that you create, as it
will have no ties to the object that created it, and it cannot be added to
the display list.

-Josh

On Mon, Dec 15, 2008 at 10:38 PM, nathanleewei nathanlee...@yahoo.comwrote:

 BasePanel uses another EventDispatcher instance which is inherit from
 UIComponent.


 So U can try
 var basePanel:BasePanel = your BasePanel instance;
 basePanel.dispatchEvent(ev);

 instead

 var dipsatcher:EventDispatcher = new EventDispatcher();
 dispatcher.dispatchEvent(ev);

 And U should have a look at;
 http://tech.groups.yahoo.com/group/flexcoders/message/66101
 http://www.helihobby.com/html/alon_desingpattern.html
 also CairngormEventDispatcher


 --- In flexcoders@yahoogroups.com, lorenzo.boaro lore...@...
 wrote:
 
  Hi
 
  i've a problem..anibody can help me?
 
  i created this class:
 
  public class CompleteEvent extends Event
{
private var array:ArrayCollection
 
public function CompleteEvent(type:String,
 array:ArrayCollection)
{
super(type);
this.array = array;
}
 
public override function clone():Event {
return new CompleteEvent(type, array);
}
  }
 
  the main class create the array through a socket connection within
 the
  socket listeners for Socket.DATA...in the method listeners dispatch
  the event...
 
  [Event(name=newEvent, type=CompleteEvent)]
 
  public class MainApp{
  
  socket.addEventListeners(ProgressEvent.SOCKET_DATA, socketData);
  ...
  private function socketData(event:Event):void {
 
  ...some code to create array from server data...
//dispatch event
  var dipsatcher:EventDispatcher = new EventDispatcher();
  var ev:CompleteEvent = new CompleteEvent(newEvent, array);
 
  dispatcher.dispatchEvent(ev);
}
  }
 
  and this other class listens for the event
 
  public class BasePanel extends Panel
{
 
private function dataEventHandler():void {
trace(Array retrieved);
}
 
public function BasePanel()
{
super();
this.addEventListener(newEvent,
 dataEventHandler);
}
  }
 
  but not working the BasePanel class doesn't listen for the event..
 
  thanks a lot
 
  Regards
  Lorenzo
 




 

 --
 Flexcoders Mailing List
 FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
 Alternative FAQ location:
 https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
 Search Archives:
 http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
 Links






-- 
Therefore, send not to know For whom the bell tolls. It tolls for thee.

Like the cut of my jib? Check out my Flex blog!

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: j...@gfunk007.com
:: http://flex.joshmcdonald.info/
:: http://twitter.com/sophistifunk