Flash中的XML-url链接
我是XML新手,在Flash中遇到了一个小问题。我有很多按钮。每个按钮都需要打开xml文件中的不同URL(我现在只添加了一个按钮(banstead),因为我不知道如何添加更多) 我的XML:Flash中的XML-url链接,xml,flash,url,actionscript-2,Xml,Flash,Url,Actionscript 2,我是XML新手,在Flash中遇到了一个小问题。我有很多按钮。每个按钮都需要打开xml文件中的不同URL(我现在只添加了一个按钮(banstead),因为我不知道如何添加更多) 我的XML: <?xml version="1.0" encoding="utf-8"?> <banstead targ="_self" href="http://www.marca.com"> </banstead> 出于某种原因,当我测试电影并单击按钮时,它不会打开我请求的URL
<?xml version="1.0" encoding="utf-8"?>
<banstead targ="_self" href="http://www.marca.com"> </banstead>
出于某种原因,当我测试电影并单击按钮时,它不会打开我请求的URL
感谢您提供的任何帮助您已经定义了变量
url
,但随后在getURL调用中调用了另一个(未定义的)变量weblinkXML.url
请尝试以下方法:
weblinkXML.onLoad = function (success)
{
trace("success is "+success);// success should be TRUE
var url = weblinkXML.firstChild.attributes.href;
trace("url = "+url);
banstead.onRelease = function ()
{
trace("button pressed with "+url);
getURL(url);
}
}
要添加更多按钮,可以尝试更改XML文件,使其看起来更像:
<?xml version="1.0" encoding="utf-8"?>
<button buttonName="banstead" targ="_self" href="http://www.marca.com"> </button>
<button buttonName="chipstead" targ="_self" href="http://www.yahoo.com"> </button>
<button buttonName="tadworth" targ="_self" href="http://www.google.com"> </button>
然后创建一个循环,遍历XML并为找到的每个项目创建一个按钮:
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function(success) {
trace("success = "+success);
banstead._visible=FALSE;// hide the original button: we're making copies
for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
// make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
var myButton:MovieClip = banstead.duplicateMovieClip(myName, i+1);
// I've assumed your button has a dynamic text field in it named buttonLabel:
myButton.buttonLabel.text=myName;
myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
myButton.href = weblinkXML.childNodes[i].attributes.href;
myButton.onRelease = function() {
getURL(this.href);// note that each button has its own href variable
};
}
};
weblinkXML=newxml();
weblinkXML.ignoreWhite=true;
load(“xml/countries.xml”);
weblinkXML.onLoad=函数(成功){
trace(“success=“+success”);
班斯特德。_visible=FALSE;//隐藏原始按钮:我们正在复制
for(变量i:Number=0;i
我对你的项目是如何建立的做了一些假设。。。但我已经测试过了,它似乎对我有效
请告诉我您的进展情况(如果这个答案对您有帮助,请不要忘记单击大勾号接受它-谢谢)。请删除goToCategory链接,并通过xml打开url链接(如wwwgoogle.com) XML
洞穴之旅
xml/plants_gallery.xml//不打开类别,只需单击并转到另一个页面,如www.google.com
植物。洞穴之旅]]>
画廊
0
动作脚本
函数tola()
{
_根.bg1.x=0;
_根bg1._y=0;
_root.bg1._height=Stage.height;
_根.bg2.x=0;
_root.bg2._y=Stage.height-45;
_root.bg3._x=Stage.width-558;
_root.bg3._y=Stage.height-258;
_根.bg4.x=0;
_root.bg4._y=Stage.height-296;
_root.bg5.x=(Stage.width-200)/2;
_root.bg5._y=Stage.height-441;
_root.bg6._x=Stage.width-261;
_根bg6._y=70;
_根b2.x=-40;
_root.b2._y=舞台高度-260;
_根.b3.x=(Stage.width-140)/2;
_根.b3._y=舞台高度-320;
_根.b4._x=台宽-390;
_根b4._y=110;
_root.b5._x=数学圆((Stage.width+60)/2);
_根.b5._y=350;
_root.page.x=35;
_root.page.\u y=0;
_根中心=数学圆((台宽-580)/2);
_根。中心。_y=200;
_root.text1.\ux=0;
_root.text1._y=0;
_root.buttons\u bot.\u x=-20;
_root.buttons\u bot.\u y=Stage.height-800;
_root.sound\u control.\u x=舞台宽度-70;
_root.sound\u control.\u y=舞台高度-30;
_root.copyright._x=Stage.width-200;
_root.copyright._y=Stage.height-22;
_root.navigation.\ux=600;
_root.navigation._y=50;
_root.navigation._x=Stage.width-300;
}//函数结束
停止();
var fullscreenCM=新的上下文菜单(menuHandler);
fullscreenCM.hidebuiltimitems();
var fs=新的ContextMenuItem(“全屏显示”,goFullScreen);
fullscreenCM.customItems.push(fs);
var xfs=新上下文菜单项(“退出全屏”,退出全屏);
fullscreenCM.customItems.push(xfs);
_root.menu=fullscreenCM;
函数readPreviews(xmlFile)
{
跟踪(“readPreviews:+xmlFile”);
var_loc7=新XML();
_loc7.ignoreWhite=真;
_loc7.onLoad=功能(成功)
{
如果(成功)
{
var_loc2=this.firstChild.childNodes[0];
(i=0,j=0);
while(i<_loc2.childNodes.length)
{
if(_loc2.childNodes[i].nodeName==“item”)
{
var\u loc5=\u loc2.childNodes[i]。childNodes[1]。childNodes[0]。nodeValue;
var\u loc4=\u loc2.childNodes[i]。childNodes[2]。childNodes[0]。nodeValue;
var\u loc3=\u loc2.childNodes[i].childNodes[3].attributes.url;
变量_loc6=_loc2.childNodes[i]。childNodes[4]。childNodes[0]。nodeValue;
++j;
连杆推力(位置5);
下降推力(_loc4);
imgArr.push(_loc3);
卡塔推力(6号位置);
}//如果结束,则结束
++一,;
}//结束时
}//如果结束,则结束
totalPreviews=j;
setPreviews();
};
_loc7.load(xmlFile);
}//函数结束
函数readGallery(xmlFile)
{
var_loc9=新数组();
var_loc8=新数组();
imgGallArr=_loc9;
catGallArr=_loc8;
跟踪(“readGallery:+xmlFile”);
var_loc7=新XML();
_loc7.ignoreWhite=真;
_loc7.onLoad=功能(成功)
{
如果(成功)
{
var_loc2=this.firstChild.childNodes[0];
(i=0,j=0);
while(i<_loc2.childNodes.length)
{
if(_loc2.childNodes[i].nodeName==“item”)
{
var\u loc6=\u loc2.childNodes[i]。childNodes[1]。childNodes[0]。nodeValue;
变量_loc5=_loc2.childNodes[i]。childNodes[2]。childNodes[0]。nodeValue;
var\u loc3=\u loc2.childNodes[i].childNodes[3].attributes.url;
变量_loc4=_loc2。
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function(success) {
trace("success = "+success);
banstead._visible=FALSE;// hide the original button: we're making copies
for (var i:Number = 0; i< weblinkXML.childNodes.length; i++) {
var myName:String = weblinkXML.childNodes[i].attributes.buttonName;
// make sure banstead is a MovieClip, not a button, otherwise duplicateMovieClip won't work!
var myButton:MovieClip = banstead.duplicateMovieClip(myName, i+1);
// I've assumed your button has a dynamic text field in it named buttonLabel:
myButton.buttonLabel.text=myName;
myButton._y=banstead._y+ i*(banstead._height+5);// position the new button
myButton.href = weblinkXML.childNodes[i].attributes.href;
myButton.onRelease = function() {
getURL(this.href);// note that each button has its own href variable
};
}
};
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<item>
<title>Trip to the Caves</title>
<link>xml/plants_gallery.xml</link> // not open the category only click and goto another page such as www.google.com
<description><![CDATA[<font color="#222222">Plants .</font> <font color="#FFFFFF">Trip to the Caves</font>]]></description>
<enclosure url="xml/previews/img2.jpg" length="0" type="image/jpeg" />
<category>gallery</category>
<guid isPermaLink="false">0</guid>
</item>
<atom:link href="xml/previews.xml" rel="self" type="application/rss+xml" />
</channel>
</rss>
Actionscript
function tola()
{
_root.bg1._x = 0;
_root.bg1._y = 0;
_root.bg1._height = Stage.height;
_root.bg2._x = 0;
_root.bg2._y = Stage.height - 45;
_root.bg3._x = Stage.width - 558;
_root.bg3._y = Stage.height - 258;
_root.bg4._x = 0;
_root.bg4._y = Stage.height - 296;
_root.bg5._x = (Stage.width - 200) / 2;
_root.bg5._y = Stage.height - 441;
_root.bg6._x = Stage.width - 261;
_root.bg6._y = 70;
_root.b2._x = -40;
_root.b2._y = Stage.height - 260;
_root.b3._x = (Stage.width - 140) / 2;
_root.b3._y = Stage.height - 320;
_root.b4._x = Stage.width - 390;
_root.b4._y = 110;
_root.b5._x = Math.round((Stage.width + 60) / 2);
_root.b5._y = 350;
_root.page._x = 35;
_root.page._y = 0;
_root.center._x = Math.round((Stage.width - 580) / 2);
_root.center._y = 200;
_root.text1._x = 0;
_root.text1._y = 0;
_root.buttons_bot._x = -20;
_root.buttons_bot._y = Stage.height - 800;
_root.sound_control._x = Stage.width - 70;
_root.sound_control._y = Stage.height - 30;
_root.copyright._x = Stage.width - 200;
_root.copyright._y = Stage.height - 22;
_root.navigation._x = 600;
_root.navigation._y = 50;
_root.navigation._x = Stage.width - 300;
} // End of the function
stop ();
var fullscreenCM = new ContextMenu(menuHandler);
fullscreenCM.hideBuiltInItems();
var fs = new ContextMenuItem("Go Full Screen", goFullScreen);
fullscreenCM.customItems.push(fs);
var xfs = new ContextMenuItem("Exit Full Screen", exitFullScreen);
fullscreenCM.customItems.push(xfs);
_root.menu = fullscreenCM;
function readPreviews(xmlFile)
{
trace ("readPreviews: " + xmlFile);
var _loc7 = new XML();
_loc7.ignoreWhite = true;
_loc7.onLoad = function (success)
{
if (success)
{
var _loc2 = this.firstChild.childNodes[0];
(i = 0, j = 0);
while (i < _loc2.childNodes.length)
{
if (_loc2.childNodes[i].nodeName == "item")
{
var _loc5 = _loc2.childNodes[i].childNodes[1].childNodes[0].nodeValue;
var _loc4 = _loc2.childNodes[i].childNodes[2].childNodes[0].nodeValue;
var _loc3 = _loc2.childNodes[i].childNodes[3].attributes.url;
var _loc6 = _loc2.childNodes[i].childNodes[4].childNodes[0].nodeValue;
++j;
linkArr.push(_loc5);
descArr.push(_loc4);
imgArr.push(_loc3);
catArr.push(_loc6);
} // end if
++i;
} // end while
} // end if
totalPreviews = j;
setPreviews();
};
_loc7.load(xmlFile);
} // End of the function
function readGallery(xmlFile)
{
var _loc9 = new Array();
var _loc8 = new Array();
imgGallArr = _loc9;
catGallArr = _loc8;
trace ("readGallery: " + xmlFile);
var _loc7 = new XML();
_loc7.ignoreWhite = true;
_loc7.onLoad = function (success)
{
if (success)
{
var _loc2 = this.firstChild.childNodes[0];
(i = 0, j = 0);
while (i < _loc2.childNodes.length)
{
if (_loc2.childNodes[i].nodeName == "item")
{
var _loc6 = _loc2.childNodes[i].childNodes[1].childNodes[0].nodeValue;
var _loc5 = _loc2.childNodes[i].childNodes[2].childNodes[0].nodeValue;
var _loc3 = _loc2.childNodes[i].childNodes[3].attributes.url;
var _loc4 = _loc2.childNodes[i].childNodes[4].childNodes[0].nodeValue;
++j;
imgGallArr.push(_loc3);
catGallArr.push(_loc4);
} // end if
++i;
} // end while
} // end if
totalGallItem = j;
navGallery = 0;
setGallery();
};
_loc7.load(xmlFile);
} // End of the function
var linkArr = new Array();
var descArr = new Array();
var imgArr = new Array();
var catArr = new Array();
var totalPreviews;
var imgGallArr = new Array();
var catGallArr = new Array();
var totalGallItem;
var navGallery;
function setPreviews()
{
container.attachMovie("item", "item" + index, index);
container["item" + index].fill._visible = false;
loadMovieClip(imgArr[index], container["item" + index].container);
} // End of the function
function setPreviewsPos()
{
container["item" + index].fill._visible = true;
toStage(container["item" + index].fill, -5, -5, container["item" + index].container._width + 10, container["item" + index].container._height + 10);
if (index != nav)
{
container["item" + index]._alpha = 20;
container["item" + index]._x = container._width + 10;
}
else
{
container["item" + index]._alpha = 20;
ZigoEngine.doTween(container["item" + nav], "_alpha", 100, 5.000000E-001, "easeOutExpo");
setDesc(container["item" + nav], nav);
} // end else if
toStage(container, Stage.width / 2 - (container["item" + nav]._x + container["item" + nav]._width / 2), Stage.height / 2);
toStage(container["item" + index], container["item" + index]._x, -container["item" + index]._height / 2);
setNavigation();
index = index + 1;
setPreviews();
} // End of the function
function setPattern()
{
var _loc2 = flash.display.BitmapData.loadBitmap("pattern");
this.beginBitmapFill(_loc2);
this.lineTo(Stage.width, 0);
this.lineTo(Stage.width, Stage.height);
this.lineTo(0, Stage.height);
this.lineTo(0, 0);
this.endFill();
} // End of the function
function setBlack()
{
attachMovie("block", "block", 0);
toStage(block, 0, 0, Stage.width, Stage.height);
block._alpha = 0;
ZigoEngine.doTween(block, "_alpha", 100, 1, "easeOutExpo");
categories.zoomz.gotoAndStop(3);
viewGallery = true;
block.onRollOver = function ()
{
block.useHandCursor = false;
};
} // End of the function
function unsetBlack()
{
categories.zoomz.gotoAndStop(1);
removeMovieClip (imageContainer);
ZigoEngine.doTween(block, "_alpha", 0, 5.000000E-001, "easeOutExpo", 0, function ()
{
removeMovieClip (block);
viewGallery = false;
});
} // End of the function
function setGallery()
{
attachMovie("imageContainer", "imageContainer", 1);
imageContainer.fill._visible = false;
toStage(imageContainer, Stage.width / 2, Stage.height / 2);
imageContainer.preload._visible = false;
imageContainer.preloadShadow._visible = false;
setCategoryGallery();
} // End of the function
function setVideo()
{
trace ("setVideo " + imgGallArr[navGallery]);
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
imageContainer.container.videoContainer.attachVideo(ns);
ns.play(imgGallArr[navGallery]);
ns.setBufferTime(3);
ns.onStatus = function (info)
{
if (info.code == "NetStream.Play.Start")
{
imageContainer.container.loading.gotoAndPlay(1);
} // end if
if (info.code == "NetStream.Buffer.Full")
{
imageContainer.container.loading.gotoAndPlay("kill");
} // end if
if (info.code == "NetStream.Play.Stop")
{
imageContainer.container.loading.gotoAndPlay("kill");
} // end if
if (info.code == "NetStream.Buffer.Empty")
{
ns.seek(0);
} // end if
};
} // End of the function
function viewProject(mc)
{
ZigoEngine.doTween(mc.descItem.visit, "_alpha,_x", [100, mc.descItem.fill._width - 15], 1, "easeInOutExpo");
container.attachMovie("viewP", "viewP", 1000);
toStage(container.viewP, mc._x - 5, mc._y - 5, mc._width, mc._height);
container.viewP.onRelease = function ()
{
if (catArr[nav] != "link")
{
setBlack();
readGallery(linkArr[nav],);
}
else
{
getURL(linkArr[nav], "_blank");
} // end else if
};
} // End of the function
function setNavigation()
{
container["item" + index].id = index;
viewProject(container["item" + nav]);
container["item" + index].onRelease = function ()
{
if (this.id != nav)
{
unsetDesc(container["item" + nav].descItem);
ZigoEngine.doTween(container["item" + nav], "_alpha", 20, 1, "easeOutExpo", 3.000000E-001);
} // end if
nav = this.id;
if (viewCategories == true)
{
viewCategories = false;
ZigoEngine.doTween(container, "_xscale,_yscale,_bezier_", [100, 100, {x: Stage.width / 2 - (container["item" + nav]._x + container["item" + nav]._width / 2), y: Stage.height / 2, controlY: "-50", controlX: "-300"}], 5.000000E-001, "easeInOutExpo", 0, function ()
{
setDesc(container["item" + nav], nav);
viewProject(container["item" + nav]);
});
}
else
{
viewProject(container["item" + nav]);
ZigoEngine.doTween(container, "_xscale,_yscale,_x,_y", [100, 100, Stage.width / 2 - (container["item" + nav]._x + container["item" + nav]._width / 2), Stage.height / 2], 7.000000E-001, "easeOutExpo");
} // end else if
};
container["item" + index].onRollOver = function ()
{
if (this.id != nav)
{
ZigoEngine.doTween(container["item" + this.id], "_alpha", 100, 5.000000E-001, "easeOutExpo");
if (viewCategories == false)
{
setDesc(container["item" + this.id], this.id);
} // end if
} // end if
};
container["item" + index].onRollOut = function ()
{
if (this.id != nav)
{
ZigoEngine.doTween(container["item" + this.id], "_alpha", 20, 5.000000E-001, "easeOutExpo", 3.000000E-001);
unsetDesc(container["item" + this.id].descItem);
} // end if
};
} // End of the function
function setDesc(mc, index)
{
var _loc2 = mc._width;
mc.attachMovie("descItem", "descItem", 0);
toStage(mc.descItem, -5, mc._height - 50);
toStage(mc.descItem.visit, mc._width - 20);
mc.descItem.visit._alpha = 0;
mc.descItem.fill._width = _loc2;
mc.descItem.fill._yscale = 0;
ZigoEngine.doTween(mc.descItem.fill, "_yscale", 80, 2.000000E-001, "easeInOutExpo");
mc.descItem.descMc._alpha = 0;
mc.descItem.descMc.createTextField("cntTxt", 0, 0, 0, 0, 0);
mc.descItem.descMc.cntTxt.html = true;
mc.descItem.descMc.cntTxt.autoSize = true;
mc.descItem.descMc.cntTxt.multiline = false;
mc.descItem.descMc.cntTxt.selectable = false;
mc.descItem.descMc.cntTxt._quality = "HIGH";
mc.cntTxt.antiAliasType = "advanced";
mc.descItem.descMc.cntTxt.embedFonts = true;
my_fmt = new TextFormat();
my_fmt.font = "agNo2";
my_fmt.size = 20;
mc.descItem.descMc.cntTxt.htmlText = descArr[index];
ZigoEngine.doTween(mc.descItem.descMc, "_alpha", 100, 1, "easeOutExpo", 3.000000E-001);
mc.descItem.descMc.cntTxt.setTextFormat(my_fmt);
} // End of the function
function unsetDesc(mc)
{
ZigoEngine.doTween(mc.visit, "_alpha", 0, 5.000000E-001, "easeOutExpo");
ZigoEngine.doTween(mc.descMc, "_alpha", 0, 1, "easeOutExpo");
ZigoEngine.doTween(mc.fill, "_yscale", 0, 2.000000E-001, "easeInOutExpo", 2.000000E-001, function ()
{
removeMovieClip (mc);
});
} // End of the function
var viewCategories = false;
var viewGallery = false;
var widthShadow;
var nav = 0;
var index = 0;
var init = true;
function loadMovieClip(externalTarget, target)
{
var _loc2 = new MovieClipLoader();
var _loc1 = new Object();
_loc1.onLoadStart = function (target)
{
++checkLoaded;
};
_loc1.onLoadProgress = function (target, bytesLoaded, bytesTotal)
{
};
_loc1.onLoadInit = function (target)
{
if (checkLoaded == totalPreviews)
{
goToCategory();
} // end if
setPreviewsPos();
};
_loc2.addListener(_loc1);
_loc2.loadClip(externalTarget, target);
} // End of the function
function loadImageMovieClip(externalTarget, target)
{
var _loc2 = new MovieClipLoader();
var _loc1 = new Object();
_loc1.onLoadStart = function (target)
{
};
_loc1.onLoadProgress = function (target, bytesLoaded, bytesTotal)
{
percent = Math.floor(bytesLoaded / bytesTotal * 100);
imageContainer.preload.perc.text = percent + " %";
imageContainer.preloadShadow.perc.text = percent + " %";
};
_loc1.onLoadInit = function (target)
{
imageContainer.preload._visible = false;
imageContainer.preloadShadow._visible = false;
imageContainer.preload.perc.text = "";
imageContainer.preloadShadow.perc.text = "";
setImagePos();
};
_loc2.addListener(_loc1);
_loc2.loadClip(externalTarget, target);
} // End of the function
var checkLoaded = 0;
function toStage(mc, xPos, yPos, mcWidth, mcHeight)
{
mc._x = Math.floor(xPos);
mc._y = Math.floor(yPos);
mc._width = mcWidth;
mc._height = mcHeight;
} // End of the function
Stage.scaleMode = "noScale";
Stage.align = "TL";
var stageListener = new Object();
stageListener.onResize = function ()
{
toStage(categories, Stage.width / 2, 0);
if (viewCategories == false)
{
toStage(container, Stage.width / 2 - (container["item" + nav]._x + container["item" + nav]._width / 2), Stage.height / 2);
}
else
{
toStage(container, Stage.width / 2 - widthShadow / 2, Stage.height / 2);
} // end else if
toStage(imageContainer, Stage.width / 2, Stage.height / 2);
toStage(block, 0, 0, Stage.width, Stage.height);
setPattern();
};
Stage.addListener(stageListener);
com.mosesSupposes.fuse.ZigoEngine.simpleSetup(com.mosesSupposes.fuse.Shortcuts, com.mosesSupposes.fuse.PennerEasing, com.mosesSupposes.fuse.Fuse, com.mosesSupposes.fuse.FuseFMP);
readPreviews("xml/previews.xml");
setPattern();