Page 1 of 1

Intersect() or Within Issues

Posted: Thu Dec 12, 2013 2:33 pm
by istech
Hi all I wonder if someone can point me in the right direction.

I have 5 images and one of the images is set as "target" via name and the rest is just "button" by name.

I have a grab image which has a simple script of:

if within (img "button", the MouseLoc) then
show img "XXX"
end if
if within (img "target", the MouseLoc) then
show img "XXX"
end if

Now when I use the MouseUp handler above it only works on 2 out of the 4 possible "button" target options.

I have tried both intersect() and within with the same results. Is there something I am missing?

Thanks all

I have checked the docs but nothing relevant that I can see.

Re: Intersect() or Within Issues

Posted: Thu Dec 12, 2013 2:45 pm
by Klaus
Hi istech,

I think the problem is that you have 4 images with the SAME name on your card.
If LC accesses an object by NAME, it will always use the object with that name at the lowest layer!
Means, LC only checks if the FIRST (lowest layer) image named "button" is intersecting your other image.

But how is your script:

Code: Select all

...
if within (img "button", the MouseLoc) then
show img "XXX"
end if
if within (img "target", the MouseLoc) then
show img "XXX"
end if
...
triggered?
Mouse-up/down/enter/move?


Best

Klaus

Re: Intersect() or Within Issues

Posted: Thu Dec 12, 2013 6:43 pm
by istech
Hi Klaus,

I think you are right Klaus. I have changed the layer before had the same problem but different image. So if I was to set it using the IDs instead it should be fine? Or should I go at it in the different direction.

I just used this:

on mouseDown
grab me
end mouseDown

on mouseUp
if within (img "button", the MouseLoc) then
show img "XXX"
end if
if within (img "target", the MouseLoc) then
show img "XXX"
end mouseUp

Thanks again Klaus you are a life saver and a credit to the forums.

Re: Intersect() or Within Issues

Posted: Thu Dec 12, 2013 8:05 pm
by Klaus
Hi istech,

I would name the images:
button1
button2
button3
button4

And then use a repeat loop to check ALL of them, that WILL work.
Having multiple objects with the same name IS asking for trouble :D

Code: Select all

on mouseUp
  repeat with i = 1 to 4
    if within (img ("button" & i), the MouseLoc) then
     show img "XXX"

    ## Only ONE hit possible, right? Otherwise delete this line
     exit repeat
   end if
  end repeat
  if within (img "target", the MouseLoc) then
    show img "XXX"
 end if
end mouseUp
Best

Klaus

Re: Intersect() or Within Issues

Posted: Fri Dec 13, 2013 12:42 pm
by istech
Thanks again Klaus

As always your coding touch works and advise followed :lol: