Problems with cloning an image

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Problems with cloning an image

Post by Tomka » Wed May 04, 2011 11:07 am

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.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problems with cloning an image

Post by Klaus » Wed May 04, 2011 11:18 am

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

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Problems with cloning an image

Post by Tomka » Wed May 04, 2011 12:10 pm

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

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problems with cloning an image

Post by Klaus » Wed May 04, 2011 12:33 pm

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

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Problems with cloning an image

Post by jmburnod » Wed May 04, 2011 12:43 pm

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
https://alternatic.ch

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problems with cloning an image

Post by Klaus » Wed May 04, 2011 1:18 pm

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

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Problems with cloning an image

Post by Tomka » Wed May 04, 2011 1:22 pm

Thanx alot.

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

Best wishes
Thomas

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Problems with cloning an image

Post by Tomka » Wed May 04, 2011 1:36 pm

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
Attachments
Objekt_kopieren.zip
(7.89 KiB) Downloaded 246 times

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Problems with cloning an image

Post by jmburnod » Wed May 04, 2011 2:42 pm

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
https://alternatic.ch

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Problems with cloning an image

Post by Tomka » Mon May 09, 2011 12:15 pm

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?

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Problems with cloning an image

Post by Klaus » Mon May 09, 2011 1:10 pm

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

Tomka
Posts: 59
Joined: Mon Apr 18, 2011 7:30 pm

Re: Problems with cloning an image

Post by Tomka » Mon May 09, 2011 1:23 pm

Great Klaus... it works.

Thanx alot.

Post Reply