Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Flex dispatch event example 
 

Below mxml file demonstrates the working of dispatchEvent() method. Method works like a driver that drives the event mentioned in its constructor.

 

Flex dispatchEvent example

                         

The example below demonstrates the working of flex dispatchEvent() method. Method works like a driver that drives the event mentioned in its constructor. This method is used to manually dispatch or run away an event. Method, to dispatch any event on the component can be applied either with the component's id or mouseOver attribute. With mouseOver attribute the method will be used inside the mxml tags. This means with and inside a control tag attribute, mouseOver the method can be dispatched on any component. 

Note:
With id attribute, method can be accessed through inside as well as outside the mxml tags. 
Note: mxml tags are the tags used inside the flex application root tag. eg. Flex component tags like control and container tags.

Syntax for using the method

component's id.dispatchEvent(event_ type, boolean value, boolean value); 

Example for event_type used in the method constructor is MouseEvent.CLICK.
eg:--   b1.dispatchEvent(MouseEvent.CLICK, false ,true);

Inside the method constructor, the first parameter is the event type specified that will be run or dispatch away by the dispatchEvent method and the second and third parameter are optional parameters that accept boolean values true and false.

Now in the example below, when the mouse arrow is passed over the component in which the dispatchEvent  method is invoked,
method dispatches the MouseEvent.CLICK type event on the component. 
With this method, the click based events on components like buttons, check boxes etc can be manually set to run before the MouseEvent.CLICK i.e. mouse click, actually takes place.

 

dispatch.mxml

<?xml version = '1.0' encoding = 'utf-8'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'
                 initialize = 'handler()'>

  <mx:Script>
    
    public function handler():void{
bull.addEventListener(MouseEvent.MOUSE_OVER, dispatcher);
bull.addEventListener(MouseEvent.CLICK, task);
    }

    public function dispatcher(e:Event):void{
  var result:Boolean = bull.dispatchEvent(
    new MouseEvent(MouseEvent.CLICK , false, false));

  }

    public function task(e:Event):void{
      lab1.text += 'Trinity' + '\n';
        txt.text += 'Ne'; 
    }

  </mx:Script>
    
    <mx:Button id = 'bull' label = 'visit over me'/>
    <mx:Label id = 'lab1'/>
    <mx:TextArea id = 'txt' width = '20%
          height = '5%' editable = 'false'/>


    <mx:Script>
      import mx.controls.Alert;

      public function handler1(event:Event):void{
Alert.show('Event ' + event.type + ' has been dispatched'); 
      } 

  </mx:Script>
    <mx:CheckBox id = 'ch' label = 'move arrow over me'
      click = 'ch.addEventListener(MouseEvent.CLICK, handler1)
      mouseOver = 'ch.dispatchEvent(
      new MouseEvent(MouseEvent.CLICK, true, false))'
      selected = 'true'/>

</mx:Application>

 

 

dispatch.swf

 

Download the code

 

                         

» View all related tutorials
Related Tags:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

3 comments so far (
post your own) View All Comments Latest 10 Comments:

learn new from this side

Posted by sabir on Sunday, 11.30.08 @ 22:12pm | #82204

learn new from this side

Posted by sabir on Sunday, 11.30.08 @ 22:11pm | #82203

this side good for learn new

Posted by sabir on Sunday, 11.30.08 @ 22:10pm | #82202

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.