从 MovieClip 中删除内容(图形线)

发布于 2024-09-12 10:49:45 字数 1722 浏览 6 评论 0原文

我有一个图像库,它加载详细图像,然后根据图像尺寸在图像旁边画一条线。单击图像将返回到主图像缩略图列表,然后单击缩略图将另一图像加载到细节容器中。一切工作正常,除了线条在细节图像卸载时不会消失,而是累积。有没有办法清除 lineDrawing MovieClip 的内容而不将其从舞台上删除,以便我可以在其中绘制新线?我尝试过在 MovieClip 上删除Child,但随后线条完全消失,与将 lineDrawing.clear() 放在 setupDetail 函数的顶部相同。到目前为止,这是我的(相关)代码,任何帮助将不胜感激,我被难住了!

var detailImage:Loader = new Loader();
var lineDrawing:MovieClip = new MovieClip();

setupDetail();

function setupDetail():void {
    detail.visible = false;
    detail.buttonMode = true;
    detail.closeMessage.mouseEnabled = false;

    detail.addChild(detailImage);

    detailImage.contentLoaderInfo.addEventListener(Event.COMPLETE, fullyLoaded);

    // make sure detail is above the gallery
    addChild(detail);

    detail.addEventListener(MouseEvent.CLICK, onCloseDetail, false, 0, true);
}

function fullyLoaded(evt:Event):void {

    var imgHeight:int = evt.target.content.height;
    var imgWidth:int = evt.target.content.width;

    var hOffset:int = imgWidth + 5 + 27;
    var vOffset:int = imgHeight + 5;

    detail.addChild(lineDrawing);

    if(imgWidth == 600) {
        lineDrawing.graphics.lineStyle(3,0x9a9345);
        lineDrawing.graphics.moveTo(28,vOffset);
        lineDrawing.graphics.lineTo(626,vOffset);
    }
    else if(imgHeight == 600) {
        lineDrawing.graphics.lineStyle(3,0x9a9345);
        lineDrawing.graphics.moveTo(hOffset, 1);
        lineDrawing.graphics.lineTo(hOffset, 599);
    }
}

function onCloseDetail(evt:MouseEvent):void {

    // only allow it to be closed if it is at least 90% opaque
    if (detailImage.alpha>.9){
      detailImage.unload();
      TweenLite.to(detail,.5, {autoAlpha:0});
      detailImage.unload();
      detail.visible = false;
    }
}

I have an image gallery which loads a detail image, then draws a line next to the image on one side based on image dimensions. Clicking on the image returns one back to the main image thumbnail list, then clicking a thumb loads another image into detail holder. Everything works fine with it, except that the lines, rather than disappearing upon detail image unload, accumulate. Is there a way to clear the contents of the lineDrawing MovieClip without removing it from the stage, so that I can draw a new line in it? I've tried removeChild on the MovieClip, but then the lines disappear entirely, same with placing lineDrawing.clear() at the top of the setupDetail function. Here is my (relevant)code so far, any assistance will be greatly appreciated, I am stumped!

var detailImage:Loader = new Loader();
var lineDrawing:MovieClip = new MovieClip();

setupDetail();

function setupDetail():void {
    detail.visible = false;
    detail.buttonMode = true;
    detail.closeMessage.mouseEnabled = false;

    detail.addChild(detailImage);

    detailImage.contentLoaderInfo.addEventListener(Event.COMPLETE, fullyLoaded);

    // make sure detail is above the gallery
    addChild(detail);

    detail.addEventListener(MouseEvent.CLICK, onCloseDetail, false, 0, true);
}

function fullyLoaded(evt:Event):void {

    var imgHeight:int = evt.target.content.height;
    var imgWidth:int = evt.target.content.width;

    var hOffset:int = imgWidth + 5 + 27;
    var vOffset:int = imgHeight + 5;

    detail.addChild(lineDrawing);

    if(imgWidth == 600) {
        lineDrawing.graphics.lineStyle(3,0x9a9345);
        lineDrawing.graphics.moveTo(28,vOffset);
        lineDrawing.graphics.lineTo(626,vOffset);
    }
    else if(imgHeight == 600) {
        lineDrawing.graphics.lineStyle(3,0x9a9345);
        lineDrawing.graphics.moveTo(hOffset, 1);
        lineDrawing.graphics.lineTo(hOffset, 599);
    }
}

function onCloseDetail(evt:MouseEvent):void {

    // only allow it to be closed if it is at least 90% opaque
    if (detailImage.alpha>.9){
      detailImage.unload();
      TweenLite.to(detail,.5, {autoAlpha:0});
      detailImage.unload();
      detail.visible = false;
    }
}

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

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

发布评论

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

评论(1

素食主义者 2024-09-19 10:49:45
lineDrawing.graphics.clear()
lineDrawing.graphics.clear()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文