HTML into an image object

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
townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

HTML into an image object

Post by townsend » Fri Jul 01, 2011 4:40 pm

How do I get HTML from a Field variable into an Image object?

This code works well on displaying HTML from a local file:

Code: Select all

     put "file:///z:\4livecode\test.html" into field my.url
     put the windowid of this stack into tWinID
     put revBrowserOpen(tWinID,field my.url) into sBrowserId   
     revBrowserSet sBrowserId, "rect",rect of image browser.image
Do I have to write my Field text to a file before it can be displayed?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: HTML into an image object

Post by Mark » Fri Jul 01, 2011 6:55 pm

Hi,

Your scripting style is horrible. You really need to fix that to make it easier for other people to read your scripts and help you.

I don't think you need a field. When you open a new browser window, you need to specify a URL. You don't need to put this URL into a field first. Nonetheless, your script should work. Do you see any errors or unexpected behaviour? What does sBrowserID contain? What is the result after executing the revBrowserSet command? Try this:

Code: Select all

put "file:///z:\4livecode\test.html" into myUrl
put the windowID of this stack into myWindowID
put revBrowserOpen(myWindowID,myUrl) into gBrowserID 
if gBrowserID is an integer then
  revBrowserSet gBrowserID,"rect",the rect of img "Name of Image"
  put the result into rslt
  if rslt is not empty then
    beep
    answer error rslt
  end if
else
  beep
  answer error gBrowserID
end if
Always put quotes around object names, unless these object names are in variables. Instead of an image, you could use any placeholder, e.g. a transparent or even invisible button, or you could define a variable or constant in the script and assign a rect to it.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: HTML into an image object

Post by townsend » Fri Jul 01, 2011 7:26 pm

That was just some code I copied from an example. I really didn't understand it completely-- but it worked.
I like your version much better. Okay... I'll start using quotes around my object names. :idea:

And... I probably didn't phrase my question correctly. What I was really trying to do is this.
When you put real HTML in the URL value, it doesn't work.

Code: Select all

put "<html><body>Hello World</body></html>" into myUrl  --<<<====
put the windowID of this stack into myWindowID
put revBrowserOpen(myWindowID,myUrl) into gBrowserID 
if gBrowserID is an integer then
  revBrowserSet gBrowserID,"rect",the rect of img "browser.image"
  put the result into rslt
  if rslt is not empty then
    beep
    answer error rslt
  end if
else
  beep
  answer error gBrowserID
end if
Thanks for your help Mark.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: HTML into an image object

Post by Mark » Sat Jul 02, 2011 2:54 am

Hi,

You might want to open a browser with an empty url. Unfortunately, this seems to be buggy and using about:blank might be more reliable. Replace

Code: Select all

put revBrowserOpen(myWindowID,myUrl) into gBrowserID 
with

Code: Select all

put revBrowserOpen(myWindowID,"about:blank") into gBrowserID 
Now put the htmlText into a variable and set the htmlText property of the browser window.

Code: Select all

put "<html><body>Hello World</body></html>" into myHtml
revBrowserSet gBrowserID,"htmlText",myHtml
Make sure to add the error checking procedures.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm

Re: HTML into an image object

Post by townsend » Sat Jul 02, 2011 7:13 pm

Wow! That worked. Thanks Mark!

And just in case others are following along, here's the code:

Code: Select all

on mouseUp
     put "<html><body>Hello World</body></html>" into myHTML
     put the windowID of this stack into myWindowID
     put revBrowserOpen(myWindowID, "about:blank") into gBrowserID 
     if gBrowserID is an integer then
          revBrowserSet gBrowserID,"htmlText", myHtml
          put the result into rslt
          if rslt is not empty then
               beep
               answer error rslt
          end if
          revBrowserSet gBrowserID,"rect", the rect of image "browserimage"
          put the result into rslt
          if rslt is not empty then
               beep
               answer error rslt
          end if
     else
          beep
          answer error gBrowserID
     end if
end mouseUp
An interesting point to note, to accomplish this, the revBrowserSet command had to be called twice with different parameters.

Post Reply