2012-04-20 74 views
0

这是继我最后一个问题后,我认为已经回答,但由于某种原因,当我将我的舞台(显示对象)的孩子视为动画片段时,我无法应用我想一般的功能:as3孩子作为动画片段 - 不会接受函数

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

任何智慧将不胜感激...和抱歉问这样一个类似的问题,因为以前...提前

感谢。

编辑:

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); 
} 
+0

是'mc1'是一个MovieClip?是否执行了'if'语句? “我不能使用通常的功能”是什么意思? – 2012-04-20 11:42:52

+0

“mc1”是一个动态创建的实例名称为“mc1”的动画片段。然后我需要将它作为时间线上的普通动画片段引用,但不会将其仅归类为显示对象。所以我将它定义为一个名为“mc1”的新变量,作为一个动画片段,希望我可以对其应用通常的操作,以便像上面那些时间线动画片段,但它不起作用。没有编译器错误只是mc1不响应我的AS中应用的操作。 – bigtoothmedia 2012-04-20 11:48:15

回答

0

Wahoo!弄清楚了!

通过在年底弹出

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

我,因为我是指孩子“MC1”之前存在的 - 它不是创建,直到用户点击“PIC”影片剪辑的地方。因此,解决办法是塞子我为“MC1”行动(包括宣布它作为一个影片剪辑)到一个单独的功能:

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应该!

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

凸轮

1

你确定影片剪辑放置在舞台上或实际上转化为影片剪辑:从AS在这个项目上的情况下更多的代码? 尝试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)) { 

} 
+0

感谢giannosfor,你可以从我发布的第二位代码中看到,它被添加到舞台上,然后在代码的第一位,我宣称它是一个动画片段,但没有喜悦 - 即使没有if声明它不起作用: 'var mc1:MovieClip =(this.getChildByName(“mc1”))as MovieClip; \t mc1.useHandCursor = true; \t mc1.buttonMode = true; \t mc1.addEventListener(MouseEvent。CLICK,fillDriveway);' – bigtoothmedia 2012-04-20 12:42:45

+0

再次,上面的例子没有编译错误,只是没有喜悦:( – bigtoothmedia 2012-04-20 12:46:25

+0

'mc1'是否进入'if语句?你有没有放置一个'trace'以确保?你可以放置我的代码里面是为了看看mc1是否正确传输,甚至可以在'fillDriveway'函数中放置一个'trace'来查看它是否相互作用,但是你看不到它。我也想'mc1.useHandCursor =真正'没有必要。 – 2012-04-20 12:57:47