我在ActionScript 3中做过同样的事情,但我不熟悉ActionScript 2,我被迫在这个项目中使用它。我正在通过XML将产品加载到SWF中,并尝试向每个动态创建的动画片段添加一个click事件。只需从XML中的节点跟踪文本就可以了。我想为每个动画片段分配一个名为“desc”或“description”的属性,并让它在单击时跟踪该属性的值。以下是我的代码的相关部分:
var iXML:XML = new XML();
iXML.ignoreWhite = true;
iXML.onLoad = init;
iXML.load("http://localhost:8888/products.php?p=Shortboards");
function init():Void
{
var imgNum:Number = iXML.firstChild.childNodes.length;
var holder_mc:MovieClip = slider.createEmptyMovieClip("holder_mc", slider.getNextHighestDepth());
for (var i:Number = 0; i < imgNum; i++)
{
var ob:Object = new Object();
ob.id = i;
ob.mc = holder_mc.createEmptyMovieClip("img" + ob.id + "_mc", holder_mc.getNextHighestDepth());
ob.mc._x = (137 * ob.id);
ob.mc.loadMovie(iXML.firstChild.childNodes[i].attributes.src);
}
for(var i in holder_mc){
trace('key: ' + i + ', value: ' + holder_mc[i]);
holder_mc[i].description = (iXML.firstChild.childNodes[i].attributes.desc);
holder_mc[i].onRelease = function() {
trace (this.description);
}
}
}
答案 0 :(得分:0)
var iXML:XML = new XML();
iXML.ignoreWhite = true;
iXML.onLoad = init;
iXML.load("http://localhost:8888/products.php?p=Shortboards");
function init():Void {
var imgNum:Number = iXML.firstChild.childNodes.length;
var holder_mc:MovieClip = slider.createEmptyMovieClip("holder_mc", slider.getNextHighestDepth());
for (var i:Number = 0; i < imgNum; i++) {
var ob:Object = new Object();
ob.id = i;
ob.mc = holder_mc.createEmptyMovieClip("img" + ob.id + "_mc", holder_mc.getNextHighestDepth());
ob.img = ob.mc.createEmptyMovieClip("img_mc", 1);
ob.mc._x = (137 * ob.id);
ob.img.loadMovie(iXML.firstChild.childNodes[i].attributes.src);
}
var x:Number = 0;
for(var i in holder_mc){
trace('key: ' + i + ', value: ' + holder_mc[i]);
holder_mc[i].description = (iXML.firstChild.childNodes[x++].attributes.desc);
holder_mc[i].onRelease = function() {
trace (this.description);
}
}
}