change the link dest of a button

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
fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

change the link dest of a button

Post by fre » Mon Nov 15, 2010 8:03 pm

hi,
is it possible to change the link destination of a button on the fly ?
i have tried the textLink property, but that does not work on buttons.

is it possible to create buttons on the fly ?

how can you pass variables from one card to another card per button click ?

help would be very nice.

best regards,
fre

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: change the link dest of a button

Post by shaosean » Mon Nov 15, 2010 8:51 pm

fre wrote:is it possible to change the link destination of a button on the fly ?
i have tried the textLink property, but that does not work on buttons.
yes, but depends on how you are going about it.. post some samples :-)

fre wrote:is it possible to create buttons on the fly ?
check out the create command.

fre wrote:how can you pass variables from one card to another card per button click ?
different options here: custom properties, putting the script in the stack, using global variables (i personally frown upon this method though).. I am sure there are other methods, lets see what you have tried and we can work from there

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

Re: change the link dest of a button

Post by Klaus » Tue Nov 16, 2010 1:20 pm

Hi fre,

as Sean already mentioned, we need to know your current script(s) and what exactly you mean by "link destination"!
Anyway, here some hints on how to do this with a custom property.

Supposed you want to open the users web browser with a specific internet url.
You could "hard code" the url in the button script:

Code: Select all

on mouseup
  launch url"http://www.server.com/subfolder/index.html"
end mouseup
Works, but is definitvely NOT dynamic!

Now you could add a custom property to theh button (via the inspector -> custom properties), lets call it cTargetUrl and set it to the string "http://www.server.com/subfolder/index.html" (without the quotes!)

Now we change the script of the button to:

Code: Select all

on mouseup
  put the cTargetUrl of me into tTargetUrl
  launch url tTargetUrl
end mouseup
Still works, but the URL is not in the script anymore and so it can be modified when and whereever necessarry
...
## somewhere in your code:
## do this
## do that
set the cTargetUrl of btn X of card y of stack z to "http://wwww.otherserver.com/folder2/anotherurl.html"
...
and the next time the buttn is clicked it will go to that url.
Now that is dynamic :D

I hope you get the picture!

Custom properties are definitively not beginner stuff, but very powerful!
They are just like global variables, but get saved with the stack!


Best

Klaus

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: change the link dest of a button

Post by fre » Tue Nov 16, 2010 4:48 pm

thank you, the custom properties sounds interesting.
but for the moment, i can not get it to work ...

the script shows how i create buttons on the fly and give them custom labels.
after that i want to tell the buttons what should happen if someone is clicking them (go to card 2)
and i want to pass an id along to the called card.

sorry for my english, i am not a native english speaker.

Code: Select all

      

      put 0 into tButtonNumber

      -- tData is an array of data from mysql database
      repeat for each line tLine in tData

         split tLine by column
         add 1 to tButtonNumber
         create button ("b" & tButtonNumber)
         set the label of button ("b" & tButtonNumber) to tLine[2]
         
         -- now give the button a link destination and apend an id ...

         -- the following line is not working:
         set the linkText of the label of button ("b" & tButtonNumber) to card "mycard" 

         -- try to set the link destination with custom properties:
         put "cTargetUrl mycard," into cCustomProperties
         split cCustomProperties by comma and space
         set the customProperties of button ("b" & tButtonNumber) to cCustomProperties
         
         -- now tell the button to go to the value of the property cTargetUrl when it is clicked ...

      end repeat

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

Re: change the link dest of a button

Post by Klaus » Wed Nov 17, 2010 2:23 pm

Hi fre,

you are lacking a lot of basic stuff!
I recommend to work through these stack here:
http://www.runrev.com/developers/lesson ... nferences/

There is more than one line in your script that will not work and trying to set custom properties via an array is erm... unusual and quite creative 8)

OK, I do not know much about your project so I cannot say if creating new buttons is the way to go, athough I doubt.

1. "linktext" is a property of text chunks inside of fields! Won't work for LABELS of buttons!
2. Buttons need to be clicked, so an eventual "mouseup" handler gets triggered, which leads to the conclusion that your buttons
also might need a "mouseup" script to do what you want.
3. Athough you did not mention this, the scripts shows that your buttons should navigate to a specific card after clicked, right?
This is the same mechanism as my internet URL example in my last posting.
4. Please do yourself a favour and lookup all (known or unknown) terms in the Rev dictionary, which isn't that bad :)
5. To start lookup "templateXXX" in the docs.

