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