MouseEvent vs DragEvent

I am trying a drag and drop feature. I want to drag object from source to target with these options :
1. While dragging object, the object follows the mouse.
2. And when the drag object over the target, the target responds. How can I do this?
I have try both MouseEvent and DragEvent.
but MouseEvent only works on 1st option and DragEvent only works on 2nd option.
I can't use them together. Is there a way??
PS. The dragging isn't smooth. What's the problem ? :(

There's a drag and drop example that wrapped in the Ensemble Demo(you can find it in the sdk run it in NetBeans). You can refer to it and get some clue.

Similar Messages

  • EventHandler T T doesn't recognize KeyEvent, bug?

    "type argument KeyEvent is not within bounds of Type-Variable T
    where T is a Type-Variable
    T extends Event declared in the interface EventHandler
    {code}
    http://docs.oracle.com/javafx/2/events/handlers.htm  this code doesn't work
    {code}
    Example 4-3 Handler for the Key Nodes
    private void installEventHandler(final Node keyNode) {
        // handler for enter key press / release events, other keys are
        // handled by the parent (keyboard) node handler
        final EventHandler<KeyEvent> keyEventHandler =
            new EventHandler<KeyEvent>() {
                public void handle(final KeyEvent keyEvent) {
                    if (keyEvent.getCode() == KeyCode.ENTER) {
                        setPressed(keyEvent.getEventType()
                            == KeyEvent.KEY_PRESSED);
                        keyEvent.consume();
        keyNode.setOnKeyPressed(keyEventHandler);
        keyNode.setOnKeyReleased(keyEventHandler);
    {code}
    nor does this code, which I copied from a eventHandler<MouseEvent>
    {code}
    class keyHandler implements EventHandler<KeyEvent>
    private final Node node;
        keyHandler(Node node)
           this.node= node ;
        @Override
        public void handle(KeyEvent event)
    {code}
    I'm going to make a jira report once I get confirmation from someone here, even though it's pretty obvious since the Tutorial example produced the same error.
    I am using Netbeans Lambda 8, with JDK 8 build-84
    InputEvent doesn't work either, going to try some others...  so far MouseEvent and DragEvent are the only working ones.
    Edited by: KonradZuse on Apr 13, 2013 10:44 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Wow :p.... I completely forgot about the duplicate set of imports.... I always do control + alt + i to import everything, so sometimes AWT stuff pops in there when it shouldn't, suprirsed I didn't think of that myself, but 2 am coding does that to you :p.
    Thanks a ton, I really appreciate it, i had no idea what was going on hahaha...
    I think it's weird that MouseEvent and DragEvent are set to FX import first... Is there a settign in netbeans that I can force the importer to use FX > all? Most of the time it's good, but as you see in this case sometimes AWT likes to bother me :P
    Edited by: KonradZuse on Apr 14, 2013 11:02 AM

  • Issue with a class extending EventHandler MouseEvent

    Hello all,
    I originally had a nested class that was a used for mouseEvents. I wanted to make this it's own class, so I can call it directly into other class objects I have made, but for some reason it isn't working and I'm getting an eror
    here is the code:
    public class MouseHandler implements EventHandler<MouseEvent>
        private double sceneAnchorX;
        private double sceneAnchorY;
        private double anchorAngle;
        private Parent parent;
        private final Node nodeToMove ;
       MouseHandler(Node nodeToMove)
           this.nodeToMove = nodeToMove ;
        @Override
        public void handle(MouseEvent event)
          if (event.getEventType() == MouseEvent.MOUSE_PRESSED)
            sceneAnchorX = event.getSceneX();
            sceneAnchorY = event.getSceneY();
            anchorAngle = nodeToMove.getRotate();
            event.consume();
          else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED)
              if(event.isControlDown())
                  nodeToMove.setRotationAxis(new Point3D(sceneAnchorY,event.getSceneX(),0));
                  nodeToMove.setRotate(anchorAngle + sceneAnchorX -  event.getSceneX());
                  sceneAnchorX = event.getSceneX();
                  sceneAnchorY = event.getSceneY();
                  anchorAngle = nodeToMove.getRotate();
                  event.consume();
              else
                double x = event.getSceneX();
                double y = event.getSceneY();
                nodeToMove.setTranslateX(nodeToMove.getTranslateX() + x - sceneAnchorX);
                nodeToMove.setTranslateY(nodeToMove.getTranslateY() + y - sceneAnchorY);
                sceneAnchorX = x;
                sceneAnchorY = y;
                event.consume();
          else if(event.getEventType() == MouseEvent.MOUSE_CLICKED)
            //  nodeToMove.setFocusTraversable(true);
               nodeToMove.requestFocus();
               event.consume();
                         nodeToMove.setOnKeyPressed((KeyEvent)
    ->{
         if(KeyCode.UP.equals(KeyEvent.getCode()))
             nodeToMove.setScaleX(nodeToMove.getScaleX()+ .1);
             nodeToMove.setScaleY(nodeToMove.getScaleY()+ .1);
             nodeToMove.setScaleZ(nodeToMove.getScaleZ()+ .1);
             System.out.println("kaw");
             KeyEvent.consume();
         if(KeyCode.DOWN.equals(KeyEvent.getCode()))
             if(nodeToMove.getScaleX() > 0.15)
             nodeToMove.setScaleX(nodeToMove.getScaleX()- .1);
             nodeToMove.setScaleY(nodeToMove.getScaleY()- .1);
             nodeToMove.setScaleZ(nodeToMove.getScaleZ()- .1);
             System.out.println(nodeToMove.getScaleX());
             KeyEvent.consume();
         nodeToMove.setOnScroll((ScrollEvent)
                 ->{
             if(nodeToMove.isFocused())
                        if(ScrollEvent.getDeltaY() > 0)
                            nodeToMove.setTranslateZ(10+nodeToMove.getTranslateZ());
                        else
                            nodeToMove.setTranslateZ(-10+nodeToMove.getTranslateZ());
           ScrollEvent.consume();
    }This is the class where I call it.
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.Box;
    * @author Konrad
    public class Display extends Pane
        Box b;
        PhongMaterial pm = new PhongMaterial(Color.GRAY);
        public Display(Double x, Double y,Double width, Double height)
             super();
             b = new Box(width, height,10);
             setPrefSize(width,height);
             relocate(x, y);
             b.setMaterial(pm); 
             b.addEventFilter(MouseEvent.ANY, new MouseHandler(this));
             getChildren().add(b);
    }There is no red dot stating the class doesn't exist, or anything is wrong, but when I run it I get an error.
    here is the error:
    C:\Users\Konrad\Documents\NetBeansProjects\3D\src\3d\Display.java:29: error: cannot find symbol
             b.addEventFilter(MouseEvent.ANY, new MouseHandler(this));
      symbol:   class MouseHandler
      location: class DisplayThis is another class from the one that it was originally "nested" in(sorry if I'm not using correct terms). The other class, as well as this, produce the same error(this one was just smaller and eaiser to use as an example).
    The code is exactly the same.
    Originally I thought that the MouseEvent class wasn't an FX class, so I switched it and thought it worked, tried it on the Display class it didn't, tried it on the first one and yeah still didn't, so not too sure what happened there :(.
    Thanks,
    ~KZ
    Edited by: KonradZuse on Jun 7, 2013 12:15 PM
    Edited by: KonradZuse on Jun 7, 2013 12:38 PM
    Edited by: KonradZuse on Jun 7, 2013 12:39 PM

    Last time that was the issue I was having for a certain case; however this seems to be different, here is the list of imports for each class.
    MouseHandler:
    import javafx.event.EventHandler;
    import javafx.geometry.Point3D;
    import javafx.scene.Node;
    import javafx.scene.Parent;
    import javafx.scene.input.KeyCode;
    import javafx.scene.input.MouseEvent;Display:
    import javafx.scene.input.MouseEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.Box;draw:
    import java.io.File;
    import java.sql.*;
    import javafx.application.Application;
    import javafx.collections.FXCollections;
    import javafx.collections.ObservableList;
    import javafx.event.ActionEvent;
    import javafx.geometry.Rectangle2D;
    import javafx.scene.Group;
    import javafx.scene.PerspectiveCamera;
    import javafx.scene.PointLight;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.ListCell;
    import javafx.scene.control.ListView;
    import javafx.scene.control.Menu;
    import javafx.scene.control.MenuBar;
    import javafx.scene.control.MenuItem;
    import javafx.scene.control.TextField;
    import javafx.scene.input.ClipboardContent;
    import javafx.scene.input.DataFormat;
    import javafx.scene.input.DragEvent;
    import javafx.scene.input.Dragboard;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.TransferMode;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.paint.PhongMaterial;
    import javafx.scene.shape.TriangleMesh;
    import javafx.stage.FileChooser;
    import javafx.stage.FileChooser.ExtensionFilter;
    import javafx.stage.Screen;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    import jfxtras.labs.scene.control.window.Window;
    import org.controlsfx.dialogs.Action;
    import org.controlsfx.dialogs.Dialog;Edited by: KonradZuse on Jun 7, 2013 2:27 PM
    Oddly enough I tried it again and it worked once, but the second time it error-ed out again, so I'm not sure what the deal is.
    then I ended up getting it to work again in the draw class only but when I tried to use the event I get this error.
    J a v a M e s s a g e : 3 d / M o u s e H a n d l e r
    java.lang.NoClassDefFoundError: 3d/MouseHandler
         at shelflogic3d.draw.lambda$5(draw.java:331)
         at shelflogic3d.draw$$Lambda$16.handle(Unknown Source)
         at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
         at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
         at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
         at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
         at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
         at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
         at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
         at javafx.event.Event.fireEvent(Event.java:202)
         at javafx.scene.Scene$DnDGesture.fireEvent(Scene.java:2824)
         at javafx.scene.Scene$DnDGesture.processTargetDrop(Scene.java:3028)
         at javafx.scene.Scene$DnDGesture.access$6500(Scene.java:2800)
         at javafx.scene.Scene$DropTargetListener.drop(Scene.java:2771)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler$3.run(GlassSceneDnDEventHandler.java:85)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler$3.run(GlassSceneDnDEventHandler.java:81)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.javafx.tk.quantum.GlassSceneDnDEventHandler.handleDragDrop(GlassSceneDnDEventHandler.java:81)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleDragDrop(GlassViewEventHandler.java:595)
         at com.sun.glass.ui.View.handleDragDrop(View.java:664)
         at com.sun.glass.ui.View.notifyDragDrop(View.java:977)
         at com.sun.glass.ui.win.WinDnDClipboard.push(Native Method)
         at com.sun.glass.ui.win.WinSystemClipboard.pushToSystem(WinSystemClipboard.java:234)
         at com.sun.glass.ui.SystemClipboard.flush(SystemClipboard.java:51)
         at com.sun.glass.ui.ClipboardAssistance.flush(ClipboardAssistance.java:59)
         at com.sun.javafx.tk.quantum.QuantumClipboard.flush(QuantumClipboard.java:260)
         at com.sun.javafx.tk.quantum.QuantumToolkit.startDrag(QuantumToolkit.java:1277)
         at javafx.scene.Scene$DnDGesture.dragDetectedProcessed(Scene.java:2844)
         at javafx.scene.Scene$DnDGesture.process(Scene.java:2905)
         at javafx.scene.Scene$DnDGesture.access$8500(Scene.java:2800)
         at javafx.scene.Scene$MouseHandler.process(Scene.java:3564)
         at javafx.scene.Scene$MouseHandler.process(Scene.java:3379)
         at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3331)
         at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1612)
         at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2399)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:312)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:237)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:354)
         at com.sun.glass.ui.View.handleMouseEvent(View.java:514)
         at com.sun.glass.ui.View.notifyMouse(View.java:877)
         at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
         at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
         at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
         at java.lang.Thread.run(Thread.java:724)
    Caused by: java.lang.ClassNotFoundException: shelflogic3d.MouseHandler
         at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
         at java.net.URLClassLoader$1.run(URLClassLoader.java:354)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:353)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
         ... 50 more
    Exception in thread "JavaFX Application Thread" E..........After the E comes a bunch of random stuff with drag and drop and such (since I'm dragging an item, and then creating it and giving it the event in question).
    Line 331 is                      b.addEventHandler(MouseEvent.ANY, new MouseHandler(b));

  • MouseEvent.MOUSE_WHEEL gets incorrect stageX and stageY in Flash Player 17.0.0.134 and Windows 8.1

    I developed a Flash Player swf application with Flash Builder 4.7 (64-bit) before and it has worked well before Flash Player version <= 16. Recently, I updated to Windows 8.1 with Internet Explorer 11 and Flash Player 17.0.0.134.
    It is strange that stageX and stageY in MouseEvent.MOUSE_WHEEL gets the position of the whole web page other than that of swf stage, But it works well in Windows 7 with FP 17.
    Another problem is BitmapData.setVector() doesn't work normally when the DPI of screen is set to 125%, even in Windows 7 with FP 17, but it works in FP16 before.
    By the way, it is interesting that all the above works well in Firefox with FP 17 even in Windows 8.1.
    Does anyone encounter this problem? Is there some workarounds on that?

    Internet Explorer has a unique Flash Player release from Firefox, so it is probably a new bug unique to that IE release. Have you tried this on more than 1 machine? If so, I would say report a bug about it.
    https://bugbase.adobe.com

  • MovieClip Filter Causing issues with EventListeners (mouseEvent.ROLL_OVER)

    Hello,
    I have been working on a flash photo gallery for the web. It loads thumbnails from an xml file into a loader which is then made the child of a movieclip.
    The thumbnails are animated and triggered with mouse events of ROLL_OVER and ROLL_OFF. I have this working, or appearing to, when the movieclip containing the loaded thumbnail has no filters applied to it.
    I want add a drop shadow on the ROLL_OVER event and remove the drop shadow on the ROLL_OFF event. I also have this working, however my problem arises when I mouse over the very edge of the movieclip. This cauese the ROLL_OVER and ROLL_OFF function to fire in rapid succession, creating a flashing dropshadow. This looks aweful and I really have no idea what would be causing this issue.
    Thanks in advance for any advice!
    Regards.

    Thanks for the reply.
    I also found it difficult to believe that the filter was causing issues with the roll over/out events. I will expand on the example code you provided so you get an idea of what I am trying to accomplish and where my issues arise.
    EDIT: I should add that the issue is only present when I tween AND add a filter. If I only add a filter or if I only tween I have no issues but the combination or adding a filter and tweening causes the OVER/OUT events to fire rapidly.
    //This code does not result in a flashing animation
    myClip.addEventListener(MouseEvent.ROLL_OVER, overClip);
    myClip.addEventListener(MouseEvent.ROLL_OUT, outClip);
    function overClip(e:MouseEvent):void
       myTween =  new Tween(myClip, "scaleX", Regular.easeOut, myClip.scaleX, 1.5 , 3, true);
       myTween =  new Tween(myClip, "scaleY", Regular.easeOut, myClip.scaleY, 1.5 , 3, true);
    function outClip(e:MouseEvent):void
       myTween =  new Tween(myClip, "scaleX", Regular.easeOut, myClip.scaleX, 1 , 3, true);
       myTween =  new Tween(myClip, "scaleY", Regular.easeOut, myClip.scaleY, 1 , 3, true);
    //However if i add these lines of code to add and remove a filter I can observe the flashing effect when the mouse is near the edge of the moveclip
    myClip.addEventListener(MouseEvent.ROLL_OVER, overClip);
    myClip.addEventListener(MouseEvent.ROLL_OUT, outClip);
    function overClip(e:MouseEvent):void
       myClip.filters = [myDropShadowFilter];
       myTween =  new Tween(myClip, "scaleX", Regular.easeOut, myClip.scaleX, 1.5 , 3, true);
       myTween =  new Tween(myClip, "scaleY", Regular.easeOut, myClip.scaleY, 1.5 , 3, true);
    function outClip(e:MouseEvent):void
       myClip.filters = [];
       myTween =  new Tween(myClip, "scaleX", Regular.easeOut, myClip.scaleX, 1 , 3, true);
       myTween =  new Tween(myClip, "scaleY", Regular.easeOut, myClip.scaleY, 1 , 3, true);
    Is there something obviously wrong with this approach to adding a filter/tweening? I am fairly new to flash.
    Thanks again!
    Message was edited by: Dafunkz

  • Can the name of a specific node in a JTree be returned by MouseEvent?

    I have created a mouseListener for a JTree. When a node in the JTree is clicked it should display the name of the node in a JOptionPane. Currently, I have the following:
    tree.addMouseListener(new MouseAdapter()
    public void mouseClicked(MouseEvent me)
         if(me.getClickCount() % 2 == 0)
         String s = "Blank";
         s = (me.getSource()).toString();
         JOptionPane.showMessageDialog(null, "Double clicked "+ s, "two", JOptionPane.PLAIN_MESSAGE);               
    }//mouseClicked          
    });//MouseListener
    This gives me the class X Y value, border, maxsize, etc.... when a node is double clicked.
    Does anyone know of a better way?

    Don't use MouseListener.
    Instead, make yourself a TreeSelectionListener as follows:
    public class WhererverYourTreeIs implements TreeSelectionListener
         public void valueChanged(TreeSelectionEvent e)
             TreePath path = e.getPath();
             System.out.println(path.getLastPathComponent());
         public void initStuff()
                 tree.addTreeSelectionLIstener(this);
    }

  • Dont detect MouseEvent as2 to as3.

    Hello. I transform a as2 game to as3. transform all the code and the game start but dont detect any MouseEvent associated to a MovieClip. In stage yes but not in any MovieClip. This is one example of my code...
    Code: 
    wheelmain.wheel.addEventListener(MouseEvent.MOUSE_DOWN, onWheelDown);
    wheelmain.wheel.addEventListener(MouseEvent.MOUSE_UP, onWheelUp);
    wheelmain.wheel.addEventListener(MouseEvent.ROLL_OUT, onWheelRollOut);
    wheelmain.wheel.addEventListener(MouseEvent.CLICK, onWheelReleaseOutside);
    function onWheelDown(e:MouseEvent)
         trace("Boton del raton pulsado.");
         //sndPotencia.start();
         potenciaRuletaOn();
    wheelmain.wheel exists and is a MovieClip. The movie dont show nothing to console.
    Anybody help me?.
    thanks!.

    Sorry for my bad english.
    Well, if i change one of the lines and type this:
    wheelmain.wheel.addEventListener(Event.ENTER_FRAME, onWheelDown);
    when the output console write:
    Boton del raton pulsado.
    Boton del raton pulsado.
    Boton del raton pulsado.
    Boton del raton pulsado.
    That means that the object is displayed and accessible, but for some strange reason it seems that no stage Movieclip dispatches any mouse event.

  • Problem with MouseEvent

    this.addMouseListener(new MouseAdapter(){
               private void showIfPopupTrigger(MouseEvent mouseEvent) {
                    try {
                        l.write("22222222222");
                   } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                       if (popupMenu.isPopupTrigger(mouseEvent))
                            try {
                                  l.write("3333333");
                             } catch (IOException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                             String name = getValueAt(getSelectedRow(), 1).toString();
                             if(getValueAt(getSelectedRow(), 2).toString().equals("FOLDER"))
                             popupMenu.init(false,name);
                             else
                                  popupMenu.init(true,name);     
                             popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                     public void mousePressed(MouseEvent mouseEvent) {
                          try {
                                  l.write("000000000000000000000");
                             } catch (IOException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                             if (mouseEvent.getButton() == MouseEvent.BUTTON3) // BUTTON3 is the right mouse button
                                  try {
                                       l.write("11111111111111111111");
                                  } catch (IOException e) {
                                       // TODO Auto-generated catch block
                                       e.printStackTrace();
                                  showIfPopupTrigger(mouseEvent);
                     public void mouseReleased(MouseEvent mouseEvent) {
                             showIfPopupTrigger(mouseEvent);
              });In the above given code, when I right click the mouse button, control reaches till l.write("22222222222");, but, it is not getting inside if (popupMenu.isPopupTrigger(mouseEvent)) , instead of that, control again goes to public void mousePressed(MouseEvent mouseEvent), what can be the reason?
    Rony

    I got the output with this.
    if (popupMenu.isPopupTrigger(mouseEvent))
                            int indRow = rowAtPoint(mouseEvent.getPoint());
                             getSelectionModel().addSelectionInterval(indRow, indRow);

  • MouseEvent not firing on DisplayObject click in AS only project in Flash Builder 4

    Hello,
    I'm having difficulty getting MouseEvents to fire in an ActionScript only project. It doesn't make any sense to me. My code is below and this object is the top most object on the stage.
    var click:Sprite = new Sprite();
    click.name = 'clickLayer';
    click.mouseEnabled = true;
    click.addEventListener(MouseEvent.CLICK, mouseClickHandler);
    addChild(click);
    function mouseClickHandler(e:MouseEvent):void{
    trace('click');
    var url:String = loaderInfo.parameters.clickTag;
    navigateToURL(new URLRequest(url), '_blank');
    My class extends Sprite.
    Everything else works fine. Something I found strange is that TextFields will fire MouseEvents when clicked if I add the EventListener, but not DisplayObjects.
    Thanks for your help.

    I just made the width & height the width & height of the container (Sprite), but still nothing.
    I also tried adding a "container" sprite to the main stage, and adding everything to that sprite - but that sprite won't instantiate and doesn't show on the stage, meaning anything added to that sprite doesn't show either.\
    Also: I've tried adding MouseEvent listeners to every display object I add to the stage and nothing will fire MouseEvents except TextFields.

  • AdvancedDatagird to ignore MouseEvent.MOUSE_WHEEL events

    Hi,
    Is there a way to get a  AdvancedDatagird to ignore MouseEvent.MOUSE_WHEEL events?

    Both these don't work sorry
    <mx:mouseWheel>
                             <![CDATA[
                              public function ignoreMouse(event:MouseEvent):void {
                              event.stopPropogation();
                              event.preventDefault();
                             ]]>
                         </mx:mouseWheel>
         <mx:mouseWheel>
                             <![CDATA[
                             function ignoreMouse(event:MouseEvent):void {
                              event.stopPropogation();
                              event.preventDefault();
                             ]]>
                         </mx:mouseWheel>

  • How do I add a mouseEvent to an area

    does anyone know how i add a mouseEvent to an area?
    i want to test the response of the user to hit a Graphic on the screen
    but i dont know how to make the Graphic so that it can be hit.
    Simple enough problem just im a bit dim. lol
    THanks for any help that would be offered,
    Brain

    You could add a mouse listener to the whole panel (or whatever container you're using) and then test each mouse click to see if it's within the area you're looking for.
    The getPoint() method of MouseEvent will tell you where the event occurred. If the graphic is rectangular, you can use the contains(Point p) method to see if the event occurred inside that region.

  • As2 to as3 the class or interface 'MouseEvent' could not be loaded

    im using as2 but the scripts are supposed to be in as3
    here's the code in as3:
    for (var i:int=0; i<10; i++){
              var newFood:mcFood=new mcFood();
              newFood.buttonMode=true;
              newFood.x = (Math.random()*510);
              newFood.y = (Math.random()*310);
              if(newFood.x>550){
                        newFood.x -=530;
              if(newFood.y>550){
                        newFood.y -=530;
              addChild(newFood);
              newFood.addEventListener(MouseEvent.MOUSE_DOWN, mousePressed);
              newFood.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
    function mousePressed(myVar:MouseEvent):void{
              myVar.target.startDrag();
    function mouseReleased(myVar:MouseEvent):void{
              myVar.target.stopDrag();
              if(myVar.target.hitTestObject(star)){
                        myVar.target.x = -300;
                        myVar.target.y = -30;
    could anyone transform this into as2?

    Basically Sir I do not have any background in using the as2. Since I started using the as3.
    Hmm actually the code up there works fine, but when I add the character to the as3 and try to run it, it says that the the button will be ignored.
    https://www.dropbox.com/s/l88ztx7o9qipbbw/asasasa.fla

  • [mouseEvent] CPU Grab

    I have a sample application with 400 column charts below. (I
    am attempting to duplicate behavior noticed in a heavily databound
    80-chart app.)
    If I allow my mouse pointer to hover over the application
    container (not the charts themselves--but the gutter to the left--a
    mite tricky in the sample), my CPU pegs at 50%, and the profiler
    indicates that most of that time is spent in [mouseEvent].
    I assume that the app is just endlessly processing mouse-over
    events and, perhaps, querying its 400 children to see whether any
    need to respond.
    Is that true? If so, how do I stop it? (The problem is more
    signifcant in our real application.)
    I've tried placing the charts in a container and turning off
    the container's mouseEnabled, focusEnabled, and mouseFocusEnabled,
    but this didn't help.
    Much thanks for any help!
    =====
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="vertical"
    creationComplete="init();">
    <mx:Script>
    <![CDATA[
    import mx.core.UIComponent;
    import mx.containers.HBox;
    import mx.collections.ArrayCollection;
    import mx.charts.LinearAxis;
    import mx.charts.ColumnChart;
    import mx.charts.CategoryAxis;
    import mx.charts.series.ColumnSeries;
    //[Bindable]
    public var myData:ArrayCollection = new ArrayCollection([
    {name:"first", value:5},
    {name:"second", value:10},
    {name:"third", value:15},
    {name:"fourth", value:20},
    {name:"fifth", value:25}
    public var myData2:ArrayCollection = new ArrayCollection([
    {name:"first", value:25},
    {name:"second", value:20},
    {name:"third", value:15},
    {name:"fourth", value:10},
    {name:"fifth", value:5}
    private function init():void
    var rows:int = 40;
    var cols:int = 10;
    rows = 40;
    cols = 10;
    for (var i:int=0; i<rows; ++i)
    var hbox:HBox = new HBox();
    for (var j:int=0; j<cols; ++j)
    hbox.addChild(buildColumnChart());
    addToContainer(hbox);
    private function addToContainer(component:UIComponent):void
    addChild(component);
    //testContainer.addChild(component);
    public function buildColumnChart():ColumnChart
    var cc:ColumnChart = new ColumnChart();
    cc.filters = [];
    cc.seriesFilters = [];
    cc.showDataTips = true;
    cc.dataProvider = myData;
    cc.width = 100; cc.height = 100;
    var axis:CategoryAxis = new CategoryAxis();
    axis.categoryField = "name";
    cc.horizontalAxis = axis;
    cc.verticalAxis = new LinearAxis();
    var series:ColumnSeries = new ColumnSeries();
    series.xField = "name";
    series.yField = "value";
    series.displayName = "Value";
    series.dataProvider = myData;
    series.filters = [];
    cc.series.push(series);
    series = new ColumnSeries();
    series.xField = "name";
    series.yField = "value";
    series.displayName = "Value";
    series.dataProvider = myData2;
    series.filters = [];
    cc.series.push(series);
    series = new ColumnSeries();
    series.xField = "name";
    series.yField = "value";
    series.displayName = "Value";
    series.dataProvider = myData;
    series.filters = [];
    cc.series.push(series);
    return cc;
    ]]>
    </mx:Script>
    <mx:VBox id="testContainer"
    mouseEnabled="false" focusEnabled="false"
    mouseFocusEnabled="false" />
    </mx:Application>

    I have the exactly same problem

  • MouseEvent.LocalX co-ordinates doesn't resize with sprite

    I'm looking into how to create a custom sprite which the
    mouse performs different actions depending which part of the sprite
    it is clicked on they are:
    1) Click and drag on the left edge able extends the box to
    the left
    2) Click and drag in the middle able to move the box round
    the screen (drag and drop)
    3) Click and drag on the right edge able to extend the box to
    the right.
    I've looked at a couple of ways to implement the context on
    the rectagle. One of them is testing where the mouse clicks on the
    sprite. My code for that test is this:
    private function get LeftHandRegion () : Number {return 25;}
    private function get RightHandRegion () : Number {return
    width - 25;}
    private function IsInLeftHandRegion(event:MouseEvent) :
    Boolean {return (event.localX < LeftHandRegion);}
    private function IsInRightHandRegion(event:MouseEvent) :
    Boolean {return (event.localX > RightHandRegion);}
    private function IsInMiddleRegion(event:MouseEvent) : Boolean
    return (event.localX >= LeftHandRegion &&
    event.localX <= RightHandRegion)
    If I set my original sprite size to 300 everything works as
    it should and I can perform all 3 actions correctly.
    However if I then streatch my rectangle to 800 the
    event.LocalX only goes upto the original 300 event though the
    sprite is now bigger so my test for the right hand region fails so
    I can't extend my box to the right any more.
    Does any one have any ideas?

    I have found a solution to this problem. On the mouseup event
    I remove the current resized DisplayObject from its parent.
    Then I create a new DisplayObject and pass in the parameters
    from the existing but resized DisplayObject.
    The new DisplayObject is then added back to the parent.
    Then everything works :D
    Code snippet is this:
    var year:YearDisplay = YearDisplay(parent);
    year.removeChild(this);
    var newUnitDisplay = new UnitDisplay(x, y, width, height,
    _unit, _colour);
    year.addChild(newUnitDisplay);

  • MouseEvent memory leak.

    Does anyone ever encounter a memory leak in java MouseEvent? I am profiling my project here and it shows that the MouseEvents never go down in size.

    .

Maybe you are looking for