Ich habe einen Movieclip, der ein Textfeld und dann eine Schaltfläche enthält. Ich muss in der Lage sein, die Farbe des Textes zu ändern, wenn Benutzer die Maus über den Text bewegt. Unten ist das Code-Snippet. Wie kann ich von außerhalb der Funktion auf einen Verweis auf das Textfeld zugreifen? Danke im Voraus.Zugriff auf Movieclip-Objekte außerhalb des Funktionsbereichs
private Funktion createRows() { var containerMc: MovieClip = Zeile;
//Create Text
var myTxt:TextField = new TextField();
myTxt.htmlText = labelName;
myTxt.antiAliasType = AntiAliasType.ADVANCED;
myTxt.selectable = false;
//Create Symbol Format Text
var myTxtFormat:TextFormat = new TextFormat();
myTxtFormat.color = 0x000000;
myTxtFormat.font = font;
myTxtFormat.bold = "bold";
myTxtFormat.size = fontSize;
//Format text
myTxt.setTextFormat(myTxtFormat);
containerMc.addChild(myTxt);
//Create button
var btn:Sprite = new Sprite();
btn.graphics.beginFill(rowColor);
btn.graphics.drawRect(0, 0, width, height);
btn.graphics.endFill();
btn.alpha = 0;
btn.name = someName;
btn.buttonMode = true;
btn.addEventListener(MouseEvent.MOUSE_OVER,testMouseOver);
containerMc.addChild(btn);
}
private Funktion testMouseOver (e: Mouseevent) { var myTxtFormat: Textformat = new Textformat(); myTxtFormat.color = 0xccff00;
var myText:TextField = new TextField;
myText.htmlText = e.currentTarget.name;
myText.setTextFormat(symTxtFormat);
}
OK, so heres, was ich hinzugefügt: createRows() - Ich habe einen Namen hinzugefügt, um die container.name = "myContainer" und myTxt.name = "htmlTxtField"; Bei testMouseOver() füge ich hinzu var containerMC: MovieClip = getChildByName ("myContainer"); var txtField: TextField = containerMC.getChildByName ("htmlTxtField"); Ich erhalte den Fehler -1118: Implizite Nötigung eines Wertes mit dem statischen Typ flash.display: DisplayObject in einen möglicherweise nicht verwandten Typ flash.text: TextField. Was mache ich falsch? – Iris
Ich habe es versäumt, die "as MovieClip" und "as TextField" zu den Enden der getChildByName Aufrufe hinzuzufügen. Siehe meine Bearbeitung. –