[Xerte] Making a page counter in Xerte 1.8 - Solved

Tenney Julian Julian.Tenney at nottingham.ac.uk
Tue Oct 30 08:51:50 GMT 2007


Paul,
 
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?"
 
So, when you execute code in page one, page two doesn't exist yet.
 
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.
 
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).
 
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:
 
icon.nextSibling.attributes.x = 100; //when the parser parses the next
icon, it will create the movieclip with _x = 100;
 
A real world appliaction of this might be something like a dynamic
layout:
 
if (align == 'left'){
  icon.nextSibling.attributes.x = 20;
} else {
  icon.nextSibling.attributes.x = 400; 
}
 
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.
 
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:
 
icon.nextSibling.duplicate(numOfItems - 1);//because you already have
the first one. Do something similar to set the url attribute to load
different images
 
//now set their IDs and build a string for drag items
dragItemsStr = "";
for (i = 0; i < numOfItems; i++){
  icon.parentNode.childNodes[i+i].attributes.id = 'item' + i;
  dragItemsStr += "item" + i + ",snap,0~";
}
 
//now set the dragItems attribute of the target area's xml node before
it is parsed
icon.parentNode.lastChild.firstChild.attributes.dragItems =
dragItemsStr;
 
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.
 
Have fun,
 
Julian


________________________________

	From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
	Sent: 29 October 2007 21:21
	To: Xerte discussion list
	Subject: RE: [Xerte] Making a page counter in Xerte 1.8 - Solved
	
	
	Correction: it is a Time Limit interaction, not Tries Limit.
(But you probably already guessed that...)


________________________________

		From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
		Sent: Monday, October 29, 2007 2:10 PM
		To: Xerte discussion list
		Subject: RE: [Xerte] Making a page counter in Xerte 1.8
- Solved
		
		
		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.
		 
		- Paul


________________________________

			From: xerte-bounces at lists.nottingham.ac.uk
[mailto:xerte-bounces at lists.nottingham.ac.uk] On Behalf Of Paul Swanson
			Sent: Monday, October 29, 2007 1:48 PM
			To: xerte at lists.nottingham.ac.uk
			Subject: [Xerte] Making a page counter in Xerte
1.8
			
			

			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.

			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):

			slideCounter.setText('Slide ' +
(dbInst.currentPage + 1) + ' of ' + dbInst.pages.length); 

			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.

			Is there a better way to do this? 

			_____________________________ 

			 Paul Swanson 
			 Harland Financial Solutions 
			_____________________________ 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.nottingham.ac.uk/pipermail/xerte/attachments/20071030/1d91beca/attachment.html


More information about the Xerte mailing list