Dual Revlets—two stacks on a page

Two stacks can communicate with each other just as they do in the LiveCode IDE, provided they are opened in the same instance of the RunRev plug-in. The example below consists of a main stack named “Rev Errors” which contains a list of error codes, and its substack that has a number entry field with a “Lookup” button. Two separate stacks should work just as well.

To see it work, enter a number into the entry field and the matching entry in the list will be selected. The two stacks communicate with each other. Clicking the button in the Lookup stack sends a message to the Rev Errors stack, along with a parameter which is the number. The Rev Errors stack finds the correct line number, hilites the line in its list, and sends a message back to the Lookup stack with a parameter that is the text of the error. The Lookup stack then displays that text. If nothing is returned, it displays “not found”.

Here is stack “Rev Errors”:

And this is stack “Lookup”:

Setting up the Javascript

The trick is to set up the javascript on the page so that each object declaration is in its own <div> section, and each stack uses the same instanceID. The instanceID is a parameter that is declared in the object declaration. Here is a table describing the parameters:

Parameter Description Example
src The URL to the revlet file on disk, either as a relative or complete path. URL-encode the path if it contains spaces or other punctuation. src="/codebits/reverrors.revlet"
width The width of the revlet in pixels. width=377
height The height of the revlet in pixels. height=407
stack The short name of the stack to display. For stacks with substacks, this is how to specify a substack. stack="Rev Errors"
requestedName The same as the stack name. You could probably omit this parameter if your irev page doesn't need to know which stack was requested. requestedName="Rev Errors"
instanceID This is the important parameter for displaying multiple stacks on a page. The instanceID must match for each object declaration. instanceID="3"
type Used in the embed declaration, and is always “application/x-revolution” type="application/x-revolution"

In the javascript segment that displays the above example, note that the instanceID of both object declarations are the same number:


<div id="plugin" style="width:377px; height:407px; 
margin:0px 146px 0px 0px; float=right">
<object classid="CLSID:B2EC94AF-4716-4300-824A-3314BF23664A" 
width=377 height=407>
  <param name="src" value="Rev%20Errors.revlet"/>
  <param name="stack" value="Rev Errors"/>
  <param name="requestedName" value=""/>
  <param name="instanceID" value=""/>
  <embed type="application/x-revolution"
	src="Rev%20Errors.revlet"
	width=377 height=407
	stack="Rev Errors"
	requestedName="Rev Errors"
	instanceID="3"
  ></embed>
</object>
</div>


<div id="plugin" style="width:213px; height:189px;
margin:0px 0px 0px 0px; 150px">
<object classid="CLSID:B2EC94AF-4716-4300-824A-3314BF23664A"
width=213 height=189>
  <param name="src" value="Rev%20Errors.revlet"/>
  <param name="stack" value="Lookup"/>
  <param name="requestedName" value=""/>
  <param name="instanceID" value=""/>
  <embed type="application/x-revolution"
	src="Rev%20Errors.revlet"
	width=213 height=189
	stack="Lookup"
	requestedName="Lookup"
	instanceID="3"
  ></embed>
</object>
</div>

The stack scripts

The script in the Lookup button calls a handler doLookup in the card, with a parameter that contains the user entry in the field. The doLookup handler looks like this:


on doLookup pNum
   put word 1 to -1 of line 1 of fld 1 into tEntry
   if tEntry is not a number then
      select text of fld 1
   else
      send "lookup tEntry" to stack (the mainstack of this stack)
   end if
end doLookup

The script in the Rev Errors stack script looks like this:


on lookup pNum
   put "" into tFeedback
   get lineoffset (pNum & tab, fld "errorList")
   if it > 0 then
      set the hilitedline of fld 1 to it
      put line it of fld 1 into tFeedback
   else
      set the hilitedline of fld 1 to 0
      put "Not found" into tFeedback
   end if
   put tFeedback into fld "feedback" of cd 1 of stack "lookup"
end lookup

The two stacks talk to each other just fine.

 

Code Bits

  • On-Rev CGI example: A rotating image display that uses very little code, thanks to iRev scripting. Gives you a look at my own garden flowers too.

  • CGIs in irev pages. Combine old-style Rev CGIs with on-rev scripts.

Games

  • MadLibs Make a crazy story. You never know what you'll get. Madlibs is an experiment using posted data within an iRev script.

Jacque’s pen

The birds