我正在编写一些动作脚本来加载xml文件并在舞台上适当地显示影片剪辑等。但是,我想通过加载不同的xml文件来通过函数重置显示,我遇到了一些问题。我已经加载了新文件,但显示不会改变,好像它仍然加载了以前的xml。
下面是加载第一个xml对象并运行我的函数的第一段代码,它改变了舞台上的mcs。
function CallLineFunction1() {
xmlFile1="test.xml"
// set up XML object
var my_xml1 = new XML();
my_xml1.ignoreWhite = true;
my_xml1.onLoad = function(success){
generateRW(my_xml1);
}
// load xml into object
my_xml1.load(xmlFile1);
}
这很好用。但是,单击一个按钮,我想加载一个新的xml文件,以再次改变舞台上的mcs。我正在使用此代码执行此操作:
function CallLineFunction2() {
xmlFile2="with_disruption_statuses.xml"
// set up XML object
var my_xml2 = new XML();
my_xml2.ignoreWhite = true;
my_xml2.onLoad = function(success){
generateRW2(my_xml2);
}
// load xml into object
my_xml.load(xmlFile2);
}
虽然我已经测试了我的第二个generateRW2语句运行(它是),但显示使用旧xml的属性保持不变。
我尝试过使用删除命令,但无济于事,
我希望我不必将所有内容复制到第二帧并从那里运行,因为有多个层和数百个mcs需要根据xml数据进行更改。
任何帮助表示赞赏!
答案 0 :(得分:0)
没有看到generateRW
和generateRW2
,很难说出问题所在。但是,有几点需要注意:确保从舞台上删除以前加载的影片剪辑,如果您不想删除它们,请确保使用剪辑的唯一ID。 / p>
答案 1 :(得分:0)
function generateRW(my_xml1){
lines=my_xml1.firstChild.firstChild.firstChild.childNodes;
stations=my_xml1.firstChild.firstChild.childNodes[1];
for(i=0;i<lines.length;i++){
offsetNode=lines[i];
offsetDisruptions=offsetNode.childNodes[0].childNodes;
eval("line"+lines[i].attributes.id).infoText="";
eval("line"+lines[i].attributes.id).infoCount=new Array;
if(offsetNode.attributes.id=="25DLR"){
lineDLR="true";
}
if(offsetNode.attributes.id=="90OVG"){
lineOverground="true";
}
if(offsetNode.attributes.status.toLowerCase()!="minor delays" && offsetNode.attributes.status.toLowerCase()!="good service"){
for(k=0;k<offsetDisruptions.length;k++){
if(offsetDisruptions[k].attributes.affectTimetable=="true"){
if(offsetDisruptions[k].childNodes[0].childNodes.length==0){
minorDelayCheck=offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue.substring(0,11);
minorDelayCheck=minorDelayCheck.toLowerCase();
if(minorDelayCheck!="minor delay"){
currentStatus++;
trace(' 4. Whole line down:'+lines[i].attributes.id);
segmentMC=eval("line"+lines[i].attributes.id);
infoTextFiltered=filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue);
if(segmentMC.infoText!=infoTextFiltered && segmentMC.infoTextOriginal!=infoTextFiltered){
segmentMC.infoTextOriginal=offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue;
segmentMC.infoText+=filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue);
segmentMC.infoCount.splice(segmentMC.infoCount.length, 0, filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue).length);
}
segmentMC.wholeLineAffected=true;
segmentMC.lineID=lines[i].attributes.id;
segmentMC.onRollOver=function(){
showText(this);
}
segmentMC.onRollOut=function(){
hideText();
}
}
} else {
segmentMCParent=eval("line"+lines[i].attributes.id);
if(segmentMCParent.infoTextOriginal!=offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue){
segmentMCParent.infoText+=filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue);
segmentMCParent.infoCount.splice(segmentMCParent.infoCount.length, 0, filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue).length);
}
currentStatus++;
for(m=0;m<offsetDisruptions[k].childNodes[0].childNodes.length;m++){
trace(' 5. Station down: '+offsetDisruptions[k].childNodes[0].childNodes[m].attributes.name);
segmentMC=eval("line"+lines[i].attributes.id+".mc"+offsetDisruptions[k].childNodes[1].childNodes[m].attributes.id+"_"+offsetDisruptions[k].childNodes[0].childNodes[m+1].attributes.id);
if(segmentMC){
//trace(' segment found: '+eval(segmentMC));
} else {
for(n=0;n<offsetDisruptions[k].childNodes[0].childNodes.length;n++) {
segmentMC=eval("line"+lines[i].attributes.id+".mc"+offsetDisruptions[k].childNodes[0].childNodes[m].attributes.id+"_"+offsetDisruptions[k].childNodes[0].childNodes[n].attributes.id);
if(segmentMC){
break;
} else {
}
}
}
if(filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue)!=segmentMC.infoText){
segmentMC.infoText+=filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue);
}
segmentMC.infoCount++;
segmentMC.lineID=lines[i].attributes.id;
segmentMC.onRollOver=function(){
showText(this);
}
segmentMC.onRollOut=function(){
hideText();
}
segmentMC.disrupted=true;
eval("mc_interchanges.mc"+lines[i].attributes.id+".mc"+offsetDisruptions[k].childNodes[0].childNodes[m].attributes.id).disrupted=true;
eval("mc_stations.mc"+offsetDisruptions[k].childNodes[0].childNodes[m].attributes.id).disrupted=true;
eval("mc_stations.mc"+offsetDisruptions[k].childNodes[0].childNodes[m].attributes.id).infoText=filterMessage(offsetDisruptions[k].childNodes[1].childNodes[0].nodeValue);
}
}
}
}
offsetStationsNode=stations;
offsetStationDisruptions=offsetStationsNode.childNodes;
for(k=0;k<offsetStationDisruptions.length;k++){
if(offsetStationDisruptions[k].attributes.closed.toLowerCase()=="true"){
if(offsetStationDisruptions[k].attributes.id!=1000023 && offsetStationDisruptions[k].attributes.id!=1000250){
if(eval("mc_stations.mc"+offsetStationDisruptions[k].attributes.id)){
currentStatus++;
stationMC=eval("mc_stations.mc"+offsetStationDisruptions[k].attributes.id);
stationMC.disrupted=true;
stationMC.infoText=filterMessage(offsetStationDisruptions[k].firstChild.firstChild.nodeValue);
stationMC.stationID=offsetStationDisruptions[k].attributes.id;
stationMC.onRollOver=function(){
showText(this);
}
stationMC.onRollOut=function(){
hideText();
}
myColor = new Color(stationMC);
myColor.setRGB(rgbRed);
stationMC.createEmptyMovieClip("square_mc", this.getNextHighestDepth());
stationMC.square_mc.beginFill(0xFFFFFF);
stationMC.square_mc.moveTo(0, 0);
stationMC.square_mc.lineTo(stationMC._width+5, 0);
stationMC.square_mc.lineTo(stationMC._width, stationMC._height);
stationMC.square_mc.lineTo(0, stationMC._height);
stationMC.square_mc.endFill();
stationMC.square_mc._alpha=0;
stationParentMC="mc"+offsetStationDisruptions[k].attributes.id;
for (var prop in mc_interchanges) {
if(eval(mc_interchanges[prop][stationParentMC])){
eval(mc_interchanges[prop][stationParentMC]).disrupted=true;
}
}
}
}
}
}
}
lineParent=eval("line"+lines[i].attributes.id);
if(lineParent.wholeLineAffected==true){
interchangeParent=(eval("mc_interchanges.mc"+lines[i].attributes.id));
for (var prop in interchangeParent) {
if (interchangeParent[prop] instanceof MovieClip) {
interchangeParent[prop].disrupted=true;
eval("mc_stations."+prop).disrupted=true;
if(eval("mc_stations."+prop).infoText==undefined){
eval("mc_stations."+prop).infoText=eval('line'+lines[i].attributes.id).infoText;
}
}
}
} else {
if(lineParent==_level0.mc_container.mc_loader.line01CIR){
if(_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072.disrupted==true && _level0.mc_container.mc_loader.line01CIR.mc1000018_1000174.disrupted==true){
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_south.disrupted=true;
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_north.disrupted=false;
}
if(_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072.disrupted==true && _level0.mc_container.mc_loader.line01CIR.mc1000196_1000174.disrupted==true){
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_south.disrupted=false;
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_north.disrupted=true;
}
if(_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072.disrupted==true && _level0.mc_container.mc_loader.line01CIR.mc1000072_1000011.disrupted==true){
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_south.disrupted=false;
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_north.disrupted=true;
}
if(_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072.disrupted==true && _level0.mc_container.mc_loader.line01CIR.mc1000072_1000011.disrupted!=true && _level0.mc_container.mc_loader.line01CIR.mc1000196_1000174.disrupted!=true && _level0.mc_container.mc_loader.line01CIR.mc1000018_1000174.disrupted!=true){
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_south.disrupted=true;
_level0.mc_container.mc_loader.line01CIR.mc1000174_1000072_north.disrupted=true;
}
}
if(lineParent==_level0.mc_container.mc_loader.line01CEN){
// Roding Valley to Woodford -- shut down if both stations are disrupted
if(_level0.mc_container.mc_loader.mc_interchanges.mc01CEN.mc1000194.disrupted==true && _level0.mc_container.mc_loader.mc_interchanges.mc01CEN.mc1000274.disrupted==true){
_level0.mc_container.mc_loader.line01CEN.mc1000274_1000194.disrupted=true;
}
}
for (var prop in lineParent) {
if (lineParent[prop] instanceof MovieClip) {
if(lineParent[prop].disrupted!=true){
// set to grey
myColor = new Color(lineParent[prop]);
myColor.setRGB(rgbGrey);
}
}
}
}
}
for (var prop in mc_stations) {
if (mc_stations[prop] instanceof MovieClip) {
if (mc_stations[prop].disrupted!=true){
myColor = new Color(mc_stations[prop]);
myColor.setRGB(rgbGrey);
} else {
if(mc_stations[prop].singleClosure==true){
mc_stations[prop].onRollOver=function(){
showText(this);
}
mc_stations[prop].onRollOut=function(){
hideText();
}
}
}
}
}
for (var prop in mc_interchanges) {
if (mc_interchanges[prop] instanceof MovieClip) {
for (var prop2 in mc_interchanges[prop]) {
if (mc_interchanges[prop][prop2] instanceof MovieClip) {
if(mc_interchanges[prop][prop2].disrupted!=true){
if(mc_interchanges[prop][prop2].mc_black){
myColor = new Color(mc_interchanges[prop][prop2].mc_black);
} else {
myColor = new Color(mc_interchanges[prop][prop2]);
}
//set the colour
myColor.setRGB(rgbGrey);
} else {
if(mc_interchanges[prop][prop2].mc_black){
stackX=parseInt(mc_interchanges[prop][prop2]._x);
stackY=parseInt(mc_interchanges[prop][prop2]._y);
stackID=prop2;
for (var stacked in mc_interchanges) {
for (var stacked2 in mc_interchanges[stacked]) {
if (stacked2 == prop2){
if(mc_interchanges[stacked][stacked2].disrupted!=true){
testStackX=parseInt(mc_interchanges[stacked][stacked2]._x);
testStackY=parseInt(mc_interchanges[stacked][stacked2]._y);
resultX=stackX-testStackX;
resultY=stackY-testStackY;
if (resultX >= -2 && resultX <= 2){
if (resultY >= -2 && resultY <= 2){
trace('*** !!! stack detected: '+mc_interchanges[stacked][stacked2]);
trace('*** resultX :'+resultX);
trace('*** resultY :'+resultY);
trace('*** stackX :'+stackX);
trace('*** testStackX:'+testStackX);
trace('*** stackY :'+stackY);
trace('*** testStackY:'+testStackY);
mc_interchanges[stacked][stacked2]._visible=false;
}
}
}
}
}
}
}
}
}
}
}
}
trace('Current status: '+currentStatus);
if(line90OVG.mc1000271_1001002.disrupted==true && line90OVG.mc1000271_1001348.disrupted!=true){
depthTop=line90OVG.mc1000271_1001002.getDepth();
depthBottom=line90OVG.mc1000271_1001348.getDepth();
line90OVG.mc1000271_1001348.swapDepths(depthTop);
line90OVG.mc1000271_1001002.swapDepths(depthBottom);
}
if(line01MET.mc90000167_90001407.disrupted==true && line01MET.mc90019046_90001407.disrupted!=true){
depthTop=line01MET.mc90000167_90001407.getDepth();
depthBottom=line01MET.mc90019046_90001407.getDepth();
line01MET.mc90019046_90001407.swapDepths(depthTop);
line01MET.mc90000167_90001407.swapDepths(depthBottom);
}
if(line01CEN.mc1000274_1000194.disrupted==true && line01CEN.mc1000274_90019033.disrupted!=true){
depthTop=line01CEN.mc1000274_90019033.getDepth();
depthBottom=line01CEN.mc1000274_1000194.getDepth();
line01CEN.mc1000274_1000194.swapDepths(depthTop);
line01CEN.mc1000274_90019033.swapDepths(depthBottom);
}
if(line01CEN.mc1000258_1000157.disrupted==true && line01CEN.mc1000099_1000157.disrupted!=true){
depthTop=line01CEN.mc1000099_1000157.getDepth();
depthBottom=line01CEN.mc1000258_1000157.getDepth();
line01CEN.mc1000258_1000157.swapDepths(depthTop);
line01CEN.mc1000099_1000157.swapDepths(depthBottom);
}
if(line01DIS.mc1000094_1000240.disrupted==true && line01DIS.mc1000048_1000240.disrupted!=true){
depthTop=line01DIS.mc1000048_1000240.getDepth();
depthBottom=line01DIS.mc1000094_1000240.getDepth();
line01DIS.mc1000048_1000094.swapDepths(depthTop);
line01DIS.mc1000048_1000240.swapDepths(depthBottom);
}
if(line01CEN.mc1000137_1000207.disrupted==true && line01CEN.mc1000137_1000250.disrupted!=true){
depthTop=line01CEN.mc1000137_1000250.getDepth();
depthBottom=line01CEN.mc1000137_1000207.getDepth();
line01CEN.mc1000137_1000207.swapDepths(depthTop);
line01CEN.mc1000137_1000250.swapDepths(depthBottom);
}
if(line01MET.mc1000264_1000102.disrupted==true && line01MET.mc1000161_1000102.disrupted!=true){
depthTop=line01MET.mc1000264_1000102.getDepth();
depthBottom=line01MET.mc1000161_1000102.getDepth();
line01MET.mc1000161_1000102.swapDepths(depthTop);
line01MET.mc1000264_1000102.swapDepths(depthBottom);
}
if(line01MET.mc90005973_90004983.disrupted==true && line01MET.mc90019057_90004983.disrupted!=true){
depthTop=line01MET.mc90005973_90004983.getDepth();
depthBottom=line01MET.mc90019057_90004983.getDepth();
line01MET.mc90019057_90004983.swapDepths(depthTop);
line01MET.mc90005973_90004983.swapDepths(depthBottom);
}
if(line01NTN.mc1000121_1000073.disrupted==true && line01NTN.mc1000121_1000254.disrupted!=true){
depthTop=line01NTN.mc1000121_1000073.getDepth();
depthBottom=line01NTN.mc1000121_1000254.getDepth();
line01NTN.mc1000121_1000254.swapDepths(depthTop);
line01NTN.mc1000121_1000073.swapDepths(depthBottom);
}
if(line01NTN.mc1000147_1000081.disrupted==true && line01NTN.mc1000081_1000261.disrupted!=true){
depthTop=line01NTN.mc1000147_1000081.getDepth();
depthBottom=line01NTN.mc1000081_1000261.getDepth();
line01NTN.mc1000081_1000261.swapDepths(depthTop);
line01NTN.mc1000147_1000081.swapDepths(depthBottom);
}
if(line01NTN.mc1000077_1000036.disrupted==true && line01NTN.mc1000152_1000036.disrupted!=true){
depthTop=line01NTN.mc1000077_1000036.getDepth();
depthBottom=line01NTN.mc1000152_1000036.getDepth();
line01NTN.mc1000152_1000036.swapDepths(depthTop);
line01NTN.mc1000077_1000036.swapDepths(depthBottom);
}
if(mc_interchanges.mc01NTN.mc1000077.disrupted==true && mc_interchanges.mc01VIC.mc1000077.disrupted!=true){
mc_interchanges.mc01VIC.mc1000077._visible=false;
}
if(mc_interchanges.mc01CIR.mc1000174.disrupted==true && mc_interchanges.mc01DIS.mc1000174.disrupted!=true){
mc_interchanges.mc01DIS.mc1000174._visible=false;
}
if(mc_interchanges.mc01CIR.mc1000072.disrupted==true && mc_interchanges.mc01DIS.mc1000072.disrupted!=true){
mc_interchanges.mc01DIS.mc1000072._visible=false;
}
if(mc_interchanges.mc01CIR.mc1000072.disrupted!=true && mc_interchanges.mc01HAM.mc1000072.disrupted==true){
mc_interchanges.mc01CIR.mc1000072._visible=false;
}
if(mc_interchanges.mc01CIR.mc1000072.disrupted==true && mc_interchanges.mc01HAM.mc1000072.disrupted!=true){
mc_interchanges.mc01HAM.mc1000072._visible=false;
}
if(mc_stations.mc1000096.disrupted==true && mc_stations.mc1000097.disrupted!=true){
mc_stations.mc1000097._visible=false;
} else if(mc_stations.mc1000097.disrupted==true && mc_stations.mc1000096.disrupted!=true){
mc_stations.mc1000096._visible=false;
} else {
mc_stations.mc1000097._visible=false;
}
if(mc_stations.mc1001348.disrupted==true && mc_stations.mc1000203.disrupted!=true){
mc_stations.mc1000203._visible=false;
} else if(mc_stations.mc1001348.disrupted!=true && mc_stations.mc1000203.disrupted==true){
mc_stations.mc1001348._visible=false;
} else {
mc_stations.mc1000203._visible=false;
}
mc_multilines.mc_multi_1002083_1002064._visible=false;
mc_multilines.mc_multi_1002084_1002083._visible=false;
mc_multilines.mc_multi_1002098_1000039._visible=false;
mc_multilines.mc_multi_1002076_1000202._visible=false; //DLR Tower Hill > Shadwell
mc_multilines.mc_multi_1000271_1001002._visible=false; //OVERGROUND Shepherds Bush > Willesden Junction
if(mc_stations.mc1001348.disrupted==true && mc_stations.mc1000271.disrupted==true){
mc_multilines.mc_multi_1000271_1001002._visible=false;
}
if(mc_stations.mc1002083.disrupted==true && mc_stations.mc1002064.disrupted==true && mc_stations.mc1002084.disrupted==true){
mc_multilines.mc_multi_1002083_1002064._visible=true;
mc_multilines.mc_multi_1002084_1002083._visible=true;
}
if(line25DLR.mc1002084_1002064.disrupted==true && line25DLR.mc1002084_1002083.disrupted!=true){
depthTop=line25DLR.mc1002084_1002083.getDepth();
depthBottom=line25DLR.mc1002084_1002064.getDepth();
line25DLR.mc1002084_1002064.swapDepths(depthTop);
line25DLR.mc1002084_1002083.swapDepths(depthBottom);
}
if(line25DLR.mc1002084_1002083.disrupted==true && line25DLR.mc1002064_1002083.disrupted!=true){
depthTop=line25DLR.mc1002064_1002083.getDepth();
depthBottom=line25DLR.mc1002084_1002083.getDepth();
line25DLR.mc1002084_1002083.swapDepths(depthTop);
line25DLR.mc1002064_1002083.swapDepths(depthBottom);
}
if(line25DLR.mc1000202_1000013.disrupted==true && line25DLR.mc1000202_1002076.disrupted!=true){
depthTop=line25DLR.mc1000202_1000013.getDepth();
depthBottom=line25DLR.mc1000202_1002076.getDepth();
line25DLR.mc1000202_1002076.swapDepths(depthTop);
line25DLR.mc1000202_1000013.swapDepths(depthBottom);
}
if(line25DLR.mc1002098_1000039.disrupted==true && line25DLR.mc1002071_1000039.disrupted==true){
mc_multilines.mc_multi_1002098_1000039._visible=true;
}
if(line25DLR.mc1002098_1000039.disrupted==true && line25DLR.mc1002071_1000039.disrupted!=true){
depthTop=line25DLR.mc1002071_1000039.getDepth();
depthBottom=line25DLR.mc1002098_1000039.getDepth();
line25DLR.mc1002098_1000039.swapDepths(depthTop);
line25DLR.mc1002071_1000039.swapDepths(depthBottom);
}
if(lineOverground!="true"){
myColor = new Color(line90OVG);
myColor.setRGB(rgbGrey);
eval(line90OVG).disrupted="false";
}
if(lineDLR!="true"){
myColor = new Color(line25DLR);
myColor.setRGB(rgbGrey);
myColor = new Color(mc_multilines);
myColor.setRGB(rgbGrey);
eval(line25DLR).disrupted="false";
}
mc_furniture._visible=false;
myColor = new Color(mc_thames);
myColor.setRGB(rgbGrey);
myColor = new Color(mc_eastLondonLine);
myColor.setRGB(rgbGrey);
_root.mapLoadStatus=true;
if(_root.xmlTimeStamp=="true"){
trace(_root.xmlTimeStamp);
mc_timestamp._visible=true;
} else {
mc_timestamp._visible=false;
}
if(offset!=undefined && offset!="normal"){
if(currentStatus==0){
_root.mc_good_service._visible=true;
} else {
mc_good_service._visible=false;
}
} else {
mc_good_service._visible=false;
}
}
答案 2 :(得分:0)
在CallLineFunction2中,这是您帖子或代码中的拼写错误吗?
// load xml into object
my_xml.load(xmlFile2);
因为方法中的实例名为“my_xml2”。