如何将属性附加到动态创建的 moviclip
您好,我尝试通过单击动态创建的 Moviclip 来访问属性。
function finishLoading(evt : Event):void {
// Handle XML Settings
XML.ignoreComments=true;
XML.ignoreWhitespace=true;
// Attach XML Data into XML Var
fXML=new XML(evt.target.data);
// Iterate XML response and build Preview List
for (var i:Number=0; i<fXML.mov.length(); i++) {
var sTmpTitle=fXML.mov[i].mov_title.text();
var sTmpSrc=fXML.mov[i].mov_src.text();
var sTmpThumb=fXML.mov[i].mov_thumb.text();
var sTmpOrder=parseInt(fXML.mov[i].mov_list_order.text());
var iPosY:Number = (sTmpOrder!=1)?(sTmpOrder-1)*105:0;
var sTmpLoader:Loader = new Loader();
sTmpLoader.load(new URLRequest(sTmpThumb));
var oTmpMc:MovieClip = new MovieClip();
oTmpMc.addChild(sTmpLoader);
oTmpMc.y=iPosY;
oTmpMc.x=0;
oTmpMc.mov_src = sTmpSrc;
oTmpMc.addEventListener(MouseEvent.CLICK, function()
{
trace(this.mov_src);
});
mc_slider.addChild(oTmpMc);
}
创建MOVIECLPIP
和处理事件运行良好,但我不知道如何通过单击剪辑来访问属性 mov_src。
需要做什么才能使其正常工作。
评分此翻译:感谢
你的评分 不好 好
Hi I try to get acces a property by click on a dynamic created Moviclip.
function finishLoading(evt : Event):void {
// Handle XML Settings
XML.ignoreComments=true;
XML.ignoreWhitespace=true;
// Attach XML Data into XML Var
fXML=new XML(evt.target.data);
// Iterate XML response and build Preview List
for (var i:Number=0; i<fXML.mov.length(); i++) {
var sTmpTitle=fXML.mov[i].mov_title.text();
var sTmpSrc=fXML.mov[i].mov_src.text();
var sTmpThumb=fXML.mov[i].mov_thumb.text();
var sTmpOrder=parseInt(fXML.mov[i].mov_list_order.text());
var iPosY:Number = (sTmpOrder!=1)?(sTmpOrder-1)*105:0;
var sTmpLoader:Loader = new Loader();
sTmpLoader.load(new URLRequest(sTmpThumb));
var oTmpMc:MovieClip = new MovieClip();
oTmpMc.addChild(sTmpLoader);
oTmpMc.y=iPosY;
oTmpMc.x=0;
oTmpMc.mov_src = sTmpSrc;
oTmpMc.addEventListener(MouseEvent.CLICK, function()
{
trace(this.mov_src);
});
mc_slider.addChild(oTmpMc);
}
}
Creating the MOVIECLPIP and handle event is working well but I dont know hw I can get access on the property mov_src by click on the clip.
What´s to do to get this working.
Thank
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,你不应该向影片剪辑添加动态属性,这是 AS2 的一个坏习惯。您应该扩展 MovieClip 类并添加所需的属性。无论如何,您可以通过外部化回调来完成您想做的事情:
First of all, you shouldn't add dynamic properties to movieclips, it's a bad habit from AS2. You should extend the MovieClip class and add the properties you want. Anyway, you can do what you want to do by externalizing your callback :