Page 1 of 1

Problems with cloning an image

Posted: Wed May 04, 2011 11:07 am
by Tomka
Hi,

i´m new here and I got a problem with a little Script.

I got a card with a .png-image and a button. I want that i`m able to select the image and clone it when I push the button.

Script of the .png-image:

Code: Select all

on mouseDown
   PersonMove //used for Drag&Drop
   set the selected of me to true
   put the selectedObject into gsle_Item
end mouseDown
Script of the button:

Code: Select all

global gsle_Item

on mouseUp
   clone image gsel_item
end mouseUp
It gives me errors: "no such object".

I also tried in the button-script:

Code: Select all

global gsle_Item

on mouseUp
   clone the selectedObject
end mouseUp
but it results in the same error.


When i used following script in the image, it works fine (buts not what i need):

Code: Select all

on mouseDown
   clone me
end mouseDown
Sorry for my bad english, its not my native language but I hope you may help me to solve the problem.

Re: Problems with cloning an image

Posted: Wed May 04, 2011 11:18 am
by Klaus
Hi Tomka,

1. looks like the GLOBAL declaration is missing in your image script!

Code: Select all

on mouseDown
   GLOBAL gsle_Item
   PersonMove //used for Drag&Drop
   set the selected of me to true
   put the selectedObject into gsle_Item
end mouseDown
2. "the selectedobject" returns somehting like: button id 1003 of card id 1002 of stack "Stack 1304504115"
Which includes the KIND of object "image/button/field..."!
So you need to omit the "image" in your button script:

Code: Select all

global gsle_Item
on mouseUp
   clone gsel_item
end mouseUp

Best from germany

Klaus

Re: Problems with cloning an image

Posted: Wed May 04, 2011 12:10 pm
by Tomka
Hi Klaus,

thanx for your answer. I tried this out but when i push the button following error results:
executing at 1:09:17 PM
Type Chunk: error in object expression
Object Button
Line clone gsel_item
Hint gsel_item

Re: Problems with cloning an image

Posted: Wed May 04, 2011 12:33 pm
by Klaus
Hi Tomka,

I am not sure what is going on here, but this does work!
Image:

Code: Select all

on mouseDown
   GLOBAL gsle_Item
   PersonMove //used for Drag&Drop
   put the name of me into gsle_Item
   ##  Or this:
   put the long ID of me into gsle_Item
   ## Although this is exactly what "the selectedobjct" returns!?
end mouseDown
Button:

Code: Select all

global gsle_Item
on mouseUp
   clone gsel_item
end mouseUp
Best

Klaus

Re: Problems with cloning an image

Posted: Wed May 04, 2011 12:43 pm
by jmburnod
Hi Tomka

You have two names for your global "gsel_Item" or "gsle_Item", Choose one and all work well

All the best

Jean-Marc

Re: Problems with cloning an image

Posted: Wed May 04, 2011 1:18 pm
by Klaus
Bonjour Jean-Marc,

arrrrrghhh 8)
I imagined that, but did not see the typo!

Thanks, I am wearing glasse, if that counts as an excuse :D


Best

Klaus

Re: Problems with cloning an image

Posted: Wed May 04, 2011 1:22 pm
by Tomka
Thanx alot.

Didnt saw the mistake in the names but it wasnt the only problem. But now it works.

Best wishes
Thomas

Re: Problems with cloning an image

Posted: Wed May 04, 2011 1:36 pm
by Tomka
Mhhh, now theres an other new problem. The cloned image isnt dragable anymore.

I uploaded the stack. Maybe its easier to check out what Imean.

Thomas

Re: Problems with cloning an image

Posted: Wed May 04, 2011 2:42 pm
by jmburnod
Hi Tomka,

My english is poor also.

For the img "image"

Code: Select all

on mouseDown
   global gsel_Item
    put the long ID of me into gsel_Item
   if the optionkey is down then --•• or other codition
      set the selected of me to false
      PersonMove
   else
         set the selected of me to true
   //put the ID of the selectedObject into fld 1
   end if
end mouseDown

on mouseUp
   set the selected of me to false
end mouseUp
For the cd script

Code: Select all

on mouseDown
   //set the selected of the selectedObject to false
   put "" into fld 1
end mouseDown

on PersonMove
   global gsel_Item
   grab gsel_Item
end PersonMove
Good luck for the next

Jean-Marc

Re: Problems with cloning an image

Posted: Mon May 09, 2011 12:15 pm
by Tomka
Thanx alot for your help. It works now but I got a little problem with the following code:

Code: Select all

global gsel_item

    on mouseDown
        if gsel_item<>"" then
           set the selected of the selectedObject to false
           put "" into gsel_item
        end if
       put gsel_item into fld 1
    end mouseDown
When I select the image it´s set to selected - works fine. But when I push the button to clone it, the image will be deselected cause of the card-script above.

Any ideas how I can deselect the image-object when I push on the background but not if I click a button?

Re: Problems with cloning an image

Posted: Mon May 09, 2011 1:10 pm
by Klaus
Hi Tomk,

when your buttons do NOT have a "mousedown" handler in their own scripts,
then the next "found" "mousedown" handler in the "message heirrachie" will get executed!

To prevent this, add a "dummy" (empty) "mousdown" handler to your "clonnig" button scripts
that should not execute the card "mousdown" handler:

Code: Select all

on mousedown
  ## Nothing
end mousedown

on mouseup
  ## do your clonin stuff...
  ...
end mouseup
And check this great article about the "message path hierarchie" in LiveCode:
http://www.fourthworld.com/embassy/arti ... _path.html

Best

Klaus

Re: Problems with cloning an image

Posted: Mon May 09, 2011 1:23 pm
by Tomka
Great Klaus... it works.

Thanx alot.