【问题标题】:AS3 Having difficulty getting movieclips to stay on top over other clipsAS3 难以让影片剪辑保持在其他剪辑之上
【发布时间】:2014-07-31 21:41:19
【问题描述】:

所以我在屏幕上有 5 个动画剪辑,当单击(向下状态)时会展开。由于这段代码,它们都出现在屏幕顶部:

addChildAt(this.Step0btn,1);
addChildAt(this.Step1btn,1);
addChildAt(this.Step2btn,1);
addChildAt(this.Step3btn,1);
addChildAt(this.Step4btn,1);

我的问题是,在每个展开的影片剪辑上都有另一个也在展开的影片剪辑,但是当我单击它时,它仍然显示在其他所有内容的下方。我想我可以添加另一个 addChildAt 命令,例如:

addChildAt(this.Step0btn.Step0img,1);

但是当我这样做时,我得到了这个错误:

TypeError:错误 #2007:参数 child 必须为非 null。 在 flash.display::DisplayObjectContainer/addChildAt() 在 SMARTTTraining_fla::MainTimeline/SMARTTTraining_fla::frame5()[SMARTTTraining_fla.MainTimeline::frame5:14]

然后展开的动画剪辑仍然显示在所有内容下方。这里有什么问题?

【问题讨论】:

    标签: actionscript-3 flash adobe movieclip


    【解决方案1】:

    Step0img 在该行代码运行时为null。可能的解释是Step0img 不存在于Step0Btn 所在的框架上。

    对于您的分层问题(我想也是您的错误),这将是您想要做的:

    this.addChild(Step0btn);  
    

    this.setChildIndex(Step0btn,this.numChildren-1);
    

    他们做同样的事情。这将带到其他步骤按钮上方的最前面,您不想通过 addChild(step0btn.step0img); 更改父/子关系

    如果您使用的代码与我在您的其他 question 中提供的代码相同,那么 onPress 方法现在应该是这样的:

    function onPress(event:MouseEvent):void
    {
        // toggle between frame 1 and 3 on button press
        gotoAndStop(Step0btn.currentFrame == 3 ? 1 : 3); //this expands your button presumably
        parent.addChild(this); //moves this (this button) to the foreground  
    }
    

    【讨论】:

    • 成功了,你很擅长这个,我很遗憾你基本上为我构建了这整个东西!
    • 实际上,它仅在我添加一行时才有效,当我添加第二行时 this.addChild(Step1btn) (我需要一直通过 Step4btn)它基本上否定了代码和它回到它最初的工作方式。第二段代码也一样。
    • 经过多次测试,它似乎只适用于最后一段代码。所以一旦我到达 setChildIndex(Step4btn,numChildren - 1);那个有效,但 Step0 -Step3 仍然显示在其他图层下方。
    • 这是设计使然。我只是假设,但应该澄清代码应该在您展开按钮的同时运行(并且仅针对该按钮)。因此,如果您使用的是我回答的其他问题中的代码,请在按钮的 onPress 方法中输入 parent.addChild(this)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 2017-06-24
    • 1970-01-01
    • 2014-08-28
    • 2015-04-24
    相关资源
    最近更新 更多