Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Action script - infinite loop

Status
Not open for further replies.

WebRic

Technical User
Sep 21, 2004
95
GB
Hi All,

I've been trying to use actionscript to get an xml document. Once done I wanted it to load one element at a time with a fade in / fade out. I've limited knowledge with this but have managed to get it partially working.

There are two dynamic text fields myphoto & mydescrip

The document loads and then fades out the crashes.

I have attached the action script
Code:
#include "tracenode.as"
  
var menu_xml = new XML()
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function (success) {
    test(this);
}
menu_xml.load("homepics.xml");
  
   
function test (node_xml){
    rootElement_xml = node_xml.firstChild;   // get document's root node
	numbElements = rootElement_xml.childNodes.length - 1; // get the number of images
	myRand = Math.round(Math.random()*numbElements);
	doDisplay(myRand);				
					}
function doDisplay(numb) {
	child_xml = rootElement_xml.childNodes[numb];
	thisPhoto = child_xml.childNodes[0].attributes.usephoto;
	thisDescription = child_xml.childNodes[1].attributes.usedescription;
	thisLink = child_xml.childNodes[2].attributes.uselink;
	mydescrip.text = thisDescription;
	myphoto.html=true;
	myphoto.htmlText= '<img src="/images/photos/' + thisPhoto +'" />';
	hideText();
}

//Routine to hide text (call from timer)
function hideText()
{
	//reset timer
	clearInterval(_root.textTimer)
	//if fully hidden, set timer to start showing the new text
	
	//if fully shown, set timer for hiding text in 5 seconds
	if (myphoto._alpha <= 0) 
	{
		newText = true; //Make sure the next time we show the text it will be changed.
		showText();
	}
	else
	{
		
		var textDisplayColor = new Color("mydescrip");
		var textTransform = textDisplayColor.getTransform();
		var picDisplayColor = new Color("myphoto");
		textTransform.aa = textTransform.aa - 5; //Remove 5 on Alpha
		textDisplayColor.setTransform(textTransform);
		picDisplayColor.setTransform(textTransform);
		_root.textTimer = setInterval(hideText, 100);
	}	
}

//Routine to show text (call from timer)
function showText()
{
	//reset timer
	clearInterval(_root.textTimer)
	

	//Work out if we should change the text 
	if (newText)
	{
	numbElements = rootElement_xml.childNodes.length - 1; // get the number of images
	myRand = Math.round(Math.random()*numbElements);
	newText = false;
	doDisplay(myRand);		
	}
	
	//if fully shown, set timer for hiding text in 5 seconds
	if (myphoto._alpha >= 100) 
	{
		_root.textTimer = setInterval(hideText, 5000);
	}
	else
	{
		//myTextDisplay._alpha = myTextDisplay._alpha + 5;
		var textDisplayColor = new Color(mydescrip);
		var textTransform = textDisplayColor.getTransform();
		var picDisplayColor = new Color("myphoto");
		textTransform.aa = textTransform.aa  + 5; //Add 5 to the Alpha
		textDisplayColor.setTransform(textTransform);
		picDisplayColor.setTransform(textTransform);
		_root.textTimer = setInterval(showText, 100);
	}
}

I've spent all day trying to figure this out so I'd love some help.
Thanks,

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top