Skip to main content
Participant
April 4, 2010
Answered

spark.primitives Eventlistener

  • April 4, 2010
  • 1 reply
  • 1008 views

good day!

i added some ellipses to a component and tried to add an eventlistener to each object e.g. mouse_click or mouse_over, for changing the objects color of shape ... doesn't matter. anyway i have no clue how to do that. is there some way ?

var ellipse:Ellipse = new Ellipse();

ellipse.height = height;

ellipse.width = width;

ellipse.stroke = new SolidColorStroke(0x111111);

ellipse.fill = new SolidColor(0x0000FF);

thanking you in anticipation

fritz

This topic has been closed for replies.
Correct answer

The GraphicElements (Rect, Path, Ellipse, etc...) that were added in Flex 4 are not interactive objects.  You cannot add mouse events directly to them.  If you need to add mouse events to a shape, then you should wrap it in a Group first and add the mouse events to that Group.  The reason for this is for performance--the graphicelements are not display objects directly and don't support interactive events.

Hope that helps,

Ryan

1 reply

Correct answer
April 5, 2010

The GraphicElements (Rect, Path, Ellipse, etc...) that were added in Flex 4 are not interactive objects.  You cannot add mouse events directly to them.  If you need to add mouse events to a shape, then you should wrap it in a Group first and add the mouse events to that Group.  The reason for this is for performance--the graphicelements are not display objects directly and don't support interactive events.

Hope that helps,

Ryan

Participant
May 3, 2010

Hi

I have the same problem. I need to assign mouse listener to Path element. As it was commented I wrapped Path with Group, but looks like only the latest added group is reacting to the mouse. Please see the code below. Can someone advise how to overcome this?

Thanks

        public function mapRegionMouseClick(event:Event):void{
            var group:Group = Group(event.target);
            var path:Path = Path(group.getElementAt(0));
            path.visible = true;
            trace("mapRegionMouseOver: " + group.name);
        }
        private var groupIndex:int = 1;
        public function addRegion(data:String):void {
            var path:Path = new Path();
       
            path.data = data;
            path.fill = FilterFactory.getGradientFill(0x4ca8dc, 0x194d6b);
            path.visible= false;
            var tempGroup:Group = new Group();
            tempGroup.name = "group" + groupIndex++;
            tempGroup.addEventListener(MouseEvent.CLICK, mapRegionMouseClick);
            tempGroup.addElement(path);
            regionGroup.addElement(tempGroup);
           
            addRegionBorder(data);
        }