0

这是我认为已回答的最后一个问题的后续,但由于某种原因,当我将舞台上的孩子(显示对象)视为影片剪辑时,我无法应用我想要的常用功能:

var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
if(mc1) {
    mc1.useHandCursor = true;
    mc1.buttonMode = true;
    mc1.addEventListener(MouseEvent.CLICK, fillDriveway);
}

任何智慧都将不胜感激......并且很抱歉提出与以前类似的问题......

提前致谢。

编辑:来自该项目的 AS 的更多代码以获取上下文:

import flash.display.*

ImageUploader.visible = false;

function showUploader(e:MouseEvent):void {
    ImageUploader.visible = true;
    ImageUploader.gotoAndPlay(2);
}

pic.addEventListener(MouseEvent.CLICK,addNewPoint);

var n:Number = 0;
var joinPointsArray:Array = new Array;

function addNewPoint(e:MouseEvent):void {
    n++;
    pointNo.text = String(n);
    if(n==1){
        var nextPoint:MovieClip = new mcstart();
        addChild(nextPoint);
        nextPoint.name = "mc"+pointNo.text;
        nextPoint.x = e.target.mouseX;
        nextPoint.y = e.target.mouseY;
    }else{
        var nextPoint2:MovieClip = new newPoint();
        addChild(nextPoint2);
        nextPoint2.name = "mc"+pointNo.text;
        nextPoint2.x = e.target.mouseX;
        nextPoint2.y = e.target.mouseY;
    }

    var joinPoints:MovieClip = new MovieClip();
    this.addChild(joinPoints);
    joinPointsArray.push(joinPoints);
    joinPoints.graphics.lineStyle(0.5,0xFF0000);
    joinPoints.graphics.moveTo(this.getChildByName("mc1").x, this.getChildByName("mc1").y);
    for(var i:int=2; i<=n; ++i){
        joinPoints.graphics.lineTo(this.getChildByName("mc"+i).x, this.getChildByName("mc"+i).y);
    }
}

pic.addEventListener(MouseEvent.CLICK, addNewPoint);

function fillDriveway(eventObject:MouseEvent) {
    var joinPoints:MovieClip = new MovieClip();
    this.addChild(joinPoints);
    for(var p:int=0; p<(joinPointsArray.length); ++p) {
        joinPointsArray[p].alpha = 0;
    }
    this.getChildByName("mc1").alpha = 0;
    joinPoints.graphics.beginFill(0xFFFFFF, 0.7);
    joinPoints.graphics.moveTo(this.getChildByName("mc1").x, this.getChildByName("mc1").y);
    for(var m:int=2; m<=n; ++m){
        joinPoints.graphics.lineTo(this.getChildByName("mc"+m).x, this.getChildByName("mc"+m).y);
    }
    joinPoints.name = "driveshape";
    filledDrive.text = "filled";
}

function undoit(eventObject:MouseEvent) {
    if(n > 0) {
        if(filledDrive.text.indexOf("filled") != -1) {
            this.removeChild(this.getChildAt(this.numChildren -1));
            filledDrive.text = "";
            }else{
            this.removeChild(this.getChildAt(this.numChildren -1));
            this.removeChild(this.getChildAt(this.numChildren -1));
            n--;
            pointNo.text = String(n);
        }
    }
}

function maskDrive(eventObject:MouseEvent) {
    if(filledDrive.text.indexOf("filled") != -1) {
        var finishA:MovieClip = new finishMC();
        this.addChild(finishA);
        finishA.x = 310;
        finishA.y = 100;
        finishA.mask = getChildByName("driveshape");
        finishA.gotoAndPlay(2);
    }
}

