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);

Similar Messages

  • Text runs of the page / doesn't resize with window

    Hi,
    I have seen this before but cant figure out how to fix this:
    In Mail and other applicaitons that involve typing text the sentenses run off the "page".
    When I resize the window the lines dont' adapt to the window.
    I am stumped, please help :-)
    Rogier

    Howdy. See if this helps:
    https://discussions.apple.com/thread/5298047?tstart=150

  • Finder, Icon Slider bottom doesn't resize

    hi, i have a small bug with my icon slider of Finder. it doesn't resize with the small slider at right bottom of a Finder window.
    as you can see: the icons in the Finder window are very small (set by the slider right), but the slider left is set to the biggest icon size.
    but
    if i go to a higher Finder level, change there the size of the icons (possible), return to the old Finder window (picture above), then:
    the functionaltiy is actually, that the sliderposition left and right is synchronous.
    that well running disappearing after couple of clicks or minutes.

    I have the same issue. If I switch from a non-icon view to the icon view, the slider doesn't work. However, if I select icon view for a folder, then close the folder and re-open again, the slider works. I think the invisible database file for the folder display isn't getting updated correctly / at the right time.
    Permission repair doesn't help, so I suspect a minor Finder bug. Hopefully 10.7.2 will fix.
    K@

  • Node Container that does not resize with Window Resize Event

    Hello,
    I'm not new to Java but I am new to JavaFX.
    I plan to have a container/Canvas with multiple shapes (Lines, Text, Rectangle etc) in it. This Container can be X times in the Szene with different Text Shapes. I need to Zoom and Pan (maybe rotation) the whole Szene and the Containers/Canvas.
    So I was playing around with that but I have two issues.
    1) all Canvas classes that I found (like Pane for example) do resize with the main window resize event. The content of the canvas isn't centered any more.
    2) I added a couple of Rectangles to the canvas and both the rectangles and the canvas have a mouse listener which will rotate the item/canvas. Problem is, that even if I click the rectangle also the underlaying canvas is rotated...I think I need some kind of Z-Info to find out what was clicked.
    Here is the little example program, it makes no produktiv sense but it demonstrates my problem.
    Does anybody has a tip what canvas class would fit and does not resize with the main window and how to figure out what was clicked?
    public class Test extends Application
         Scene mainScene;
         Group root;
         public static void main(String[] args)
            launch(args);
        @Override
        public void init()
            root = new Group();
            int x = 0;
            int y = -100;
            for(int i = 0; i < 5; i++)
                 x = 0;
                 y = y + 100;
                 for (int j = 0; j < 5; j++)
                      final Rectangle rect = new Rectangle(x, y, 30 , 30);
                       final RotateTransition rotateTransition = RotateTransitionBuilder.create()
                             .node(rect)
                             .duration(Duration.seconds(4))
                             .fromAngle(0)
                             .toAngle(720)
                             .cycleCount(Timeline.INDEFINITE)
                             .autoReverse(true)
                             .build();
                     rect.setOnMouseClicked(new EventHandler<MouseEvent>()
                          public void handle(MouseEvent me)
                               if(rotateTransition.getStatus().equals(Animation.Status.RUNNING))
                                    rotateTransition.setToAngle(0);
                                    rotateTransition.stop();
                                    rect.setFill(Color.BLACK);
                                    rect.setScaleX(1.0);
                                    rect.setScaleY(1.0);
                               else
                                    rect.setFill(Color.AQUAMARINE);
                                    rect.setScaleX(2.0);
                                    rect.setScaleY(2.0);
                                    rotateTransition.play();
                      root.getChildren().add(rect);
                      x = x + 100;
        public void start(Stage primaryStage)
             final Pane pane = new Pane();
             pane.setStyle("-fx-background-color: #CCFF99");
             pane.setOnScroll(new EventHandler<ScrollEvent>()
                   @Override
                   public void handle(ScrollEvent se)
                        if(se.getDeltaY() > 0)
                             pane.setScaleX(pane.getScaleX() + 0.01);
                             pane.setScaleY(pane.getScaleY() + 0.01);
                        else
                             pane.setScaleX(pane.getScaleX() - 0.01);
                             pane.setScaleY(pane.getScaleY() - 0.01);
             pane.getChildren().addAll(root);
             pane.setOnMouseClicked(new EventHandler<MouseEvent>(){
                   @Override
                   public void handle(MouseEvent event)
                        System.out.println(event.getButton());
                        if(event.getButton().equals(MouseButton.PRIMARY))
                             System.out.println("primary button");
                             final RotateTransition rotateTransition2 = RotateTransitionBuilder.create()
                                  .node(pane)
                                  .duration(Duration.seconds(10))
                                  .fromAngle(0)
                                  .toAngle(360)
                                  .cycleCount(Timeline.INDEFINITE)
                                  .autoReverse(false)
                                  .build();
                             rotateTransition2.play();
             mainScene = new Scene(pane, 400, 400);
             primaryStage.setScene(mainScene);
            primaryStage.show();
    }Edited by: 953596 on 19.08.2012 12:03

    To answer my own Question, it depends how you add childs.
    It seems that the "master Container", the one added to the Scene will allways resize with the window. To avoid that you can add a container to the "master Container" and tell it to be
    pane.setPrefSize(<child>.getWidth(), <child>.getHeight());
    pane.setMaxSize(<child>.getWidth(), <child>.getHeight());
    root.getChildren().add(pane);and it will stay the size even if the window is resized.
    Here is the modified code. Zooming and panning is working, zomming to window size is not right now. I'll work on that.
    import javafx.animation.Animation;
    import javafx.animation.ParallelTransition;
    import javafx.animation.ParallelTransitionBuilder;
    import javafx.animation.RotateTransition;
    import javafx.animation.RotateTransitionBuilder;
    import javafx.animation.ScaleTransitionBuilder;
    import javafx.animation.Timeline;
    import javafx.animation.TranslateTransitionBuilder;
    import javafx.application.Application;
    import javafx.event.EventHandler;
    import javafx.geometry.Point2D;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.input.MouseButton;
    import javafx.scene.input.MouseEvent;
    import javafx.scene.input.ScrollEvent;
    import javafx.scene.layout.Pane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Rectangle;
    import javafx.stage.Stage;
    import javafx.util.Duration;
    public class Test extends Application
         Stage primStage;
        Scene mainScene;
         Group root;
         Pane masterPane;
         Point2D dragAnchor;
         double initX;
        double initY;
         public static void main(String[] args)
            launch(args);
        @Override
        public void init()
            root = new Group();
            final Pane pane = new Pane();
            pane.setStyle("-fx-background-color: #CCFF99");
            pane.setOnScroll(new EventHandler<ScrollEvent>()
                @Override
                public void handle(ScrollEvent se)
                    if(se.getDeltaY() > 0)
                        pane.setScaleX(pane.getScaleX() + pane.getScaleX()/15);
                        pane.setScaleY(pane.getScaleY() + pane.getScaleY()/15);
                        System.out.println(pane.getScaleX() + " " + pane.getScaleY());
                    else
                        pane.setScaleX(pane.getScaleX() - pane.getScaleX()/15);
                        pane.setScaleY(pane.getScaleY() - pane.getScaleY()/15);
                        System.out.println(pane.getScaleX() + " " + pane.getScaleY());
            pane.setOnMousePressed(new EventHandler<MouseEvent>()
                public void handle(MouseEvent me)
                    initX = pane.getTranslateX();
                    initY = pane.getTranslateY();
                    dragAnchor = new Point2D(me.getSceneX(), me.getSceneY());
            pane.setOnMouseDragged(new EventHandler<MouseEvent>()
                public void handle(MouseEvent me) {
                    double dragX = me.getSceneX() - dragAnchor.getX();
                    double dragY = me.getSceneY() - dragAnchor.getY();
                    //calculate new position of the pane
                    double newXPosition = initX + dragX;
                    double newYPosition = initY + dragY;
                    //if new position do not exceeds borders of the rectangle, translate to this position
                    pane.setTranslateX(newXPosition);
                    pane.setTranslateY(newYPosition);
            int x = 0;
            int y = -100;
            for(int i = 0; i < 5; i++)
                 x = 0;
                 y = y + 100;
                 for (int j = 0; j < 5; j++)
                      final Rectangle rect = new Rectangle(x, y, 30 , 30);
                       final RotateTransition rotateTransition = RotateTransitionBuilder.create()
                             .node(rect)
                             .duration(Duration.seconds(4))
                             .fromAngle(0)
                             .toAngle(720)
                             .cycleCount(Timeline.INDEFINITE)
                             .autoReverse(true)
                             .build();
                     rect.setOnMouseClicked(new EventHandler<MouseEvent>()
                          public void handle(MouseEvent me)
                               if(rotateTransition.getStatus().equals(Animation.Status.RUNNING))
                                    rotateTransition.setToAngle(0);
                                    rotateTransition.stop();
                                    rect.setFill(Color.BLACK);
                                    rect.setScaleX(1.0);
                                    rect.setScaleY(1.0);
                               else
                                    rect.setFill(Color.AQUAMARINE);
                                    rect.setScaleX(2.0);
                                    rect.setScaleY(2.0);
                                    rotateTransition.play();
                      pane.getChildren().add(rect);
                      x = x + 100;
            pane.autosize();
            pane.setPrefSize(pane.getWidth(), pane.getHeight());
            pane.setMaxSize(pane.getWidth(), pane.getHeight());
            root.getChildren().add(pane);
            masterPane = new Pane();
            masterPane.getChildren().add(root);
            masterPane.setStyle("-fx-background-color: #AABBCC");
            masterPane.setOnMousePressed(new EventHandler<MouseEvent>()
               public void handle(MouseEvent me)
                   System.out.println(me.getButton());
                   if((MouseButton.MIDDLE).equals(me.getButton()))
                       double screenWidth  = masterPane.getWidth();
                       double screenHeight = masterPane.getHeight();
                       System.out.println("screenWidth  " + screenWidth);
                       System.out.println("screenHeight " + screenHeight);
                       System.out.println(screenHeight);
                       double scaleXIs     = pane.getScaleX();
                       double scaleYIs     = pane.getScaleY();
                       double paneWidth    = pane.getWidth()  * scaleXIs;
                       double paneHeight   = pane.getHeight() * scaleYIs;
                       double screenCalc    = screenWidth > screenHeight ? screenHeight : screenWidth;
                       double scaleOperator = screenCalc  / paneWidth;
                       double moveToX       = (screenWidth/2)  - (paneWidth/2);
                       double moveToY       = (screenHeight/2) - (paneHeight/2);
                       System.out.println("movetoX :" + moveToX);
                       System.out.println("movetoY :" + moveToY);
                       //double scaleYTo = screenHeight / paneHeight;
                       ParallelTransition parallelTransition = ParallelTransitionBuilder.create()
                               .node(pane)
                               .children(
                                   TranslateTransitionBuilder.create()
                                       .duration(Duration.seconds(2))
                                       .toX(moveToX)
                                       .toY(moveToY)
                                       .build()
                                   ScaleTransitionBuilder.create()
                                       .duration(Duration.seconds(2))
                                       .toX(scaleOperator)
                                       .toY(scaleOperator)
                                       .build()
                      .build();
                       parallelTransition.play();
        public void start(Stage primaryStage)
             primStage = primaryStage;
            mainScene = new Scene(masterPane, 430, 430);
             primaryStage.setScene(mainScene);
            primaryStage.show();
    }

  • Is it possible to make a fixed size page in muse, so it doesn't resize?

    I want to make a fixed size page (pic1),
    but there always an extra space on the bottom… pic2

    Thank you for reply - I will check it out…
    Date: Wed, 18 Dec 2013 09:07:46 -0800
    From: [email protected]
    To: [email protected]
    Subject: Is it possible to make a fixed size page in muse, so it doesn't resize?
        Re: Is it possible to make a fixed size page in muse, so it doesn't resize?
        created by Zak Williamson (Adobe) in Help with using Adobe Muse CC - View the full discussion
    Assuming the screenshots are of the same page, the one that's taller is either taller because the minimum page height has been changed or due to some page content (that's not marked as a Footer Item) being located in the new space. This may be an empty text frame or the transparent area of a widget, text frame or other object.
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/5941664#5941664
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/5941664#5941664
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/5941664#5941664. In the Actions box on the right, click the Stop Email Notifications link.
               Start a new discussion in Help with using Adobe Muse CC at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • My iphone 5 doesn't sync with itunes on my pc. it says this computer has  previously been synced to another io6 device or iphone? please help what to do?

    My iphone 5 doesn't sync with itunes on my pc. it says this computer has  previously been synced to another io6 device or iphone? please help what to do?

    The error message you're seeing is likely the other way around -- i.e. something like "This iPhone has previously been synced with a different computer".   There's no problem syncing multiple iOS devices to the same computer.
    However, the reverse is not true for the iPhone --  you cannot connect an iPhone to another computer without it being erased, even if you manually manage music and video.  So, it sounds like you've been syncing your iPhone to a different computer?
    Also, 5.1 (not 5.0.1) is the latest iOS.

  • Iphone 5s doesn't sync with itunes

    got a new iphone 5s and my itunes doesn't sync with it. can't draw songs over to phone. i bought some songs from itunes and don't show up in mu library.. lm getting tired of apple it was never this hard to sync songs..  have same id on both phone and mac.. don't know what to do plz help anybody.. starting to get disappointed on apple

    You cannot update iTunes on an iPad. The lastest version of iTunes on the iPad is updated when you update it's iOS
    You can update iTunes to the latest version 11.1.2 on your Mac if it supports the following:
    Macintosh System Requirements
    Mac computer with an Intel Core processor
    OS X version 10.6.8 or later
    400MB of available disk space
    Broadband Internet connection to use the iTunes Store
    Also, see the following:
    http://www.apple.com/support/itunes/install/

  • How to install W.7 on 2011 Macbook pro which doesn't come with bootcamp dvd?

    how to install W.7 on 2011 Macbook pro which doesn't come with bootcamp dvd?

    Use the Boot Camp Assistant in the /Applications/Utilities/ folder to put the Boot Camp drivers onto an optical disk or USB thumbdrive.
    (80603)

  • Trying to load illustrator 6cs onto new mac and the old activation code for my ill cs doesn't work with it

    Trying to load a downloaded version of illustrator 6cs onto new mac and the old activation code for my illustrator cs doesn't work with it.  Do I need a new code or am I missing something?  Same goes for my Photoshop cs.

    you need your serial number.
    if you purchased from or registered with adobe check your account, https://www.adobe.com/account.html

  • New DVI-standard doesn't fit with old Apple adapter

    I bought a new MBP i7 the last week and was very surprised when i noticed that the adapter i bought (Mini Display to DVI) doesn't fit with my old adapter (DVI to VGA). Apples new DVI-adapter us the DVI-D standard and that doesn't work well with teh DVI-I standard. When i talked with Apple and also with a Apple store they didn't know of any new DVI-standard and if there is an adapter (Mini Display to DVI-I). http://www.interfacebus.com/DesignConnector_Digital_Visual_Interface_DVIBus.html
    Is there anyone out there who know if it is possible to buy this Mini Display to DVI-I (Dual)?

    The Apple Mini-Displayport-to-DVI adapter is DVI-D because there is no analog signal emitted from the Mini-Displayport. The contacts the adapter lacks are the ones that would carry an analog signal, if there were any. If you want to connect your MBP to a device with a VGA input port, get a mini-displayport-to-VGA adapter.

  • Cinema Display (clear) with DVI/ADC box doesn't work with MacBook Pro

    Cinema Display (clear) with DVI/ADC box doesn't work with MacBook Pro when plugged in with a dvi to mini dvi cable. Any ideas what to do to make it work? I lugged the 23" 2500 miles into the wilderness and I need help

    Okay, here's an update: the DVI to ADC adapter does work with the Apple displays that I have tried, but it won't work with the Formac. I have tried multiple time to contact them, but to no avail... they don't even respond to threats of posting my opinion of them, which is this:
    DON'T BUY ANYTHING FROM FORMAC! They make quality products, but their customer service is a big time joke! They won't take care of you.

  • Safari crashes or hangs requiring unplugging power to my iMac desktop running OS 10.8.2. This doesn't happen with FireFox. Also while trying to recover my old files using Carbonite I get messages saying there is no space on my startup disk 1 TB?

    After replacing my burnt out original hard drive in my iMac 24 inch desk top computer with 1 TB hard drive I've had repeated problems with Safari hanging/not responding. This has frozen my computer and required me to unplug the power cord and restart. It doesn't happen with FireFox. In addition, while trying to restore from Carbonite I've had it hang five or six times never completing the restore. When the technician replaced the hard drive he installed OC 10.8.2. When restoring I get repeated messages that there isn't enough room on my startup disk to continue the restore. This obviously isn't the case because I have far more storage space with a 1 TB hard drive. Any ideas what is going on and how I can prevent these two problems from continuing? Thanks.

    You've got an  incompatible Logitech driver and java was incompletely uninstalled.
    You may have a problem with the Wacom driver.
    I don't know if fixing those things will help.
    There also a few window server errors, but I don't know if they are causal.
    If you can note the time of the hangs, that might help narrow it down in the logs.

  • I want to cut and paste iCal entries on iPad.  Have seen a number of questions raised but no definitive answer - is it possible or not?  (I use Bento but that doesn't sync with ICal now so can use that solution)

    I want to cut and paste iCal entries on iPad.  Have seen a number of questions raised but no definitive answer - is it possible or not? 
    (I use Bento but that doesn't sync with ICal now so can use that solution)
    Hope to hear helpful news soon....
    C

    No, the camera connection kit only supports the copying of photos and videos to the Photos app, it doesn't support copying content off the iPad. For your second camera instead of the SD reader part of the kit, does the iPad to camera cable not work with it for direct transfer to the iPad ?
    For Lightroom and Nikon software again no - you can only install apps that are available in the iTunes app store on your computer and the App Store app on the iPad, 'normal' PC and Mac (OS X) software are not compatible with the iPad (iOS). There are some apps that perform fairly basic editing functions that are available in the store, but nothing as sophisticated as, for example, Lightroom.

  • How to use airport time capsule on a dell portable pc with windows 7 taking in consideration that Time machine doesn't run with Windows ?

    how to use airport time capsule on a dell portable pc with windows 7 taking in consideration that time machine doesn't run with Windows ?

    TM does not work like that.
    If you want files to use later.. do not use TM.
    Or do not use TM to the same location. Plug a USB drive into the computer and use that as the target for the permanent backup.
    Read some details of how TM works so you understand what it will do.
    http://pondini.org/TM/Works.html
    Use a clone or different software for a permanent backup.
    http://pondini.org/TM/Clones.html
    How to use TC
    http://pondini.org/TM/Time_Capsule.html
    This is helpful.. particularly Q3.
    Why you don't want to use TM.
    Q20 here. http://pondini.org/TM/FAQ.html

  • How can I delete my icloud account from my iphone, since it doesn't synch with my ipad?

    How can I delete my icloud account from my iphone 4, since it doesn't sync with my ipad mini?

    Go to https//appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Tap edit next to the primary email account, tap Edit, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address (you shouldn't need to verify the old account).  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https//appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

Maybe you are looking for

  • Using US nano in the UK

    Hi, If i buy a nano in the USA (being much cheaper than here in the UK), can i use a USB power adaptor bought in the UK with no problems?

  • Data recovery options if drive not accessible through Target Disk Mode

    I have the classic data recovery question: my computer seems to have failed, and I'd like to save some data. Thanks in advance for any advice. Details: - Most recent backup was about a month ago to Time Machine (unfortunately, this laptop went off on

  • Hard lock when waking from sleep

    I have a nVidia 9400m MacBook Pro 13 and I've been having consistent problems waking the machine from sleep. Once the computer goes to sleep and I wake it (either by opening the lid or pressing the power button if the lid is open,) I get a display of

  • Custom Control Screen not able to record

    Hi, I have a Custom Control Screen in PA30, I call this using FM : " RH_EDITOR_SET " to display text on it. My Question is during recording(SHDB) I am not able to get the customer Control screen, is any way to capture the customer Control. Prabhu Raj

  • Can PSP be used in Portals?

    Hi Portal Gurus, I understand PL/SQL Cartridges can be used in portal development. But, has Oracle started supporting use of PSP (PL/SQL Server Pages) for portal development? If so, is there any documentation out there for it? Any help will be greatl