Dispatching an ItemClick event from a chart

I am trying to provide a simple drill down by getting a name
from a pie slice and then putting the slices contents in a datagrid
based on that name as a filter.
I am trying to use an event dispatcher and an event listener,
but im not exactly sure im doing it right.
The dispatcher would dispatch when something is clicked, and
the string item of what is clicked would be passed into the
remote object. (Not sure how the ItemClick string is passed
by an event)
I know i'm a newb with events.... thanks for any input.
here is the chart component
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="
http://www.adobe.com/2006/mxml"
title="Defect Chart (Status not Closed)" layout="absolute"
width="100%" height="100%">
<mx:Script>
<![CDATA[
import mx.charts.ChartItem;
import mx.collections.ArrayCollection;
//Label function for the Defect Pie Chart
private function labels(dataItem:Object, field:String
,Index:int, dataPercent:Number ):String
return dataItem.BG_SEVERITY + " " + dataItem.CNT;
private function ItemClick(name:String):void
dispatchEvent(new ChartItemEvent.);
trace("event is dispatched");
]]>
</mx:Script>
<mx:PieChart id="DefectPie"
width="100%"
height="100%"
showDataTips="true"
y="40"
itemClick="{ItemClick(event.hitData.chartItem.item.toString())}"
>
<mx:series>
<mx:PieSeries id="series"
field="CNT"
nameField="BG_SEVERITY"
labelPosition="callout"
labelFunction="labels"
>
This is called in main's init()
this.addEventListener("name" , ItemClickHandler);
And this is the handler function:
private function ItemClickHandler(event:Event):void
trace(event);
dataManager.soe_bug_list_detail(event['BG_SEVERITY']);
}

JoeADSK,
This might sound like a bit over-kill but you might go ahead
and use a seperate EventHandler class and a DTO(Data Transfer
Object) class to accomplish the event even though you are simply
sending 1 piece of data.
Here is an example if you need one:
==Event Handler Class==
package event
import flash.events.Event;
import myApp.dto.ChartItemDTO;
public class ChartClickEvent extends Event
public var chartName:ChartItemDTO;
public function ChartClickEvent(chartName:ChartItemDTO,
type:String)
super(type);
this.chartName = chartName;
override public function clone():Event
return new ChartClickEvent(chartName, type);
DTO Class:
package myApp.dto
public class ChartItemDTO
public var name:String;
public function ChartItemDTO(name:String)
this.name = name;
Here is how you use it in your mxml for or whatever:
import event.ChartClickEvent;
import myApp.dto.ChartItemDTO;
DONT FORGET TO ADD THIS EVENT BLOCK:
<mx:Metadata>
[Event(name="chartName", type="event.ChartClickEvent")]
</mx:Metadata>
HERE IS AN EXAMPLE FUNCTION NON-WORKING===
private function setChartName(name:String):void
var chrtName:ChartItemDTO = new ChartItemDTO(name);
var chrtClickEvent:ChartClickEvent = new
ChartClickEvent(chrtName, "chartName");
dispatchEvent(chrtClickEvent);
Now this is just hacked together quickly not a working model
but you will get the idea.
Basically the event must be passed a Data Transfer Object to
hand off from the Click event.
Like I said this is over-kill but a good place to start as
you venture forth in the the Event Handling world in Flex.
Good luck, hope this helps,
Kenny

