Actionscript 3 as3儿童作为电影唇-赢得';不接受函数

Actionscript 3 as3儿童作为电影唇-赢得';不接受函数,actionscript-3,flash,Actionscript 3,Flash,这是从我的上一个问题开始的,我认为这个问题已经得到了回答,但由于某种原因,当我将舞台上的孩子(展示对象)视为电影剪辑时,我无法应用我想要的常规功能: var mc1:MovieClip = this.getChildByName("mc1") as MovieClip; if(mc1) { mc1.useHandCursor = true; mc1.buttonMode = true; mc1.addEventListener(MouseEvent.CLICK, fill

这是从我的上一个问题开始的,我认为这个问题已经得到了回答,但由于某种原因,当我将舞台上的孩子(展示对象)视为电影剪辑时,我无法应用我想要的常规功能:

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);
}
导入flash.display*
ImageUploader.visible=false;
函数showUploader(e:MouseEvent):无效{
ImageUploader.visible=true;
图像上传器。gotoAndPlay(2);
}
pic.addEventListener(MouseEvent.CLICK,addNewPoint);
变量n:数值=0;
var joinPointsArray:Array=新数组;
函数addNewPoint(e:MouseEvent):void{
n++;
pointNo.text=字符串(n);
如果(n==1){
var nextPoint:MovieClip=new mcstart();
addChild(nextPoint);
nextPoint.name=“mc”+点编号文本;
nextPoint.x=e.target.mouseX;
nextPoint.y=e.target.mouseY;
}否则{
var nextPoint2:MovieClip=newnewpoint();
addChild(下一个点2);
nextPoint2.name=“mc”+pointNo.text;
nextPoint2.x=e.target.mouseX;
nextPoint2.y=e.target.mouseY;
}
var joinPoints:MovieClip=新的MovieClip();
此.addChild(连接点);
接合点滑动推送(接合点);
连接点.图形.线型(0.5,0xFF0000);
joinPoints.graphics.moveTo(this.getChildByName(“mc1”).x,this.getChildByName(“mc1”).y);

对于(var i:int=2;i您确定电影剪辑被放在舞台上还是实际转换为电影剪辑? 请尝试
stage.getChildByName()
。您将此代码放在哪里?放在框架内还是主文档类内?以确保您可以检查添加到stage上的孩子,并查看他们的名字。 您可以使用此代码

        for ( var i :int = 0; i < this.numChildren; i++ )
        {
            babe = this.getChildAt( i );
            if ( babe is MovieClip)  {
                trace( babe.name);
            }
        }
哇呜!想出来了

爆裂

var mc1:MovieClip = this.getChildByName("mc1") as MovieClip;
在我的演讲结束时,我指的是孩子“mc1”,在它出现之前,它是在用户点击“pic”movieclip的某个地方后才被创建的。因此解决方案是将我对“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应该

我很高兴-谢谢你的指导


Cam

mc1
一个MovieClip吗?是否执行
if
语句?什么是“我不能应用常用函数?”mc1是一个实例名为“mc1”的动态创建的MovieClip。然后,我需要将其作为时间轴上的普通movieclip引用,但不会引用,因为它仅被分类为显示对象。因此,我将其定义为一个名为“mc1”的新变量作为一个movieclip,我希望我可以在它上面应用通常的操作,我会像上面那样创建一个时间轴movieclip,但它不工作。没有编译器错误,只是mc1不响应我的as中应用的操作。感谢giannosfor,你可以从我发布的第二段代码中看到,它被添加到了阶段,然后在我发布的第一段代码中我声明它是一个movieclip,但没有乐趣-即使没有if语句,它也不工作:
var mc1:movieclip=(this.getChildByName(“mc1”))作为movieclip;mc1.useHandCursor=true;mc1.buttonMode=true;mc1.addEventListener(MouseEvent.CLICK,fillDriveway);
再次使用上述示例没有编译器错误也没有乐趣:(mc1的
if
语句是否进入
if
语句?是否放置
trace
以确保?您可以将我的代码放置在内部,以查看
mc1
是否正确铸造。或者甚至将
trace
放置在
fillDriveway
函数中,以查看它是否相互作用,但您看不到。我认为也是如此。)
mc1.useHandCursor=true不需要。
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();
    }