//BTN RollOvers
function btn1over(myEvent:MouseEvent) {
    btn1.gotoAndPlay(2);
}
function btn1out(myEvent:MouseEvent) {
    btn1.gotoAndPlay(11);
}
function btn2over(myEvent:MouseEvent) {
    btn2.gotoAndPlay(2);
}
function btn2out(myEvent:MouseEvent) {
    btn2.gotoAndPlay(11);
}
function btn3over(myEvent:MouseEvent) {
    btn3.gotoAndPlay(2);
}
function btn3out(myEvent:MouseEvent) {
    btn3.gotoAndPlay(11);
}
function undoover(myEvent:MouseEvent) {
    undo.gotoAndPlay(2);
}
function undoout(myEvent:MouseEvent) {
    undo.gotoAndPlay(11);
}

//BTN Calls
btn1HIT.addEventListener(MouseEvent.CLICK, fillDriveway);
btn1HIT.addEventListener(MouseEvent.ROLL_OVER, btn1over);
btn1HIT.addEventListener(MouseEvent.ROLL_OUT, btn1out);
btn1HIT.buttonMode = true;
btn1HIT.useHandCursor = true;
btn2HIT.addEventListener(MouseEvent.CLICK, maskDrive);
btn2HIT.addEventListener(MouseEvent.ROLL_OVER, btn2over);
btn2HIT.addEventListener(MouseEvent.ROLL_OUT, btn2out);
btn2HIT.buttonMode = true;
btn2HIT.useHandCursor = true;
btn3HIT.buttonMode = true;
btn3HIT.useHandCursor = true;
btn3HIT.addEventListener(MouseEvent.ROLL_OVER, btn3over);
btn3HIT.addEventListener(MouseEvent.ROLL_OUT, btn3out);
btn3HIT.addEventListener(MouseEvent.CLICK, showUploader);
undoHIT.addEventListener(MouseEvent.CLICK, undoit);
undoHIT.addEventListener(MouseEvent.ROLL_OVER, undoover);
undoHIT.addEventListener(MouseEvent.ROLL_OUT, undoout);
undoHIT.buttonMode = true;
undoHIT.useHandCursor = true;

var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
if(mc1) {
    mc1.useHandCursor = true;
    mc1.buttonMode = true;
    mc1.addEventListener(MouseEvent.CLICK, fillDriveway);
}
4

2 回答 2

1

您确定影片剪辑是放在舞台上还是实际转换为影片剪辑?试试stage.getChildByName()。你把这段代码放在哪里了?在框架内还是在主文档类内?为了确保您可以检查孩子们是否已添加到舞台上,并查看他们的名字。您可以使用此代码

        for ( var i :int = 0; i < this.numChildren; i++ )
        {
            babe = this.getChildAt( i );
            if ( babe is MovieClip)  {
                trace( babe.name);
            }
        }

这个我也看到了,不知道好不好用。

if (stage.contains(mc1)) {

}
于 2012-04-20T11:58:21.737 回答
0

哇!弄清楚了!

通过弹出

var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;

在我的 AS 结尾处,我指的是子“mc1”在它存在之前 - 在用户单击“pic”电影剪辑上的某个位置之前它不会被创建。所以解决方案是将我对“mc1”的操作(包括将其声明为 MovieClip)放入一个单独的函数中:

function createstartEndMC():void {
    var startEnd:MovieClip = (this.getChildByName("mc1")) as MovieClip;
    startEnd.useHandCursor = true;
    startEnd.buttonMode = true;
    startEnd.addEventListener(MouseEvent.CLICK, fillDriveway);
}

然后在创建“mc1”子项后调用此函数:

function addNewPoint(e:MouseEvent):void {
    n++;
    pointNo.text = String(n);
    if(n==1){
        var nextPoint:MovieClip = new mcstart();
        addChild(nextPoint);
        nextPoint.name = "mc"+pointNo.text;
        nextPoint.x = e.target.mouseX;
        nextPoint.y = e.target.mouseY;
        createstartEndMC();
    }

最后它工作了,“mc1”(或者我称之为“startEnd”,一旦它被创建并制作成一个 MC)最终表现得像一个正常的时间线 MC 应该的!

我很高兴-感谢您的所有指导!

凸轮

于 2012-06-27T11:01:49.340 回答