Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在文档类中填充数组_Actionscript 3_Flash_Flash Cs6 - Fatal编程技术网

Actionscript 3 在文档类中填充数组

Actionscript 3 在文档类中填充数组,actionscript-3,flash,flash-cs6,Actionscript 3,Flash,Flash Cs6,我想做一个有4个选择题按钮的测验。选择一个答案后,它会播放一个简短的动画并引导您进入下一个问题。我一直在用时间线代码来完成这一切,但我已经了解到AS3更适合使用类文件进行面向对象编程,所以我现在正在尝试 我想不是每个问题1帧,而是为所有问题1帧,并从数组填充问题标题和答案按钮。我最初在“动作脚本”层中定义数组,但现在我决定在名为DocumentClass.as的类文件中进行定义。到目前为止,我尚未完成的代码是: package { import flash.display.MovieCl

我想做一个有4个选择题按钮的测验。选择一个答案后,它会播放一个简短的动画并引导您进入下一个问题。我一直在用时间线代码来完成这一切,但我已经了解到AS3更适合使用类文件进行面向对象编程,所以我现在正在尝试

我想不是每个问题1帧,而是为所有问题1帧,并从数组填充问题标题和答案按钮。我最初在“动作脚本”层中定义数组,但现在我决定在名为DocumentClass.as的类文件中进行定义。到目前为止,我尚未完成的代码是:

    package {
import flash.display.MovieClip;


public class DocumentClass extends MovieClip
{
//global definitions
private var milanquestions:Array = new Array();
private var milancorrectanswers:Array = new Array();
private var userscore:Number = 0;
private var currentquestion:Number = 0;

milanquestions[0] = "What is the primary type of Rescue used?";
milanquestions[1] = "Why is Remote Lower the preffered method to use?";
milanquestions[2] = "Which pieces of equipment are needed to complete a Rescue safely?";
milanquestions[3] = "Who conducts the Rescue?";
milanquestions[4] = "Once the casualty reaches the ground, what is it important to do first?";
milanquestions[5] = "What is used to keep the casualty clear of any obstruction?";

milancorrectanswers[0] = "Remote Lower";
milancorrectanswers[1] = "It can be done without another operative needing to climb down to the casualty";
milancorrectanswers[3] = "A Balfour Beatty operative trained in Tower Rescue";
milancorrectanswers[4] = "Place in the recovery position and administer first aid where possible";
milancorrectanswers[5] = "A holding out rope";

public function DocumentClass()
    {
        //a place for listeners
    }
  }
}
使用此代码,在数组中的每个条目上都会出现以下错误:

P:\Interactive Animation test folder\DocumentClass.as, Line 13  1120: Access of undefined property milanquestions.
P:\Interactive Animation test folder\DocumentClass.as, Line 14  1120: Access of undefined property milanquestions.
等等


我希望用问题和正确答案填充数组,但我似乎无法回避这些错误。有什么想法吗?或者有什么更好的方法来完成我想做的事情吗?

试着把数组赋值放在某个函数中,然后在构造函数中调用该函数。就像我说的,我使用动作脚本和Flash不到一天,我不是程序员。任何答案都必须少一点含糊,多一点描述性。非常好,谢谢。这就是你调用函数的方式吗?随便说说吧?如果它不在同一个类中,我假设它的位置?是的,调用一个函数就是
myFunctionName(),已授予它在同一类中。
public class DocumentClass extends MovieClip
{
     //global definitions
    private var milanquestions:Array = new Array();
    private var milancorrectanswers:Array = new Array();
    private var userscore:Number = 0;
    private var currentquestion:Number = 0;

    public function DocumentClass()
    {
    //a place for listeners
         initAnswerAndQuestions();
    }

    private function initAnswerAndQuestions():void {

        milanquestions[0] = "What is the primary type of Rescue used?";
        milanquestions[1] = "Why is Remote Lower the preffered method to use?";
        milanquestions[2] = "Which pieces of equipment are needed to complete a Rescue safely?";
        milanquestions[3] = "Who conducts the Rescue?";
        milanquestions[4] = "Once the casualty reaches the ground, what is it important to do first?";
        milanquestions[5] = "What is used to keep the casualty clear of any obstruction?";


        milancorrectanswers[0] = "Remote Lower";

        milancorrectanswers[1] = "It can be done without another operative needing to climb down to the casualty";
        milancorrectanswers[3] = "A Balfour Beatty operative trained in Tower Rescue";
        milancorrectanswers[4] = "Place in the recovery position and administer first aid where possible";
        milancorrectanswers[5] = "A holding out rope";
    }
}