I am new to XML and am having a small problem in Flash. I have a number of buttons. Each of these buttons need to open up a different URL which is in a xml file (I have added only one button for now (banstead), as I wasn´t sure how to add more).
My XML:
<?xml version="1.0" encoding="utf-8"?>
<banstead targ="_self" href="http://www.marca.com"> </banstead>
My AS:
weblinkXML = new XML();
weblinkXML.ignoreWhite = true;
开发者_如何学编程weblinkXML.load("xml/counties.xml");
weblinkXML.onLoad = function (success)
{
var url = weblinkXML.firstChild.attributes.href;
banstead.onRelease = function ()
{
getURL(weblinkXML.url);
}
}
For some reason when I test the movie and click on the button it doesn´t open the URL I requested.
Appreciate any help
Plz remove the goToCategory link and open the url link (Such as wwwgoogle.com) throguh xml
XML
<?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();
You've defined the variable url
, but then called a different (undefined) variable weblinkXML.url
in your getURL call.
Try this instead:
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);
}
}
To add more buttons, you might try changing your XML file to look more like this:
<?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>
Then make a loop which goes through the XML and makes a button for each item it finds:
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
};
}
};
I have made some assumptions about how your project is set up... but I've tested it and it seems to work for me
Let me know how you get on (and don't forget to click the big tick mark to accept this answer if it has helped you - thanks).
精彩评论