0
我縮短了下面的代碼示例以便它更具可讀性。這裏是揉搓:我創建了一大堆包含字母a-z的影片剪輯。這些影片剪輯是名爲「levelTwo」的父級影片剪輯的子代,其中levelTwo是該級別的一種邏輯管理器。解決子對象和父函數之間的1069錯誤
當他們被點擊時,他們發送一些數據到levelTwo評估(這是Hang子手)。問題是,點擊我得到一個1069錯誤。它是一個1061錯誤,直到我在LetterButton中添加了event.target.parent位。
下面是相關代碼:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class LetterButton extends MovieClip {
var buttonText:String;
public function LetterButton(lText:String,objX:int,objY:int)
{
trace ("Creating new button");
x = objX;
y = objY;
buttonText = lText;
letterText.text = buttonText;
this.stop();
addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
this.addEventListener(MouseEvent.CLICK,onMouseClick);
}
private function onMouseOver(event:Event):void
{
gotoAndStop(2);
letterText.text = buttonText;
//trace ("You're over me and my text is " + buttonText);
}
private function onMouseOut(event:Event):void
{
gotoAndStop(1);
letterText.text = buttonText;
//trace ("You're out of me and my text is " + buttonText);
}
private function onMouseClick(event:Event):void
{
trace ("I am clicked and I am " + buttonText);
event.target.parent.checkGuess(buttonText);
}
}
} 而從levelTwo的相關位:
public function checkGuess(guess:String):void
{ //Check to see if the guess matches the string
trace ("Guess: "+guess);
for(var i:int=0;i<answer.length;i++)
{
if(guess == answer.charAt(i))
{
censoredAnswer[i] = guess;
trace ("Got one right");
answerField.text = answerRedisplay(); //Do it now or it won't update for the check
}
}
if (answerField.text == answer)
{
setWin();
}
}
管理以解決此問題:MovieClip(parent).checkGuess(buttonText); – GilloD