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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scroll XML data stored in FLASHMX 1

Status
Not open for further replies.

bubu

Programmer
Mar 3, 2002
463
RO
Hello guys!

Some days ago i have posted a question about XML and FLASHMX interaction.
David and Wangbar helped me understand how can i do this but now i want another thing:

On the timeline i have a textbox that displays the data from the XML file and i want to scroll it's content with actionscript...from left to right or from right to left.

Regards,
Dragos.

dragos.jpg

 
In MX each textfield has an hscroll property that controls horizontal scrolling. Place a dynamic textfield on the stage with instance name "myTextField" and add this to frame 1 of the movie:


myTextField.text = "loads and loads of text loads and loads of text loads and loads of text loads and loads of text ";
_global.speed = 5;
this.onEnterFrame = function() {
myTextField.hscroll += speed;
};


 
If i have a dynamic textbox that reads the text from an xml file can i add this action to the first frame of the movie to make the text scroll?

_global.speed = 5;
this.onEnterFrame = function() {
myTextField.hscroll += speed;
};


AND another thing: why the files that David posted in the other thread you answered me about xml vs flash doesn't work on my machine? (the .fla and the .xml files)...because his .swf works properly.



Regards,
Dragos.

dragos.jpg

 
Yes. Turn your parsed XML data into a string variable (both Dave and I did that with the code we posted) and set myTextField.text equal to that variable. Remember though that XML takes time to load in and be parsed so there will be a delay before it shows up. Assign the variable to the text field in the 'onLoad' function.
 
So my code will look something like this:

//reading the text from the xml file
flightsXML = new XML();
flightsXML.ignoreWhite = true;
flightsXML.onLoad = convertXML;
flightsXML.load('flights.xml');
numFlights=3;
destinationArray = new Array();
priceArray = new Array();
function convertXML() {
if (flightsXML.loaded) {
for (i=0; i<numFlights; i++) {
destinationArray = flightsXML.firstChild.childNodes.attributes.Destination;
priceArray = flightsXML.firstChild.childNodes.attributes.Price;
}
for(i=0;i<numFlights;i++) {
output+=destinationArray+&quot; &quot;+priceArray+&quot;::&quot;;

}
} else {
convertXML();
}
}

//scrolling the text
onLoad(){
flights=output;
}
_global.speed = 5;
this.onEnterFrame = function() {
myTextField.hscroll += speed;
};


//instance name of the textbox=myTextField
variable name=flights



I began learning actionscript for couple of weeks so please excuse me because i want everything step by step...can be boring with you.

P.S. I have tried with the files of David and with your actions but it doesn't work on my machine...don't know why. Do you know what can be the problem?








Regards,
Dragos.


 
And another thing WANGBAR:

I want the text to scroll continuosly...with no break between repetitions. Regards,
Dragos.


 
This should work:

Code:
_global.output;
_global.speed = 5;
_global.textLoaded = false;
//reading the text from the xml file
flightsXML = new XML();
flightsXML.ignoreWhite = true;
flightsXML.onLoad = convertXML;
flightsXML.load('flights.xml');
numFlights = 3;
destinationArray = new Array();
priceArray = new Array();
//
function convertXML() {
	if (flightsXML.loaded) {
		for (i=0; i<numFlights; i++) {
			destinationArray = flightsXML.firstChild.childNodes.attributes.Destination;
			priceArray = flightsXML.firstChild.childNodes.attributes.Price;
		}
		for (i=0; i<numFlights; i++) {
			output += destinationArray+&quot; &quot;+priceArray+&quot;::&quot;;
		}
		//
		textLoaded = true;
		myTextField.text = output;
		//
	} else {
		convertXML();
	}
}
this.onEnterFrame = function() {
	if (textLoaded) {
		myTextField.hscroll += speed;
	}
};

Also - it's worth using Dave's way of setting up the loop in the code it's more dynamic that what I supplied.

As to why it's not working, could be loads of things - my code works on my machine, so does Dave's. Have you tried tracing the XML to see if it's loading in?
 
The xml file is loading...i will use this code right now and let you know what happened. Regards,
Dragos.


 
I have changed the code a little bit and now it looks something like this:

_global.output;
_global.speed = 50;
_global.textLoaded = false;
// reading the text from the xml file
flightsXML = new XML();
flightsXML.ignoreWhite = true;
flightsXML.onLoad = convertXML;
flightsXML.load('flights.xml');
//
function convertXML() {
if (flightsXML.loaded) {
for (i=0; i<flightsXML.firstChild.childNodes.length; i++) {
output += flightsXML.firstChild.childNodes.attributes.Destination+&quot; &quot;+flightsXML.firstChild.childNodes.attributes.Price+&quot;::&quot;;
}
//
textLoaded = true;
myTextField.text = output;
//
} else {
convertXML();
}
}
this.onEnterFrame = function() {
if (textLoaded) {
myTextField.hscroll += speed;
}
};




Everything works fine but i want the text to scroll continuosly from left to right...you understand what i want?
Regards,
Dragos.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top