Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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 在字符串上找不到AS3错误属性5,并且没有默认值_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 在字符串上找不到AS3错误属性5,并且没有默认值

Actionscript 3 在字符串上找不到AS3错误属性5,并且没有默认值,actionscript-3,flash,Actionscript 3,Flash,我是集成Flash的新手。我对一个项目有意见。我正在flash Cs5.5中工作。下面是我的堆栈和代码。有人能告诉我我做错了什么吗 我的堆栈错误: ReferenceError: Error #1069: Property 5 not found on String and there is no default value. at SceneQues_fla::MainTimeline/randomRange() at SceneQues_fla::MainTimeline/q

我是集成Flash的新手。我对一个项目有意见。我正在flash Cs5.5中工作。下面是我的堆栈和代码。有人能告诉我我做错了什么吗

我的堆栈错误:

ReferenceError: Error #1069: Property 5 not found on String and there is no default value.
    at SceneQues_fla::MainTimeline/randomRange()
    at SceneQues_fla::MainTimeline/ques()
我的代码:场景1:

     stop();

     var question:Array =["slide2","slide3","slide4","slide5"];
     function randomRange(array) {
     var i = array.length,
         j = 0,
         temp;


    while (i--) {

        j = Math.floor(Math.random() * (i+1));
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;

    }

    return array;
}

start_btn.addEventListener(MouseEvent.CLICK, ques);
function ques(event:MouseEvent):void
{   

     var randomRange = String(randomRange(question[0]));
     gotoAndStop(randomRange);
}




    /* start_btn.addEventListener(MouseEvent.CLICK, ques  ); 
     function ques(e:MouseEvent):void
{
我在flash中使用了六个不同的场景。我已经在场景中声明了帧标签<代码>幻灯片2是场景2,
slide3
是场景3,
slide4
是场景4,
slide5
是场景5

谢谢。

首先,您的功能:

function randomRange(array) {
var randomRange = String(randomRange(question[0]));
//                                   ^^^^^^^^^^^ This value is the string "slide2".
以及您对该函数的输入:

function randomRange(array) {
var randomRange = String(randomRange(question[0]));
//                                   ^^^^^^^^^^^ This value is the string "slide2".
请注意,您是如何向需要数组的函数提供字符串的。

在函数ques()中,您调用:RandomRange(问题[0]),但问题[0]是slide2,数组问题的第一个元素

您的参数是
字符串
,而不是
数组
。因此,您的变量i给出了slide2的长度,您使用循环遍历该字符串,如下所示,导致相同的错误:

var myString:String = 'slide5';
var i:int = myString.length; // 6
while (i--)
{
    trace(i); // 5 4 3 2 1 0
    trace(myString[i]); // first iteration (5) causes the error message.
}
您的代码应该是这样的:

var questions:Array = [['slide2','scene2'],
                       ['slide3','scene3'],
                       ['slide4','scene4'],
                       ['slide5','scene5']];

var len:int = questions.length; // 4

start_btn.addEventListener(MouseEvent.CLICK, ques);

function ques(event:MouseEvent):void
{
    var k:int = Math.floor(Math.random() * len);
    gotoAndStop(questions[k][0], questions[k][1]);
}

我需要一个数组元素场景,同时使用随机数函数,这就是为什么我使用这个var randomRange=String(randomRange(问题[0]);是对还是错?@SathisJo错了,也许你的意思是
randomRange(问题)
?如果我使用String(randomRange(问题));同时,我有一个错误——在场景1中找不到帧标签slide3,slide5,slide4,slide2……我该怎么办?谢谢你的重播helloflash。但我在出现此错误时使用了你的代码。错误:在场景1中找不到帧标签slide4。在flash.display::MovieClip/gotoAndStop()at Randomques_fla::main timeline/ques()@Sathis Jo,您必须通过单击主时间线的框架并使用属性面板中的标签菜单来创建标签。