0

我似乎找不到这个问题的答案。我无法使以下工作:

public class Callbattle extends MovieClip
    {
import flash.display.MovieClip;
import flash.display.Stage;
import flash.display.InteractiveObject;
import flash.events.MouseEvent;
import global.Globalvar;

    public var battlegraphics:Array = new Array();
    public function Battle()
    {



        var battlewindow:MovieClip = new Battlewindow() as MovieClip;
        battlegraphics.push(addChild(battlewindow));
        battlewindow.x = 4; 
        battlewindow.y = 248;

        var attackbutton:MovieClip = new Battlebutton() as MovieClip;
        battlegraphics.push(addChild(attackbutton));
        attackbutton.x = 192; 
        attackbutton.y = 255;

        attackbutton.addEventListener(MouseEvent.CLICK, Attackclicked);


    }

    public function Attackclicked(event:MouseEvent):void{
        battlegraphics[attackbutton].y = 248;
    }

}

我收到错误

Battlegraphics[攻击按钮].y = 248;

在尝试这种将影片剪辑添加到数组的方法之前,我这样做了,结果相同:

public class Callbattle extends MovieClip
        {
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.display.InteractiveObject;
    import flash.events.MouseEvent;
    import global.Globalvar;
public function Battle()
        {



            var battlewindow:MovieClip = new Battlewindow() as MovieClip;
            this.addChild(battlewindow);
            battlewindow.x = 4; 
            battlewindow.y = 248;

            var attackbutton:MovieClip = new Battlebutton() as MovieClip;
            this.addChild(attackbutton);
            attackbutton.x = 192; 
            attackbutton.y = 255;

            attackbutton.addEventListener(MouseEvent.CLICK, Attackclicked);

            while (Globalvar.battle == true){

                if (hero1turn == true){

                }
            }
        }

        public function Attackclicked(event:MouseEvent):void{
            attackbutton.y = 248;
        }
    }

我基本上只是希望能够从另一个函数访问一个影片剪辑。

谢谢大家,任何帮助都会很棒-马克

4

2 回答 2

1

诀窍是,如果您要引用数组的内容,则使用 type 的索引int,或者在某些情况下 type String,而您attackbutton在该函数中未定义。解决方案非常简单:在函数attackbutton外部声明,并从启动中删除。Battle()varattackButton

public class Battle extends MovieClip {
    private var attackbutton:MovieClip;
    private var battlewindow:MovieClip;
    public function Battle() {
        attackbutton=new Battlebutton();
        battlewindow=new Battlewindow();
        ...
    }
    public function attackClicked(event:MouseEvent):void {
        attackbutton.y=248; // this is now valid
    }
}
于 2013-05-14T11:33:57.913 回答
1

Battlegraphics [攻击按钮].y = 248;

数组应该采用数字而不是您指定的变量名称。所以会是

战图[1].y = 248;

于 2013-05-14T11:37:11.483 回答