A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Stop mouse cursor moving past a certain Y axis point

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    38

    Stop mouse cursor moving past a certain Y axis point

    Hi, I am creating a e-card game for my company and I have replaced the mouse cursor with a hand grabbing animation. I would like to stop the user being able to move too far up on the screen so the arm is only present at the bottom. What is the best way to do this? Any help would be great?

    Thanks

    Ben

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    You can use a constrained area drag, like a slide bar sort of thing

    AS3, Something like so
    PHP Code:
    function drag(e:MouseEvent):void
    {
         
    e.target.startDrag(false, new Rectangle(30,30,150,150));
    }

    function 
    drop(e:MouseEvent):void
    {
         
    stopDrag();

    AS2, Something like so
    PHP Code:
    dragger.onPress = function ()
    {
         
    startDrag(this,false,30,30,150,150);
    }

    dragger.onRelease = function ()
    {
         
    stopDrag();

    obviously you will need to use your own coordinates.

    Numbers = (left,top,right,bottom);
    Last edited by fruitbeard; 12-02-2014 at 01:29 AM.

  3. #3
    Member
    Join Date
    Jan 2008
    Posts
    38
    Hi thanks for your response... currently my code is:

    Code:
    stop();
    Mouse.hide();
    cursor_mc.startDrag(true);
    
    
    hiddenmc.addEventListener(MouseEvent.CLICK, insidecursor);
    
    
    function insidecursor(e:MouseEvent):void
    {
    	
    	cursor_mc.gotoAndPlay("insidecursorlabel");
    		
    }
    Currently when you click screen it will play the animation within the movieclip. I tried to alter the code and insert what you specified but the object stops moving when I do... am I incorrectly referencing the movie clip?

    Code:
    stop();
    Mouse.hide();
    
    function drag(e:MouseEvent):void
    {
         cursor_mc.target.startDrag(false, new Rectangle(0,100,50,0));
    }
    
    function drop(e:MouseEvent):void
    {
         stopDrag();
    }
    Cheers

  4. #4
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Without seeing your file its hard for me to say but I assume the mouseEvent is obscuring the other mouseEvent.

    it would be "e.target" and not "cursor_mc.target".

    if you have no luck try attaching your *.fla

  5. #5
    Member
    Join Date
    Jan 2008
    Posts
    38
    Ok, file attached...

    Xmas2014 - Copy.fla

    Thanks

  6. #6
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    At present the drag event is not being listened to by anything, so what is it you wish to drag.

    OK you want to drag the arm, i got it.

    Is this any better?
    Last edited by fruitbeard; 12-02-2014 at 02:37 AM.

  7. #7
    Member
    Join Date
    Jan 2008
    Posts
    38
    Thanks for this and is a lot closer to what I need, but I actually wanted the arm to replace the mouse cursor and move with the mouse rather than a drag and drop. The aim on the 'game' will be to grab toys from a conveyor belt using the claw... Is this even possible?

    Cheers

  8. #8
    Member
    Join Date
    Jan 2008
    Posts
    38
    I've actually got it how I want but the last issue I'm facing is being able to click on an object with the claw when the object is placed underneath the claw (how I need it) in the timeline see Xmas2014_copy2.fla

    Is there a way around this?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center