Hi,
 
When you extend UIComponent, it comes with event dispatching capabilities. So you don't need to use EventDispatcher.initialize(this) kind of mixin.
 
You need to add [Event("eventName")] metadata in your class/component and just use dispatchEvent(..) method directly. No need to use Delegate inside your class, compile generates the code for you with right scope.
 
Also you don't need to execute the event-handlers in your code by getting the reference of event-handler. Everything is done automatically...
 
Check out following link to see how to dispatch event correctly. You probably need to less code that you write  than you write pure Flash because Flex makes your life little easier :)
 
http://livedocs.macromedia.com/flex/15/flex_docs_en/00000985.htm
 
If you still have any problem, let us know.
 
-abdul
 
 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ramu p
Sent: Tuesday, October 18, 2005 4:32 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Is it the right way of using dispatchEvent?

Hi Flex coders,
 
Thanks a lot to all group people for solving my problem on "Issue on Accordion reference".
 
I am stuck up with one more problem.
 
Here is the problem,
 
I have a simple mxml file which uses a component(circle.as) , extends UIComponent.
OnPress of this circle I want to invoke a method that user has provided.
i.e, I included "circle" component in my xmxl in the following way.
 
<circle xmlns:circle="*" cirPress="fun"/>
 
So here "circle" is an as component which has cirPress event which has to invoke fun method in mxml file.
 
Here is the code of mxml file:
//**************************************************************************

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
 <mx:Script>
      <![CDATA[
         function fun(){
            mx.controls.Alert.show("Event dispatched!")
         }
      ]]>
 </mx:Script>
<circle xmlns:circle="*" cirPress="fun"/>

</mx:Application>

//**************************************************************************

Here is component (circle.as)

//**************************************************************************

// ActionScript Document
import mx.core.UIComponent
import mx.utils.Delegate
import mx.events.*
class circle extends UIComponent{
  public var dispatchEvent:Function
  
  [Embed(source="cir_sym.swf",symbol="cir_sym")]
  var cir_sym:String;
  
  var obj:Object
  var cirPress
  
  function circle(){
  }
  
  function init():Void{
   super.init();
   EventDispatcher.initialize(this);
  }
  function draw():Void{
   super.draw();
  }
  
  function createChildren():Void{
   obj = attachMovie("cir_sym","cir_sym",1);
   addEventListener("cirPressed",Delegate.create(this,tempFun))
  }
  
  function tempFun(){
   eval("_root."+cirPress).call()
  }
  
  function onPress():Void{
    dispatchEvent({type:"cirPressed"})
  }
  
   
  
}

//**************************************************************************

 

Here the above works well!!!
But problem is I shouldnt use "_root." to invoke the method! (coz method my be in a class/somewhere. So everytime method may not be in root)
 
 
And please suggest me, is it the right way of using dispatchEvent()?
I really appreciate one's help on "how to use dispatchEvent in appropriate way".
 
Thanks in advance!
 
Regards,
Ramu
 
 


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




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to