Flash XML 数据,单击时显示节点标题

发布于 2024-08-22 01:51:38 字数 972 浏览 10 评论 0原文

我正在编写一个 Flash AS2 脚本,该脚本为 XML 文件中的每个节点添加一个影片剪辑实例。我还在 XML 文件中包含了每个节点的标题,并且希望在用户单击单个影片剪辑之一时显示这些标题。我玩过clipevents 和attachMovie,但我一生都不知道如何解决这个问题。有什么想法吗?

好的,现在使用更新脚本 - 是的!

var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("map.xml");
myXML.onLoad = function(success) {
if (success) {
var myPin = myXML.firstChild.childNodes;
for (i=0; i<myPin.length; i++) {

var pinNumber = i+1;

_root.attachMovie("box", "pin"+i, _root.getNextHighestDepth());
var xpos = Number(myPin[i].attributes["xpos"]);
var ypos = Number(myPin[i].attributes["ypos"]);
_root["pin" + i]._x = xpos;
_root["pin" + i]._y = ypos;
_root["pin" + i].popup.titleBox.text = myPin[i].firstChild.nodeValue;

_root["pin" + i].popup._visible = false;// hide the title to begin with
_root["pin" + i].onRelease = function () { //when the pin is clicked...
_root["pin" + i].popup._visible=!_root["pin" + i].popup._visible; //toggle the titleBox's visibility
}

}
}
};

I am working on a Flash AS2 script that adds an instance of a movieclip for each node in an XML file. I have also included titles for each node in the XML file and I would like to display these when a user clicks on one of the individual movieclips. I have played around with clipevents and attachMovie but for the life of me I can't figure out how to approach this problem. Any ideas?

Ok Now with update script - yea!

var myXML:XML = new XML();
myXML.ignoreWhite=true;
myXML.load("map.xml");
myXML.onLoad = function(success) {
if (success) {
var myPin = myXML.firstChild.childNodes;
for (i=0; i<myPin.length; i++) {

var pinNumber = i+1;

_root.attachMovie("box", "pin"+i, _root.getNextHighestDepth());
var xpos = Number(myPin[i].attributes["xpos"]);
var ypos = Number(myPin[i].attributes["ypos"]);
_root["pin" + i]._x = xpos;
_root["pin" + i]._y = ypos;
_root["pin" + i].popup.titleBox.text = myPin[i].firstChild.nodeValue;

_root["pin" + i].popup._visible = false;// hide the title to begin with
_root["pin" + i].onRelease = function () { //when the pin is clicked...
_root["pin" + i].popup._visible=!_root["pin" + i].popup._visible; //toggle the titleBox's visibility
}

}
}
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2024-08-29 01:51:38

欢迎来到SO。

您可以尝试这样的操作(在创建每个引脚时):(

_root["pin" + i].titleBox._visible = false;// hide the title to begin with

_root["pin" + i].onRelease = function () { //when the pin is clicked...
this.titleBox._visible=!this.titleBox._visible; //toggle the titleBox's visibility
}

编辑:将 onRelease 函数更改为使用“this.titleBox”)

详细信息将取决于您希望它的行为方式。

希望这有帮助。

welcome to SO.

You could try something like this (when creating each pin):

_root["pin" + i].titleBox._visible = false;// hide the title to begin with

_root["pin" + i].onRelease = function () { //when the pin is clicked...
this.titleBox._visible=!this.titleBox._visible; //toggle the titleBox's visibility
}

(EDIT: changed the onRelease function to use 'this.titleBox')

The details would depend on exactly how you want it to behave.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文