britsky
11-03-2009, 04:20 PM
I also posted this in the Newbie section last week, but didn't get a response there yet.
Project:
Reading text from XML document
Text scrolls up, pauses, then automatically scrolls up and off the screen
Text content changes to the next node.
Scene Level:
I have a movie clip named "symbol headline" (see attached screenshot)
Within the Movie Clip:
I have 2 dynamic text boxes: headlineText and contentText (see attached screenshot)
Action Script:
// Import flash libraries
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.xml.*;
import flash.net.*;
// Declare variable to hold XML and load the XML document
var vendorFlash_xml:XML = new XML();
var XML_URL:String = "VendorFlash.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
// This function is run when the load of the XML is complete
function xmlLoaded(event:Event):void
{
vendorFlash_xml = XML(myLoader.data);
var i:int = 1; //Starting at 1 because we'll be displaying the first node manually
var item_count:int = vendorFlash_xml.item.length();
var pattern:RegExp = /\\n/gi; //We'll use \n in the XML to denote a newline. This pattern is used below to insert a \r
var contentString:String //Needed for string replace function
var timer:Timer = new Timer(6000,0); //Timer(milliseconds, repeat count[0 for infinite])
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
// Display the first node so there's not a delay.
headlineText.text=vendorFlash_xml.item[0].headline.text();
contentString=vendorFlash_xml.item[0].content.text();
contentText.text=contentString.replace(pattern,"\r");
function timerHandler(event:TimerEvent):void {
headlineText.text=vendorFlash_xml.item[i].headline.text();
contentString=vendorFlash_xml.item[i].content.text();
contentText.text=contentString.replace(pattern,"\r");
i++;
if (i == item_count) {
i = 0;
}
}
}
The Problem:
Everything works GREAT except there is a slight difference between the TIMER in the ActionScript and the frames in the GUI. That means that after 3 or 4 iterations, the text starts changing before the motion tween is done.
My Idea:
Instead of using a timer in my ActionScript, can I create and Event Listener that listens for when the movie clip starts to replay? If so, HOW ?
This is my first ActionScript project, and I've exhausted my Google abilities to figure out this last hurdle.
Many thanks, and God bless!
-Jeff
Project:
Reading text from XML document
Text scrolls up, pauses, then automatically scrolls up and off the screen
Text content changes to the next node.
Scene Level:
I have a movie clip named "symbol headline" (see attached screenshot)
Within the Movie Clip:
I have 2 dynamic text boxes: headlineText and contentText (see attached screenshot)
Action Script:
// Import flash libraries
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.xml.*;
import flash.net.*;
// Declare variable to hold XML and load the XML document
var vendorFlash_xml:XML = new XML();
var XML_URL:String = "VendorFlash.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
// This function is run when the load of the XML is complete
function xmlLoaded(event:Event):void
{
vendorFlash_xml = XML(myLoader.data);
var i:int = 1; //Starting at 1 because we'll be displaying the first node manually
var item_count:int = vendorFlash_xml.item.length();
var pattern:RegExp = /\\n/gi; //We'll use \n in the XML to denote a newline. This pattern is used below to insert a \r
var contentString:String //Needed for string replace function
var timer:Timer = new Timer(6000,0); //Timer(milliseconds, repeat count[0 for infinite])
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();
// Display the first node so there's not a delay.
headlineText.text=vendorFlash_xml.item[0].headline.text();
contentString=vendorFlash_xml.item[0].content.text();
contentText.text=contentString.replace(pattern,"\r");
function timerHandler(event:TimerEvent):void {
headlineText.text=vendorFlash_xml.item[i].headline.text();
contentString=vendorFlash_xml.item[i].content.text();
contentText.text=contentString.replace(pattern,"\r");
i++;
if (i == item_count) {
i = 0;
}
}
}
The Problem:
Everything works GREAT except there is a slight difference between the TIMER in the ActionScript and the frames in the GUI. That means that after 3 or 4 iterations, the text starts changing before the motion tween is done.
My Idea:
Instead of using a timer in my ActionScript, can I create and Event Listener that listens for when the movie clip starts to replay? If so, HOW ?
This is my first ActionScript project, and I've exhausted my Google abilities to figure out this last hurdle.
Many thanks, and God bless!
-Jeff