Hello,
I am in the process of making an animation that takes text from an XML document and displays it in a scrollPane. I had this working when I was just using string variables. Now with XML it seems to ignore the new line characters. I have looked all over but nothing is working. Now that I think about it, special cahracters like “%3C” are not working. Can anyone help?
import fl.events.ScrollEvent;
import fl.containers.ScrollPane;
import fl.controls.ScrollPolicy;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.text.*;
import flash.display.Bitmap;
import flash.display.Sprite;
include "automate_script.as"
include "automate_text.as"
var mstrTxtArr:Array = new Array();
var singleCommandArray:Array = new Array();
var listXmlCommands:XMLList = new XMLList();
var numberOfCommands:uint;
var commClkCount:uint = 0;
var outPutFlag:Boolean = false;
var numberOfEnters:uint = 0;
var amountToScroll:uint = 0;
var prompt:String = "C:\\>";
btnNext.addEventListener(MouseEvent.CLICK, handleNext);
btnReset.addEventListener(MouseEvent.CLICK, handleReset);
/*********Set up the look of the scrollPane w/ black background*************************************/
var newSkinClip:MovieClip = new MovieClip();
newSkinClip.graphics.clear();
newSkinClip.graphics.beginFill(uint(0x000000), 1);
newSkinClip.graphics.drawRect(0,0,272.0,191.0);
newSkinClip.graphics.endFill();
mcWindow.setStyle("skin", newSkinClip);
mcWindow.setStyle("upSkin", newSkinClip);
mcWindow.source = mcContentOnStage;
mcWindow.setSize(725, 381);
mcWindow.setStyle("contentPadding", 10);
mcWindow.verticalScrollPolicy = "off";
//mcWindow.horizontalScrollPolicy = "on";
/*****Highlight portions of the text.****************************************************************/
var mark:String = "";//This marks the text to highlight.
var startHilite:int = 0;
var formatHilite:TextFormat = new TextFormat("Lucida Console",15,0xFF0000);
var formatNormal:TextFormat = new TextFormat("Lucida Console",15,0xFFFFFF);
/*********Load the XML file.**********************************************************************/
var loaded:XML = new XML();
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
loader.load(new URLRequest("automate.xml"));//adls_test_1.xml
function loadXML(e:Event)
{
loaded = XML(e.target.data);
numberOfCommands = loaded.commandArray.command.length();
var string3:String = loaded.commandArray.command.output;
//trace(numberOfCommands);
listXmlCommands = loaded.commandArray.command;
//trace(listXmlCommands[2]);
/*****Create the textFields and push them into an array.*********************************************/
for (var i:uint = 0; i < numberOfCommands; i++)
{
var tf:TextField = new TextField();
tf.autoSize = TextFieldAutoSize.LEFT;
tf.multiline = true;
tf.text = listXmlCommands*.commText;
tf.setTextFormat(formatNormal);
mstrTxtArr.push(tf);
//trace(mstrTxtArr*.text);
//trace(tf.height);
}
/********Set up the initial "C:\>" output.***********************************************************/
mstrTxtArr[0].text = prompt;
mstrTxtArr[0].setTextFormat(formatNormal);
this.mcContentOnStage.addChild(mstrTxtArr[0]);
/*****Initial directions for the user.**************************************************************/
txtScreen.selectable = false;
txtScreen.text = loaded.directions;
}
function handleReset(evt:MouseEvent):void
{
mstrTxtArr[0].text = prompt;
mstrTxtArr[0].setTextFormat(formatNormal);
txtScreen.text = directions;
for (var i:uint=1; i<= numberOfCommands; i++)
{
mstrTxtArr*.text = "";
}
mcWindow.verticalScrollPosition = 0;
mcWindow.verticalScrollPolicy = "off";
btnNext.addEventListener(MouseEvent.CLICK,handleNext);
btnNext.x = 300;
commClkCount = 0;
}
function handleNext(evt:Event):void
{
/**** This handles showing the command step for the animation. *******************/
if (outPutFlag == false)
{
trace("In the first if");
mstrTxtArr[commClkCount].htmlText += listXmlCommands[commClkCount].commText;
mstrTxtArr[commClkCount].setTextFormat(formatNormal);
mark = listXmlCommands[commClkCount].commText;
startHilite=mstrTxtArr[commClkCount].text.indexOf(mark);
mstrTxtArr[commClkCount].setTextFormat(formatHilite, startHilite, startHilite + mark.length);
txtScreen.text=feedBack1;
outPutFlag = true;
trace(commClkCount %2);
}
/**** This handles showing the output step for the animation. *******************/
else if (outPutFlag == true)
{
trace(mcContentOnStage.width);
mcWindow.verticalScrollPolicy="on";
mcWindow.horizontalScrollPolicy="on";
btnNext.removeEventListener(MouseEvent.CLICK, handleNext);
btnReset.removeEventListener(MouseEvent.CLICK, handleReset);
mstrTxtArr[commClkCount].text = listXmlCommands[commClkCount].output;
trace(mstrTxtArr[commClkCount].text);
mstrTxtArr[commClkCount + 1].text=prompt;
mstrTxtArr[commClkCount + 1].setTextFormat(formatNormal);
mstrTxtArr[commClkCount].setTextFormat(formatNormal);
mark = listXmlCommands[commClkCount].commText;
startHilite=mstrTxtArr[commClkCount].text.indexOf(mark);
//mstrTxtArr[commClkCount].setTextFormat(formatHilite, startHilite, startHilite + mark.length);
this.mcContentOnStage.addChild(mstrTxtArr[commClkCount]);
this.mcContentOnStage.addChild(mstrTxtArr[commClkCount + 1]);
mstrTxtArr[commClkCount].y=mstrTxtArr[commClkCount + 1].y+mstrTxtArr[commClkCount].height+5;
mstrTxtArr[commClkCount].y=mstrTxtArr[commClkCount+1].y+mstrTxtArr[commClkCount].height+20;
txtScreen.text=feedBack2;
amountToScroll=15;
stage.addEventListener(Event.ENTER_FRAME, handleScrollPosition);
outPutFlag = false
commClkCount++;
}
Sample XML
<command>
<commText>Delete. browstat /help</commText>
<commInfo>Here we see the 'browstat' help command.</commInfo>
<output>Delete Usage: BROWSTAT Command [Options | /HELP] \r Where %3CCommand%3E is one of:\r\r ELECT ( EL) - Force election on remote domain\r GETBLIST ( GB) - Get backup list for domain\r GETMASTER ( GM) - Get remote Master Browser name (using NetBIOS)\r GETPDC ( GP) - Get PDC name (using NetBIOS)\r LISTWFW (WFW) - List WFW servers that are actually running browser\r STATS (STS) - Dump browser statistics\r STATUS (STA) - Display status about a domain\r TICKLE (TIC) - Force remote master to stop\r VIEW ( VW) - Remote NetServerEnum to server or domain on transport\r DUMPNET ( DN) - Display the list of transports bound to browser\rUnknown switch specified\rIn server (or domain) list displays, the following flags are used:\r W=Workstation, S=Server, SQL=SQLServer, PDC=PrimaryDomainController,\r BDC=BackupDomainController, TS=TimeSource, AFP=AFPServer, NV=Novell,\r MBC=MemberServer, PQ=PrintServer, DL=DialinServer, XN=Xenix,\r NT=Windows NT, WFW=WindowsForWorkgroups, MFPN=MS Netware,\r SS=StandardServer, PBR=PotentialBrowser, BBR=BackupBrowser,\r MBR=MasterBrowser, OSF=OSFServer, VMS=VMSServer, W95=Windows95,\r DFS=DistributedFileSystem, CLUS=NTCluster, DCE=IBM DSS</output>
<outPutInfo>Notice the functions and the sever list flags in the ‘browstat /help’ output. Which 'browstat' commad would be used to enumerate the server/service types on each computer? If you wanted to find a SQL server what flag would you look for? After you try to figure out these answers click next to see the answer demonstrated.</outPutInfo>
</command>
<command>
<commText>browstat vw /help</commText>
<commInfo>Now let's look at the command’s syntax in the help menu.</commInfo>
<output>Usage: BROWSTAT VIEW Transport [%3CDomain%3E|\\\\%3CServer%3E [%3CFlags%3E|/DOMAIN \r[%3CDomainToQuery%3E]]]\r BROWSTAT VIEW %3Ctransport%3E\r BROWSTAT VIEW %3Ctransport%3E %3Cdomain%3E|\\\\%3CServer%3E [/DOMAIN]\r BROWSTAT VIEW %3Ctransport%3E %3Cserver%3E /DOMAIN %3Cdomain%3E\rRemote NetServerEnum to a server or domain on transport.\r\rType 'BROWSTAT' to list all switches.</output>
<outInfo>One nice feature about ‘browstat vw’ is that the IP address or name of the server can be used instead of just the domain as with ‘net view’. This allows individual computers (even on different subnets), whether a browser or domain controller, to be checked individually. Also notice the 'transport' is required as part of the ‘browstat vw’ command.</outInfo>
</command>