繁体   English   中英

我无法理解以下错误ActionScript

[英]I can't understand following error ActionScript

开发环境为FLASH BUILDER(适用于Android / iOS应用程序)。 我无法理解以下错误。 请修正我的代码。 错误:RangeError:错误#1125:索引2超出范围0。位于以下位置的views :: twoHomeView / sets()[C:\\ Users \\ Adob​​e Flash Builder 4.6 \\ y \\ src \\ views \\ twoHomeView.mxml:162] views :: twoHomeView / down_clickHandler()[C:\\ Users \\ Adob​​e Flash Builder 4.6 \\ y \\ src \\ views \\ twoHomeView.mxml:115] at views :: twoHomeView / __ down_click()[C:\\ Users \\ Adob​​e Flash Builder 4.6 \\ y \\ src \\ views \\ twoHomeView.mxml:203]

码:

<fx:Script>
    <![CDATA[

        import flash.display.Sprite;
        import flash.events.TimerEvent;
        import flash.utils.Timer;


        private var timer:Timer;

        public function Main()
        {
            timer = new Timer(1000, 4);
            timer.addEventListener(TimerEvent.TIMER, onTimer);
            timer.start();
            go.visible=true;
        }
        var kaisu:int =0; 
        public function onTimer(event:TimerEvent):void
        {


                kaisu += 1;
                if(kaisu>=0)
                {
                    go.visible =false;
                }
                display(n[kaisu-1]);
                if(kaisu==5)
                {
                    kaisu = 0;
                }

        }


        public  var n:Vector.<int> = new Vector.<int>(4);   
        public var a:int =0;
        public var s:int =0;


            function display(q:int):void{//矢印を表示させる 0=↑1=→2=↓3=←
            if(q ==0)
            {
                ue.visible= true;
                migi.visible= false;
                shita.visible= false;
                hidari.visible= false;
            }
            else if(q ==1)
            {

                ue.visible= false;
                migi.visible= true;
                shita.visible= false;
                hidari.visible= false;
            }
            else if(q ==2)
            {
                ue.visible= false;
                migi.visible= false;
                shita.visible= true;
                hidari.visible= false;
            }
            else if(q ==3)
            {
                ue.visible= false;
                migi.visible= false;
                shita.visible= false;
                hidari.visible= true;
            }

            else 
            {
                ue.visible= false;
                migi.visible= false;
                shita.visible= false;
                hidari.visible= false;
            }

                }
        protected function button1_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub

            display(3);
            sets(3);
        }

        protected function button2_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub

            display(0);
            sets(0);

        }

        protected function right_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            display(1);
            sets(1);
        }


        protected function down_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            display(2);
            sets(2);
        }



        /*function wait(time:int, handler:Function):void

        {

            var timeri:Timer = new Timer(time, 1);

                timeri.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);

                timeri.start();

            function timerHandler(event:TimerEvent):void

            {

                    handler();

                    timeri.removeEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);

            }

        }   
        function lv1():void{
    }*/

        function showMC():void//配列に乱数を入れ込む。
        {

            for(var i:int;i<n.length;i++)
            {   var r:int = Math.floor(Math.random() * 4);
                n[i]=r;
            }   
            point.text = n[0]+""+" "+n[1]+" "+n[2]+" "+n[3];
        }


        public  var set:Vector.<int> = new Vector.<int>;
        public var points:int=0;
        public var nyuryoku:int =0;
        public var pan:int;

        function sets(q:int){

            if( n[nyuryoku]==set[q]){

        nyuryoku +=1;
        points += 1;
        pan = points;
            tensu.text = pan.toString();
        }
            else
            {
                end();
            }
        }



     function end(){
         bad.visible = true;
         points = 0;
         kaisu = 0;
         display(5);
     }



    ]]>
</fx:Script>

<fx:Declarations>
    <!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
</fx:Declarations>


<s:Image x="-31" y="-40" width="383" height="486" source="assets/yattah.jpg"/>
<s:Button id="left" x="13" y="304" width="50" height="50" label="←"
          click="button1_clickHandler(event)"/>
<s:Label id ="point" x="19" y="7" text="点"/>
<s:Button id="up" x="60" y="257" width="50" height="50" label="↑"
          click="button2_clickHandler(event)"/>
<s:Button id="right" x="107" y="304" width="50" height="50" label="→"
          click="right_clickHandler(event)"/>
<s:Button id="down" x="59" y="352" width="50" height="50" label="↓"
          click="down_clickHandler(event)"/>
<s:Button x="260" y="309" width="50" height="50" label="A" click="Main()"/>
<s:Button x="207" y="359" width="50" label="B" click="showMC()"/>
<s:Image id="ue" x="75" y="33" visible="false" smooth="true" source="assets/ue.png"/>
<s:Image id="shita" x="80" y="49" smooth="true" source="assets/shita.png"/>
<s:Image id="hidari" x="75" y="55" smooth="true" source="assets/hidari.png"/>
<s:Image id="migi" x="100" y="53" smooth="true" source="assets/migi.png"/>
<s:Image id="good" x="-21" y="84" width="363" height="103" visible="false" source="assets/good.png"/>
<s:Image id="go" x="28" y="62" width="263" height="153" visible="false" source="assets/go.png"/>
<s:Label id="tensu" x="19" y="31" text="ラベル"/>
<s:Image id="bad" x="24" y="54" visible ="false" source="assets/bad.png"/>

范围错误表示您正在尝试访问数组或向量的成员,但是该数组或向量在该索引处没有值。

所以对于数组exampleArray = [1,2,3,4]

调用exampleArray [3]是有效的,因为该数组在该索引处包含“ 4”,但是exampleArray [4]将生成错误,因为exampleArray不包含第5个索引。 (提醒,数组和向量索引以零开头,而不是一个)

因此,当您致电:

protected function down_clickHandler(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            display(2);
            sets(2);
        }

当该函数中的代码引用set [2]时,“ sets(2)”行会引起问题,因为set不包含3个成员。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM