I have an actionscript that I have modified from developphp. The script works fine (see code below). The problem that I have is that I am wanting to add a timer to pause the for loop, this way it only shows 1 ListItem from the XML at a set time. A cool animation in and out would be great also, but that comes next.
Right now the XML file has 3 list items (could be more or less) and the action script gets the values from each list item (see example below). The problem is that the actionscript currently shows all 3 by drawing a rectangle for each listitem at a set distance apart from each other, what I need to happen is for it to show the 1st listitem for X seconds, then move to the next and once it lands on the last listitem return to the first.
I am new to flash and only know ASP.NET by heart, so I am getting really confused in the syntax and APIs. So any help, examples, etc.. would be GREAT!!
------------------------
XML FILE EXAMPLE
------------------------
<?xml version="1.0" encoding="utf-8"?>
<XML>
<myXMLList>
<ListItem>
<itemColor>664204</itemColor>
<itemLabel>Christmas Party!</itemLabel>
<itemText>Come Join the Fun</itemText>
</ListItem>
<ListItem>
<itemColor>664204</itemColor>
<itemLabel>Announcement 2</itemLabel>
<itemText>Stuff about announcement 2</itemText>
</ListItem>
<ListItem>
<itemColor>664204</itemColor>
<itemLabel>announcement 3</itemLabel>
<itemText>There could be any number of announcements in this file</itemText>
</ListItem>
</myXMLList>
</XML>
---------------------------
ActionScript - Kinda Long Sorry about that
--------------------------
import flash.text.TextFormat;
import flash.text.StyleSheet;
import flash.text.TextField;
// Set the "y" location on stage where the first box will live
var yPlacement:int = 20;
// Set the "x" location on stage where all boxes will line up vertically
var xPlacement:int = 30;
// Set the distance each box should be apart here
var distance:int = 770; //Wont be needed after timer/pause is figured out
// Initialize the XML, place the xml file name, initialize the URLRequest
// put URLRequest into a new URLLoader, and add event listener on
// myLoader listening for when the XML loading is complete
var myXML:XML = new XML();
var XML_URL:String = "myXMLFile.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", xmlLoaded);
// Create the xmlLoaded function
function xmlLoaded(event:Event):void {
// Place the xml data into the myXML object
myXML = XML(myLoader.data);
// Initialize and give var name to the new external XMLDocument
var xmlDoc:XMLDocument = new XMLDocument();
// Ignore spacing around nodes
xmlDoc.ignoreWhite = true;
// Define a new name for the loaded XML that is the data in myLoader
var menuXML:XML = XML(myLoader.data);
// Parse the XML data into a readable format
xmlDoc.parseXML(menuXML.toXMLString());
// store CSS styles in a String variable
var css1:String = ".bv{color:#fafafa; font-family:Arial; font-size:32px; font-weight:bold; border:false;}";
var css2:String = ".abv{color:#815303; font-family:Arial; font-size:16px; font-weight:normal; border:false;}";
// Defines the instance for the "StyleSheet" object
var styles1:StyleSheet = new StyleSheet();
var styles2:StyleSheet = new StyleSheet();
// Applies the "parseCSS" method to the variable with the CSS styles
styles1.parseCSS(css1);
styles2.parseCSS(css2);
// Run the "for each" loop to iterate through all of the menu items listed in the external XML file
for each (var ListItem:XML in myXML..ListItem) {
// Access the value of the "itemColor" node in our external XML file
var listColor:String = ListItem.itemColor.toString();
// Access the value of the "itemLabel" node in our external XML file
var listLabel:String = ListItem.itemLabel.toString();
// Access the value of the "itemPhone" node in our external XML file
var listText:String = ListItem.itemText.toString();
// This all pertains to the style of the Box that holds each person
var rect:Shape = new Shape;
var color:Number = Number("0x"+listColor);
rect.graphics.beginFill(color);
rect.graphics.lineStyle(0, 0x000000);
// Draw the Box
rect.graphics.drawRoundRect(0, 0, 745, 175, 10);
rect.alpha = 0.3;
// This all pertains to the text fields that give our boxes their labels
var myText1:TextField = new TextField();
myText1.styleSheet = styles1;
myText1.text = '<span class="bv">'+listLabel+'</span>'; // uses the "styleSheet" property bv to attach the CSS styles to the "txt" instance
myText1.autoSize = TextFieldAutoSize.LEFT;
myText1.x = 2;
myText1.y = 2;
var myText2:TextField = new TextField();
myText2.styleSheet = styles2;
myText2.text = '<span class="abv">'+listText+'</span>'; // uses the "styleSheet" property bv to attach the CSS styles to the "txt" instance
myText2.multiline = true;
myText2.wordWrap = true;
myText2.width = 740;
myText2.height = 170;
myText2.x = 10;
myText2.y = 25;
// Create MovieClip holder for each box graphic and text labels to organize everything into container
var clip_mc = new MovieClip();
//Add the rectangle graphic
clip_mc.addChild(rect);
// Add the text fields
clip_mc.addChild(myText1);
clip_mc.addChild(myText2);
// Put the new movieClip on stage now
addChild(clip_mc);
// Now apply it in its offset Y position to the stage
clip_mc.y = yPlacement;
// X position that it will be placed on stage
clip_mc.x = xPlacement;
// Offset each one in the loop to make sure they don't just get put right on top of each other
xPlacement = xPlacement + distance; //This line is to be removed once a pause/timer function is figured out
}
}