如何将属性附加到动态创建的 moviclip

发布于 2024-10-22 05:33:23 字数 1277 浏览 5 评论 0原文

您好,我尝试通过单击动态创建的 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 技术交流群。

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

发布评论

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

评论(1

坚持沉默 2024-10-29 05:33:23

首先,你不应该向影片剪辑添加动态属性,这是 AS2 的一个坏习惯。您应该扩展 MovieClip 类并添加所需的属性。无论如何,您可以通过外部化回调来完成您想做的事情:

...
        oTmpMc.addEventListener(MouseEvent.CLICK, onClipClicked);

        mc_slider.addChild(oTmpMc);
}

private function onClipClicked(e:Event):void
{
        var clip:MovieClip = e.currentTarget as MovieClip;
        trace(clip.mov_src);
}

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 :

...
        oTmpMc.addEventListener(MouseEvent.CLICK, onClipClicked);

        mc_slider.addChild(oTmpMc);
}

private function onClipClicked(e:Event):void
{
        var clip:MovieClip = e.currentTarget as MovieClip;
        trace(clip.mov_src);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文