我想创建一个使用XML加载某些数据的Flash影片。我希望当用户点击屏幕时,每行数据都会逐一显示。到目前为止,我已将所有数据添加到屏幕上,但我不确定如何为此编写点击机制。
我尝试添加一个允许我点击删除和对象的功能,如下所示:
muppet_name0.addEventListener(MouseEvent.CLICK, fl_ClickToKermit);
function fl_ClickToKermit(event:MouseEvent):void
{
muppet_name0.visible = false;
}
但我不确定如何重新出现。如何在添加新对象的同时添加将删除对象的MouseClick事件?
我的文档类关注
package {
import flash.display.MovieClip;
import flash.text.TextField;
import flash.events.MouseEvent;
public class MuppetsDoc extends MovieClip {
public var myData:XML = <data>
<item>
<a>Kermit the Frog</a>
<b>Jim Henson</b>
<c>1955</c>
</item>
<item>
<a>Miss Piggy</a>
<b>Frank Oz</b>
<c>1974</c>
</item>
<item>
<a>Animal</a>
<b>Frank Oz</b>
<c>1975</c>
</item>
<item>
<a>The Swedish Chef</a>
<b>Jim Henson/Frank Oz</b>
<c>1975</c>
</item>
</data>;
public function MuppetsDoc() {
// constructor code
//trace(myData);
//muppets_txt.text = myData.item[2].a.length();
var aTxt:String = myData.item[2].a.text();
muppet_name0.appendText(myData.item[0].a.text());
muppet_puppet0.appendText(myData.item[0].b.text());
muppet_year0.appendText(myData.item[0].c.text());
muppet_name1.appendText(myData.item[1].a.text());
muppet_puppet1.appendText(myData.item[1].b.text());
muppet_year1.appendText(myData.item[1].c.text());
muppet_name2.appendText(myData.item[2].a.text());
muppet_puppet2.appendText(myData.item[2].b.text());
muppet_year2.appendText(myData.item[2].c.text());
muppet_name3.appendText(myData.item[3].a.text());
muppet_puppet3.appendText(myData.item[3].b.text());
muppet_year3.appendText(myData.item[3].c.text());
}
}
}
答案 0 :(得分:1)
我不确定你要做什么,但我认为你正在寻找的东西是这样的:
function fl_ClickToKermit(event:MouseEvent):void
{
muppet_name0.alpha = (muppet_name0.alpha == 0) : 1 ? 0;
}
每次点击您都会反转其alpha
值。当您使用visible
时,DisplayObject
会被禁用,因此无法点击。使用alpha
而不是DisplayObject
保持启用但不再可见。
查看文档以获取更多信息: