dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: if statement issues with draggable movie clip

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    373

    if statement issues with draggable movie clip

    I'm creating a draggable movie clip (an arrow symbol) that drags along a rectangular track. Works fine but my issue is when the arrow's y axis is at a certain position, it needs to remove a movie clip instance and also run a trace statement. Right now, it's not doing that (if I change the == in the if statement to += it works but then it just works as soon as you mouse down on the arrow) and I'm wondering where I'm goofing up. Here's my code:

    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.events.MouseEvent;

    var arrow_mc:MovieClip = new arrow();
    addChild(arrow_mc);
    arrow_mc.x = 110;
    arrow_mc.y = 316;

    var product:MovieClip = new Products ();
    addChild(product);
    product.x = 228;
    product.y = 54;

    arrow_mc.addEventListener(MouseEvent.MOUSE_DOWN,dr agIt);
    function dragIt(evt:MouseEvent):void {
    var rectangle:Rectangle = new Rectangle(109, 62, 0, 254);
    arrow_mc.startDrag(false, rectangle);
    if (arrow_mc.y == 300) {
    removeChild(product);
    trace("Product Removed");
    }
    }

    arrow_mc.addEventListener(MouseEvent.MOUSE_UP,drag Stop);
    function dragStop(evt:MouseEvent):void {
    arrow_mc.stopDrag();
    }
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    try using >= (greater than or equal) rather than == (exactly equals)
    as the arrow.mc might stop at 299.9 or 300.1 which will fail your argument

  3. #3
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    That's a good point but in this case, it's similar to when I tried !=. As soon as I Moused Down on the button, it went ahead and played the arguments out. Is there a way I can do an if statement specifying a range. Like if y>=300 but y<=310?
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    sure:
    PHP Code:
    if(arrow_mc.>= 300 && arrow_mc <= 310){ ... } 
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  5. #5
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    I tried if(arrow_mc.y <= 198 && arrow_mc.y >= 214) but it didn't work. Nothing happened.
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  6. #6
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Yeah, but that's because of the statement, if the y is <= 198, then it can't be possibly larger than 214 at the same time!

    PHP Code:
    if(arrow_mc.>= 198 && arrow_mc.<= 214
    is probably what you need
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  7. #7
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    I tried that but no change.
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

  8. #8
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    Hmm.. I once managed to tie in a square with that method using 4 x &&!
    Maybe your solution would be to check for a hit test, rather than the y position.

    Are you sure the registration point of the arrow is located at it's tip and not anywhere else, because that's something people tend to forget about when using arrows
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  9. #9
    Junior Member
    Join Date
    Jan 2004
    Location
    UK
    Posts
    10
    Maybe set up a trace for mouseX and mouseY to check that the numbers correspond to where/what you think the mouseX and mouseY are?

    The reason I suggest this is that I had some issues that were solved in this thread when a hittest wouldn't work for me (due to the mouseX/Y being not where they should of been):

    http://board.flashkit.com/board/showthread.php?t=799765
    keep the krazykayak faith; play online
    now!
    http://www.krazykayak.co.uk

  10. #10
    Senior Member
    Join Date
    Jul 2000
    Posts
    373
    Registration point seems to be in the right place. I looked at hitTest examples and didn't really think that this was what I was looking for. One other thing I noticed here was if my mouse is on the arrow and I start dragging, as long as my mouse is down and not even on the arrow anymore, the drag effect still happens. That's really weird. Any way I can constrain it so that it only drags when my mouse is directly on the arrow object?
    Adam Bell
    dzign@datatv.com
    --
    Over 90% of all websites
    suck......
    Join the minority.

Tags for this Thread

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