Is it possible to replace words with imagesource based upon user input?

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Sep 16 08:21:31 EDT 2006


Hi William,

I would not use the imageSource property but would handle the html.
Why?
Because imageSource applies only to a "real entity" in a field and  
html allows to handle variables: much faster ;-)

on mouseUp
   constant kWords = "School,Pupil,Pencil" -- etc.
   constant kImages = "1001,1002,1003" -- corresponding IDs in the  
same order
   local tSentence,tFound
   ------
   ask "Write a sentence:" with "New sentence"
   if it = empty or it = "New sentence" then exit mouseUp
   put it into tSentence
   -----
   repeat with i = 1 to the number of items of kWords
     put wordOffset(item i of kWords, tSentence) into tFound
     if tFound <> 0 then
       replace item i of kWords with "<img src=" & item i of kImages  
& ">" in tSentence
     end if
   end repeat
   set the htmlText of fld "Text" to "<p>" & tSentence & "</p>"
end mouseUp

Note the compulsory parity between words and images IDs constants.
In addition, you might be interested in my "Encoded text picker"  
plugin that will allow you to test many html combinations and  
understand them easily.
See my website.

Le 16 sept. 06 à 13:07, William de Smet a écrit :

> Here's a nice one. I'd like to replace chars with imagesource based
> upon user input and so far I came up with this:
> on mouseUp
>  Ask "Write a sentence:"
>  put it into fld "text"
>  if the text of fld "text" contains "school"
>  then replace "school" with "Q" in fld "text"
>  then set the imagesource of the last char of fld "text" to 1009
>  end if
> end mouseUp
>
> As you can see there is a problem with this script:
> - always the last char is replaced with the imagesource even if there
> are three words in the sentence. It only works when you put just one
> word into it and that word is "school".
>
> I know I have to make a statement for every word the user puts into
> the sentence.
> I don't know you to combine it.
> Is it possible to replace a whole word with an imagesource?
>
> Who has a good idea?
>
> greetings,
>
> William de Smet


Best Regards from Paris,
Eric Chatonet
------------------------------------------------------------------------ 
----------------------
http://www.sosmartsoftware.com/    eric.chatonet at sosmartsoftware.com/





More information about the Use-livecode mailing list