Here my attempt to make you script (excerpt) work:

Code: Select all

...
   put 0 into tButtonNumber

   ## I will NOT use an array here, but fetch the second item of each line, see ITEMDEL below...
   ## Of course you way does also work!
   set itemdel to TAB

   -- tData is an array of data from mysql database
   repeat for each line tLine in tData
      put item 2 of l into tLabel
      create button ("b" & tButtonNumber)
      set the label of button ("b" & tButtonNumber) to tLabel
        
    -- now give the button a link destination and apend an id ...
     ##ID ??

      ## Here we need to create a SCRIPT for the buttons, see above!!!
      ## This will only work with scripts < 10 lines! 
      ## See "scriptlimit" in the docs!!
       set the script of button ("b" & tButtonNumber) to "on mouseup" & CR & \
            "put the cTargetCardName of me into tTargetCard" & CR & \
              "go card tTargetCard" & CR & "end mouseup"

       ## set the custom property:
       set the cTargetCardName of button ("b" & tButtonNumber) to "mycard"
     
 end repeat
....
This will make your buttons work as you would exspect (or what I think you do exspect 8) )


Best

Klaus

fre
Posts: 41
Joined: Fri Nov 12, 2010 7:22 pm

Re: change the link dest of a button

Post by fre » Thu Nov 18, 2010 10:50 am

yes klaus , you are right. i am lacking a lot of basic stuff.
i know runrev now since one week and of course i am not an expert after that time.
i am reading lessions and the dictionary and the documentation.
and i am trying to get the things i want to make to work. learning by doing.

my project is quit simple:
i am fetching keywords from database and place them on the page one per line.
every keyword must be clickable. when you click on the keyword you open another card.
on this card i show some text depending on the keyword that was clicked.
thats why i need to set a variable when clicking. i think that could be handled by a global variable.
thats all.

i use buttons because i found it easier to style the label of a button than style
the text in a field (my button is transparent with no borders). if i set the text of a field to a link,
i have a blue underlined word ... thats not what i want.

the script is working so far. i fetch data, create buttons, set the style of the labels.
your "set the script of button.." examaple will help me setting the action of the button
and the global variable. but there is one thing i could not fix. when the keyword is clicked,
i see a dotted rect round it. i did not find the right attribute of the button to hide that.
do you know how to do that?

now if you know a better solution than using buttons i would be glad if you could tell me.

again, thanks for you help !

best regards
fred.

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

Re: change the link dest of a button

Post by Klaus » Thu Nov 18, 2010 1:14 pm

Hi Fred,
fre wrote:yes klaus , you are right. i am lacking a lot of basic stuff.
i know runrev now since one week and of course i am not an expert after that time.
i am reading lessions and the dictionary and the documentation.
and i am trying to get the things i want to make to work. learning by doing.
Learning by doing is very good!
Please check the stacks on the url I posted, you will not regret :)
fre wrote:my project is quit simple:
i am fetching keywords from database and place them on the page one per line.
every keyword must be clickable. when you click on the keyword you open another card.
on this card i show some text depending on the keyword that was clicked.
thats why i need to set a variable when clicking. i think that could be handled by a global variable.
thats all.
Can't you do this by just providing a list field?
But maybe I know to little about you project...
fre wrote:i use buttons because i found it easier to style the label of a button than style
the text in a field (my button is transparent with no borders). if i set the text of a field to a link,
i have a blue underlined word ... thats not what i want.
You can set the properties "linkcolor" and "underlinelinks" to make it for for you, see the Rev Dictionary for more info!
fre wrote:the script is working so far. i fetch data, create buttons, set the style of the labels.
your "set the script of button.." examaple will help me setting the action of the button
and the global variable. but there is one thing i could not fix. when the keyword is clicked,
i see a dotted rect round it. i did not find the right attribute of the button to hide that.
do you know how to do that?
Go to the inspector for your butto(s) and uncheck "Icons and Borders" -> "Hilite border"
fre wrote:now if you know a better solution than using buttons i would be glad if you could tell me.
See above, maybe a list field?
Sorry no idea so far, you could send me a copy of your stack, if you like, I am a very visual guy, seeing is believing :)
klausATmajor-k.de

Best

Klaus

Post Reply