Similar Messages

  • How Do I Programmatically Dispatch an Itemclick Event in Flex 3?

    Hi,
    I need some help with programmatically dispatching an itemclick event in Flex 3.
    For example, I've got a popupmenubutton as follows:
    <mx:PopUpMenuButton
        id="myPopUpMenuButton"
        label="Neighborhoods"
        dataProvider="{myNeighborhoodList}"
        itemClick="myPopUpMenuButtonClickHandler(event)"
    />
    Let's say that the myNeighborhoodList contains 3 choices: Old Port, Newport, Southport.
    In another piece of code, I want to programmatically dispatch the myPopUpMenuButton itemclick event as if "Newport" were chosen. How do I do that?
    FYI, I posted this question on Stack Overflow, but I didn't get a reply.
    Thank you!
    -Laxmidi

    Ok , here is how I solve the problem architecturally.  One class should be responsible for the viewstack index.  This class can respond to events dispatched anywhere.  So it goes a little something like this.
    The view stack
    <Viewstack selctedIndex="{stackIndex}">
      <Script>
          [Bindable] public var stackIndex:int;
       </Script>
      <ViewOne />
      <ViewTwo/>
      <ViewThree />
    </Viewstack/>
    StackPresentation.as
    public var stackCount:int;
    [Bindable] public var stackIndex:int;
    public function startUp():int
        stackIndex = someRandomNumberGenerator( 0 , stackCount );
         return stackIndex;
    public function changeStackHandler( newStackIndex:int ):void
        stackIndex = newStackIndex;
    There are a few things I must explain here.
    1.  The stackIndex of the StackPresentation class in "injected" into the Viewstack class.  This can be accomplished using a number of frameworks.  Personally I use Mate , but there is a whole cornucopia of DI frameworks ( Prana , RobotLegs , Swiz ...).
    2.  When you want to change the stack index from any part of the application , you dispatch an event like the one I posted earlier.  Your framework will wire this event to the StackPresentation.  The event will have some parameters ( i.e var newStackIndex:int ) which it uses to go to the next stack index , it could very well be different from what I posted as this is an example.
    The advantages of this are numerous.  But they all stem from "separation of concern".   The view class is responsible for being a view , and the presentation is responsible for coordinating the state of the view class.  The other advantage is that if some other part of the application wants to change the viewstack index , it MUST go through the presentation layer , preventing a "ball of mud" type of approach.  This greatly cuts down on the number of bugs and the time it takes to resolve them.  In scenarios where there is a problem , you only have to look at a few things , the logic in the presentation class ( which lends itself to unit-testing) and the cases where the event triggering the change is dispatched.  Hope this helps.
    Sincerely ,
      Ubu

  • [svn:fx-trunk] 12818: The MX TabBarAccImpl now sends the MSAA event EVENT_OBJECT_SELECTION followed by EVENT_OBJECT_FOCUS when the TabBar dispatches an  "itemClick" event.

    Revision: 12818
    Revision: 12818
    Author:   [email protected]
    Date:     2009-12-10 16:20:49 -0800 (Thu, 10 Dec 2009)
    Log Message:
    The MX TabBarAccImpl now sends the MSAA event EVENT_OBJECT_SELECTION followed by EVENT_OBJECT_FOCUS when the TabBar dispatches an "itemClick" event. Previously it only sent EVENT_OBJECT_SELECTION.
    QE notes: None
    Doc notes: None
    Bugs: SDK-17927
    Reviewer: Jon, Hans
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-17927
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/accessibility/TabBarAccImpl.as

    Can't solve your immediate problem, but thought this might be of interest.
    I created a tutorial on converting the Adobe Flex 3 example Dashboard application to Flex 4.
    The tutorial is here:
    http://stardustsystems.com/learning/flex4/tutorials/portDashboardToFlex4/index.html
    There are links to the tutorial PDF, the converted applicaton, and the source code.
    Hope this helps someone.
    http://www.stardustsystems.com
    http://www.stardustsystems.com/blog

  • Dispatching a simple event from classB to ClassA

    Hi,
    I have read at multiple places tutorials/explanations on the EventDispatcher use in AS3 and that confuses me a lot. I would appreciate a lot if somebody could show me in the simple exemple below how I should do to just send a simple message from a ClassB to a Class A. In the exemple below that I made, I have classA that calls classB to send a message that ClassA then gets. Of course, I simplified to the minimum the 2 classes to allow focusing on the problem. Currently, the exemple does NOT work, i.e. the line "trace ("message was received!");" is not executed.
    I saw in several exemples on the web that some put the addEventListener on the EventDispatcher object. I do not understand the logic behind this, I would put the addEventListener on the objects that will receive the message.
    I wonder also why can't I just put an addEventlistener at the ClassA constructor "addEventListener("hello", receivedHello);" and then send a dispatchEvent from classB. I tried that as well but it does not work.
    package {
        import flash.display.MovieClip;
        import flash.events.Event;
        public dynamic class ClassA extends MovieClip{
            public function ClassA(){
                ClassB.getClassB().registerUser(this);
                ClassB.getClassB().sendMessage();
            public function receivedHello(e:Event){
                trace ("message was received!");
    package{
        import flash.events.Event;
        import flash.events.EventDispatcher;
        class ClassB {
            public var sender:EventDispatcher;
            // constructor
            public function ClassB() {
                sender= new EventDispatcher();
            // function getClassB() to be sure only one instance of this class is running
            public static function getClassB():ClassB {
                if (ClassB._instance == null) {
                    ClassB._instance = new ClassB();
                return ClassB._instance;
            public function registerUser(user:Object){
                user.addEventListener("hello", user.receivedHello);
            public function sendMessage(): void {
                sender.dispatchEvent(new Event("hello"));
    Thanks so much in advance for your help
    Pieter

    package {
        import flash.display.MovieClip;
        public dynamic class ClassA extends MovieClip{
            public function ClassA(){
               addEventListener("customEvent",f);
            function f(e:Event){
                trace("event received");
    package{
       import ClassA;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        class ClassB {
            // constructor
            public function ClassB() {
                 var a:ClassA = new ClassA();
                 a.dispatchEvent(new Event("customEvent"))

  • Dispatch custom event from itemClick handler

    hi,
    I'm trying to dispatch a custom event from my itemClick handler.
    So when I click on an item of my datagrid, I want to send a custom event.
    private function dataGridItemClickHandler( event:ListEvent): void
         dispatchEvent( new myEvent( myEvent.NEW, values[event.columnIndex]["name"]) );
    <mx:DataGrid dataProvider="{values}" itemClick="dataGridItemClickHandler(event)">
    </mx:DataGrid>
    but this code doesn't work.
    Can you help me
    thanks
    best regards

    Please see that you override the function clone() and return the new function.If that is correct.you can call the super() method to initialize your base class.
    If your custom event {myEvent} is in package say: CustomEvent,
    1)import package CustomEvent.myEvent
    2) keep in <mx:metadata>[Event(name="NEW", type="CustomEvent.myEvent")]</mx:metadata>.. name suggest  what type of event you want
    3)Create an itemclick listener and in dataGridItemClickHandler
    private function dataGridItemClickHandler( event:ListEvent): void
         dispatchEvent( new myEvent( ' NEW ', values[event.columnIndex]["name"]) );
    private funcation myEventListener(evt:myEvent):void
    //Put your logic
    4)Use this event by name NEW="myEventListener(event)"  this will behave as event type in the datagrid tag like click, hover and others.
    Hope this helps! Please excuse if anything is logically incorrect.Do point out.Thanks.

  • Avoiding first select event from chart ?

    Hi,
    I trigger a select event from a chart to another BI query to drill down into details. Unfortunately, when the chart is build up, without any user interaction a first select event is already triggered. Is it possible to avoid this event (for instance by a guard condition) ?
    Regards, Christian

    Hi Christian
    Sorry about the delay. The solution here is to use a data store and a guard condition, the data store should be triggered on the first select event in the chart, its default value should be itself+1, this means that when the first select event is triggered the value will be 1, you can then use your guard condition to check for this and only if the value is greater than 1 it should continue.
    Jarrod Williams

  • Prevent PopUpMenuButton itemClick Event

    Hi Guys,
    I have a PopUpMenuButton where I would like to prevent the itemClick event from being triggered if the button itself is clicked (not the drop-down with the list of menu items). According to Adobe Live Docs clicking the button fires off the click event, and then also triggers the itemClick event.
    How can I prevent the itemClick event from firing?
    My reasoning is this: I only want the popupmenubutton to display the dropdown list when the button portion is clicked, not do any other processing. It should behave just as if the drop-down button to the right was clicked, exposing the drop-down list of menu items.
    Instead, what happens now if I click the button section is that it shows the drop-down list, but then also fires off the itemClick event, acting as if I selected the first item in the drop-down list (since that is highlighted by default when the list is exposed).
    Thanks!

    That is what I have right now:
         <mx:Script>
              <![CDATA[
                   private function toolClickHandler(event:MenuEvent):void
                        switch(event.label)
                             case "Password Generator":
                                  var window:PasswordGenerator = PopUpManager.createPopUp(this, PasswordGenerator, true) as PasswordGenerator;
                                  PopUpManager.centerPopUp(window);
                                  break;
              ]]>
         </mx:Script>
         <mx:XMLList
              id="xl_tool_menu">
              <node
                   label="Tools"
              />
              <node
                   label="Calculator"
              />
         </mx:XMLList>
         <mx:PopUpMenuButton
              id="pmb_tools"
                    label="Tools"
              labelField="@label"
              dataProvider="{xl_tool_menu}"
                    click="this.pmb_tools.open();"
              itemClick="toolClickHandler(event);"
         />
    However, since Password Generator is the only item in the list, it appears to handle it as always selected, meaning that event.label will always result in "Calculator".

  • [svn:osmf:] 14474: Adding a 'dispatchInitialChangeEvent' parameter to the ' watch' method in order to allow the initial change event from being dispatched, continued.

    Revision: 14474
    Revision: 14474
    Author:   [email protected]
    Date:     2010-02-28 23:53:31 -0800 (Sun, 28 Feb 2010)
    Log Message:
    Adding a 'dispatchInitialChangeEvent' parameter to the 'watch' method in order to allow the initial change event from being dispatched, continued.
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/MetadataWatcher.as

    *Feedback*
    "Use the form below to send us your comments. We read all feedback carefully, but please note that we cannot respond to the comments you submit."
    http://www.apple.com/feedback/ipad.html
    We can complain about Apple's business decisions, but these discussions are user to user talk about possible solutions.
    Here are the places to report bugs:
    Get an account at
    http://developer.apple.com/  then submit a bug report to http://bugreporter.apple.com/
    Once on the bugreporter page,
       -- click on New icon
       -- See if you need to attach a log file or log files, clicking on Show instructions for gathering logs.  Scroll down to find the area or application that matches the problem.
       -- etc.

  • [svn:osmf:] 14473: Adding a 'dispatchInitialChangeEvent' parameter to the ' watch' method in order to allow the initial change event from being dispatched.

    Revision: 14473
    Revision: 14473
    Author:   [email protected]
    Date:     2010-02-28 23:45:28 -0800 (Sun, 28 Feb 2010)
    Log Message:
    Adding a 'dispatchInitialChangeEvent' parameter to the 'watch' method in order to allow the initial change event from being dispatched.
    Modified Paths:
        osmf/trunk/framework/OSMF/org/osmf/metadata/MetadataWatcher.as

    Perhaps you're not handling the "EndOfStreamEvent" correctly/at all, and thus not freeing up the socket to listen for the "NewReceiveStreamEvent " after the initial stream has ended...
    ?

  • Dispatching an event from a command

    Hi,
    In one for my commands in the Cairngorm based application I'm working on I need to dispatch a event to amend the view. In my command I'm amending some value objects in a ArrayCollection, which is the data source for a List component in my view. Once I completed my changes to these value objects I'd like to dispatch a event to resort the ArrayCollection and update my view to the new order.
    What is the best approach for dispatching an event in the command?
    Thanks
    Stephen

    Great question - I'm currently sorting out how to do this myself.  I'm new to Cairngorm but have a decent amount of experience with Flex.  Here are my thoughts:
    Cairngorm promotes decoupling of the data model and front controller/commands from the view - which is appropriate for an MVC framework. Data binding supports this seperation (to an extent) and keeps the view up to date with the model in 'real time'.  Data binding does not however provide an intuitive mechanism for reacting to cairngorm event results.  So here a few solutions I've been tossing around:
    1.  Rely on Built in Flex events such as the datagrid's dataChange event to trigger a reaction.
    2.  Create view state variables in the model that, when changed through the front controller / commands, dispatch custom events from within their VO's / setters / ect.
    3.  Dispatch custom events directly from front controller / commands.
    4.  Create custom (or override existing) item renderers that self-transition / tween when changed as a result of data binding.
    I'm sure there are other ways to do what we want, but I'm out of ideas.  Which approach to take very well depends on how strongly you'd like to adhere to the MVC concept.  Commands that dispatch generic events as their messages may or may not be acceptable to you - but they provide a straitforward way to trigger view related reactions without relying on data binding events.  I'd be interested to know if Cairngorm 3 will address this challenge...
    Let me know what you decide on if and when you make a choice!

  • Dispatching an event from a MovieClip???

    Hello, can somebody tell me if there is a way to dispatch an
    event from a Movieclip?, I tried to dispatch an event from a class
    and all ran ok. But now, if I have a Movieclip on my scenario and I
    want that when it arrive to "x" frame it dispatch an event that
    could be catched by a listener on the _root, what I have to do?
    (without doing use of classes), thanks a lot.

    Try the following. On the first frame of the movieclip place
    the following code.
    // Event Routines //
    var dispatchEvent:Function;
    var addEventListener:Function;
    var removeEventListener:Function;
    mx.events.EventDispatcher.initialize(this);
    Then on the "x" frame of the movieclip, place the following
    code:
    var evt:Object = new Object();
    evt.type = "framereached"; // this can be whatever you wish
    to listen for
    evt.target = this;
    dispatchEvent(evt);
    This is how you would do this in a class and it should work
    just as well if coded directly onto a frame. However, to make this
    more versatile I would place it in a class with a public function,
    for example, name throwEvent(). This public method would then
    execute the above code and could be called from any frame. You
    could even add another item to the evt object that would contain
    the frame the executed the event.
    Tim

  • Retriving value from Pie chart to hidden field using onmouseover event

    Hi,
    I am Vaibhav. I have create Pie chart on EMP table. Pie chart query is as follows,
    SELECT 'javascript:onmouseover=$x(''P25_DEPTNO'').value='||deptno||';popupURL(''http://www.google.com'');' LINK,
    deptno, COUNT (empno)
    FROM emp
    GROUP BY deptno
    On mouseover on Pie chart i want to get value of deptno column but from above query i am not getting the value of deptno. So how should I get value of deptno on mouseover event on Pie chart.
    Thanks in advance,
    Regards,
    Vaibhav
    Edited by: user10600404 on Feb 28, 2011 10:39 PM

    Hi,
    I can get it to work with:
    SELECT 'javascript:onclick=$x("P24_DEPTNO").value='||deptno||';popupURL("http://www.google.com");' LINK,
    deptno, COUNT (empno)
    FROM emp
    GROUP BY deptno That is - using onclick instead of onmouseover.
    See: http://apex.oracle.com/pls/otn/f?p=9568:24 - the Select list is updated as you click on a slice in the pie chart
    Andy

  • How to dispatch custom events from an item renderer used for Datagrid Column

    Hi,
    I am using an Item Renderer for a Data Grid Column and in that mxml, I am dispatching a custom event with data.
    But the main mxml which has the DataGrid is not able to resolve the event. How can I solve this?
    Thanks

    Hi,
    This is the constructor for Event.
    public function Event(type:String, bubbles:Boolean  = false, cancelable:Boolean  = false)
    When you created your custom event after extending from Event, for the parent container receives the event, the bubbles property must be set to true.
    Please check if you have done so. That should solve the problem. Let me know if it doesn't.
    Nishad

  • If OSMFSettings.enableStageVideo true, then click event from the MediaContainer is not dispatch.

    Hi!
    I use org.osmf.vast.mediaVAST2TrackingProxyElement from the VASTLibrary for display advertising and use click to handle advertisement redirection.
    It's works for flash.media.Video.
    But after setting OSMFSettings.enableStageVideo = true, the click event from the MediaContainer is not dispatch.
    Can you please help?

    Actually, I looked briefly at the dev guide this week end, and Stage Video actually renders from the GPU under the Actionscript App.
    It could be something like this:
    Stage video is behind the Actionscript objects and one of them is as big or bigger than the video rendering rectangle and it is grabbing mouse interaction.
    Just speculating.
    Also, I'm not certain StageVideo can recieve mouse events...
    Hope this helps.

  • Dispatching event from Javascript

    Can I dispatch events from javascript to flash player? I am trying to do so by calling dispatchEvent() on flash player dom object but the event is not passing inside flash player. Any links or clue?

    To be specific ... I can catch a right click and supress it. But I want to send it to flash (lets say) as a left click. Problem is when i do that, javascript listner for dom element will get fired for left click but there wont be any events in flash.
    SO the question is can i fire events on flash from outseide or is it outside the public APIs?

Maybe you are looking for

  • ITunes cannot open apple iphone 4 device

    Recently i have been trying to sync my iTunes and put new music and other stuff, but a small box appears and says "The iPhone cannot be used because the Apple Mobile device service is not started". I try to restart my laptop and iPhone 4 but it has b

  • Songs I purchased a while ago no longer appear in my library, how do I add them to my library?

    I purchased an album a few years ago, since then I have changed computers. How do I add the old album I bought to my new computer, or is it even possible. Apple has a record of my purchase, but it will not let me access it other then just showing me

  • Condition not executed in Plan

    Hi, we´ve got a sql statement which looks like that: SELECT BplSegment.SalesOrg, WeeklyBplDataMeta.Line FROM BPLSEGMENT BplSegment LEFT OUTER JOIN BPLDATA WeeklyBplData INNER JOIN BPLDATAMETA WeeklyBplDataMeta ON WeeklyBplDataMeta.PKey=WeeklyBplData.

  • I have lines on my screen

    Hi everybody , I now have about 8 vertical lines on my screen , is there anything I can do about this, or do I have to get it repaired at the Apple shop , and if so does anyone know roughly how much this would cost ? Thanks Tony.

  • Keyboard not working after cleaning

    I cleaned the flat aluminum keyboard with a spray that sprays foam and now some keys on the keyboard are not functioning. I have used this spray on other keyboards without any problem. Yesterday the keys 1, 2, Q, W, A, S, Z, X and the key to lower th