<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Making a page counter in Xerte 1.8</TITLE>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>Paul,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>You're really getting into the innards of things here. The
reason is this. The .rlo is a hierarchical xml file. The engine parses it, by
looping through each node, then all of it's children, and so on, and then on to
the next node. As it encounters each node it says 'what have I got here?
Oh, a node that defines a Graphic icon - better add a graphic to the
screen. What's next?"</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>So, when you execute code in page one, page two doesn't
exist yet.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>Each icon can be thought of as two things: the xmlNode in
the rlo file, and the resulting MovieClip on the stage. Each MovieClip keeps a
reference to it's corresponding XML node, in the .XMLElement property. This can
be useful sometimes.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>Also, note that the XML file is fully loaded before it is
parsed. So whilst rootIcon.pages.length will be 1 in the first page (because the
parser hasn't added the other pages yet), icon.parentNode.childNodes.length WILL
contain the right number of children for the framework. Alternatively
rootIcon.XMLElement.childNodes.length will do the same thing. Sometimes it is
more convenient to use the XML to figure things out than the MovieClips. You
always have all of the XML. You don't always have all of the MovieClips (items
inside an interaction response for example).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>This brings us to an important point for the more hardcore
Xerte developer. Because the XML hasn't finished parsing, you can manipulate it
at runtime before it is parsed to create dynamic pieces on the fly. Try a script
before a text icon that sets it's attributes:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>icon.nextSibling.attributes.x = 100; //when the parser
parses the next icon, it will create the movieclip with _x =
100;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>A real world appliaction of this might be something like a
dynamic layout:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>if (align == 'left'){</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2> icon.nextSibling.attributes.x =
20;</FONT></SPAN></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>} else {</FONT></SPAN></DIV><SPAN
class=689493108-30102007><FONT face=Verdana color=#0000ff size=2>
icon.nextSibling.attributes.x = 400;</FONT></SPAN>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>Of course, you could position the MovieClips with a script
after them as well. There are some things that are much more convenient to do on
the XML though, for instance adding dragItems to a target area response. You
might not know ahead of time how many items to add, or what their IDs
are.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>So, you have a script above a graphic above an interaction
with a target area on it. You can create as many graphics as you
need:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>icon.nextSibling.duplicate(numOfItems - 1);//because you
already have the first one. Do something similar to set the url attribute to
load different images</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>//now set their IDs and build a string for drag
items</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>dragItemsStr = "";</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>for (i = 0; i < numOfItems; i++){</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2> icon.parentNode.childNodes[i+i].attributes.id =
'item' + i;</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2> dragItemsStr += "item" + i +
",snap,0~";</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>}</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=689493108-30102007><FONT face=Verdana
color=#0000ff size=2>//now set the dragItems attribute of the target area's xml
node before it is parsed</FONT></SPAN></DIV>
<DIV dir=ltr align=left><FONT face=Verdana><FONT size=2><FONT
color=#0000ff><SPAN
class=689493108-30102007>icon.parentNode.lastChild.firstChild.attributes.dragItems
= dragItemsStr;</SPAN></FONT></FONT></FONT></DIV>
<DIV dir=ltr align=left><FONT face=Verdana><FONT size=2><FONT
color=#0000ff><SPAN class=689493108-30102007></SPAN><SPAN
class=689493108-30102007></SPAN><SPAN
class=689493108-30102007></SPAN></FONT></FONT></FONT> </DIV>
<DIV><SPAN class=689493108-30102007><FONT face=Verdana color=#0000ff size=2>This
technique opens up VERY powerful possibilities, akin to creating Authorware
icons at runtime, particuarly when loading a seperate XML file to drive a
template.</FONT></SPAN></DIV>
<DIV><SPAN class=689493108-30102007><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=689493108-30102007><FONT face=Verdana color=#0000ff size=2>Have
fun,</FONT></SPAN></DIV>
<DIV><SPAN class=689493108-30102007><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=689493108-30102007><FONT face=Verdana color=#0000ff
size=2>Julian</FONT></SPAN></DIV>
<DIV dir=ltr align=left><BR></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk
[mailto:xerte-bounces@lists.nottingham.ac.uk] <B>On Behalf Of </B>Paul
Swanson<BR><B>Sent:</B> 29 October 2007 21:21<BR><B>To:</B> Xerte discussion
list<BR><B>Subject:</B> RE: [Xerte] Making a page counter in Xerte 1.8 -
Solved<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=718261921-29102007><FONT face=Arial
color=#0000ff size=2>Correction: it is a Time Limit interaction, not Tries
Limit. (But you probably already guessed that...)</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk
[mailto:xerte-bounces@lists.nottingham.ac.uk] <B>On Behalf Of </B>Paul
Swanson<BR><B>Sent:</B> Monday, October 29, 2007 2:10 PM<BR><B>To:</B> Xerte
discussion list<BR><B>Subject:</B> RE: [Xerte] Making a page counter in
Xerte 1.8 - Solved<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=741500721-29102007><FONT face=Arial
color=#0000ff size=2>It seems to be a timing issue. I added a 0.1 second
Tries Limit interaction before the script that prints the counter on the
first page, and it correctly prints the number of pages in the
framework.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=741500721-29102007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=741500721-29102007><FONT face=Arial
color=#0000ff size=2>- Paul</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> xerte-bounces@lists.nottingham.ac.uk
[mailto:xerte-bounces@lists.nottingham.ac.uk] <B>On Behalf Of </B>Paul
Swanson<BR><B>Sent:</B> Monday, October 29, 2007 1:48 PM<BR><B>To:</B>
xerte@lists.nottingham.ac.uk<BR><B>Subject:</B> [Xerte] Making a page
counter in Xerte 1.8<BR></FONT><BR></DIV>
<DIV></DIV><!-- Converted from text/rtf format -->
<P><FONT face=Arial size=2>I've been working on creating a page counter
within a Framework, and when you get to the first page of the framework,
the total number of pages isn't calculating correctly.</FONT></P>
<P><FONT face=Arial size=2>I have an empty text icon with an ID of
'slideCounter' that is in the Entry Frame of the framework. The framework
ID is dbInst. I am placing the following code in a script icon on each
page (not in the Entry Frame):</FONT></P>
<P><FONT face="Lucida Console" size=2>slideCounter.setText('Slide ' +
(dbInst.currentPage + 1) + ' of ' + dbInst.pages.length);</FONT> </P>
<P><FONT face=Arial size=2>On the first page of the framework, this prints
'Slide 1 of 1'. Moving to the second page, it correctly prints 'Slide 2 of
20' and returning to the previous page, it prints 'Slide 1 of 20' -- so it
isn't giving the correct value for the length of the pages array on the
first pass, but correctly does so after that. And if that wasn't strange
enough, if I use Ctrl+F5 to open Page 1, it displays the correct values,
but if I navigate to this framework from the page prior to it (or use
Ctrl+F5 with the Framework icon selected), it displays the incorrect
value.</FONT></P>
<P><FONT face=Arial size=2>Is there a better way to do this?</FONT> </P>
<P><FONT face="Courier New" color=#808080
size=2>_____________________________</FONT> </P>
<P><FONT face="Courier New" color=#808080 size=2> Paul Swanson</FONT>
<BR><FONT face="Courier New" color=#808080 size=2> Harland Financial
Solutions</FONT> <BR><FONT face="Courier New" color=#808080
size=2>_____________________________</FONT>
</P></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>