我似乎找不到这个问题的答案。我无法让以下工作:
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 [attackbutton] .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;
}
}
我基本上只是希望能够从其他功能访问动画片段。
谢谢大家伙,任何帮助都会很棒 -Mark
答案 0 :(得分:1)
诀窍是,如果您正在引用数组的内容,则使用类型为int
的索引,或者在某些类型为String
的情况下使用索引,而您的attackbutton
未定义功能。解决方案非常简单:在attackbutton
函数之外声明Battle()
,并从启动var
中删除attackButton
。
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
}
}
答案 1 :(得分:1)
battlegraphics [攻击按钮]。y = 248;
数组应该是数字,而不是您指定的变量名称。 所以它将是
battlegraphics [1] .y = 248;