Importing an image via a button into a different stack?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Importing an image via a button into a different stack?

Post by richmond62 » Wed Jan 17, 2024 12:44 pm

Imagine, if you will, a palettised stack containing a button with this script:

Code: Select all

on mouseUp
   answer file "Select image:"
   if the result is not cancel then
      set the lockscreen to true
      put the short name of the topStack into STAKK
      import paint from file it to stack STAKK
      set the name of the last control to "XYZ"
   end if
end mouseUp
Now what ACTUALLY happens with this script is that my imported image ends up in the stack containing my button, and NOT my target stack.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Importing an image via a button into a different stack?

Post by bn » Wed Jan 17, 2024 4:00 pm

Richmond,

this works for me.

Code: Select all

on mouseUp
   put the topStack into STAKK
   if (the short name of this stack) is STAKK or STAKK is empty then
      answer "activate the target stack first" with "Ok"
      exit mouseUp
   end if
   answer file "Select image:"
   if the result is not cancel then
      set the lockscreen to true
      set the defaultStack to STAKK
      import paint from file it 
      set the name of the last control to "XYZ"
   end if
end mouseUp
Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Importing an image via a button into a different stack?

Post by richmond62 » Wed Jan 17, 2024 4:14 pm

Super!

Thank you, Bernd.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”