as3在其他类中使用setter(parent)

时间:2014-10-16 14:51:35

标签: actionscript-3

我正在尝试创建一个简单的setter,我喜欢用子类访问它。 这是父类代码:

    public class DeGeheimeMissie extends MovieClip
{
    var deLader:URLLoader;
    var deXmlData:XML;
    public var hoofdVragenLijst:Object = new Object(); 
    public var subVragenLijst:Object = new Object(); 
    public var hetAntwoord:String;

    public function DeGeheimeMissie() 
    {
        var hetVerzoek:URLRequest;
        hetVerzoek = new URLRequest("dialogen.xml");
        deLader = new URLLoader(hetVerzoek);
        deLader.addEventListener(Event.COMPLETE, vragenGeladen);
        deLader.load(hetVerzoek);

        instObama.addEventListener(MouseEvent.CLICK, showVragen);
        instObama.buttonMode    = true;
        instObama.useHandCursor = true;
    }

    public function set hetAntw(str:String):void
    {
        hetAntwoord = str;
    }

这是我尝试访问它的子类:

public class Rutte extends MovieClip
{
    var deLader:URLLoader;
    var deXmlData:XML;
    public var antwoordenOverzicht = []; 
    //constructor
    public function Rutte()
    {
        var hetVerzoek:URLRequest;
        hetVerzoek = new URLRequest("dialogen.xml");
        deLader = new URLLoader(hetVerzoek);
        deLader.addEventListener(Event.COMPLETE, antwoordenGeladen);
        deLader.load(hetVerzoek);

        instRutte.addEventListener(MouseEvent.CLICK, showAntwoorden);
        instRutte.buttonMode    = true;
        instRutte.useHandCursor = true;
    }
        public function setAntwoord(e:MouseEvent)
    {
        var antw = e.currentTarget.text.charAt(0);
        trace(e.currentTarget.text.charAt(0));
        this.parent.hetAntw(antw);
    }

我得到的错误是: 1061:通过静态类型flash.display的引用调用可能未定义的方法hetAntwoord:DisplayObjectContainer。

1 个答案:

答案 0 :(得分:0)

你应该尝试这个,这就是我们使用setter的方式: this.parent.hetAntw = antw;

但为什么要在公共静态变量上创建公共setter?