动作脚本
我在使用计时器功能时遇到问题。
我想做跟随程序。第一:生成随机数并放置数组。第二:通过存储的数组以3秒的间隔执行功能。
但是在使用定时器功能时,我不能使用应该执行间隔 3 秒的功能参数。
错误消息: RangeError:错误 #1125:索引 7 超出范围 4。在 views::twoHomeView/onTimer()[C:\Users\Kinect\Adobe Flash Builder 4.6\yattah\src\views\twoHomeView.mxml: 26] 在 flash.utils::Timer/_timerDispatch()
在 flash.utils::Timer/tick()
<?xml version="1.0" encoding="utf-8"?>
<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, 3);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
var kaisu:int =0;
private function onTimer(event:TimerEvent):void
{
for(var i:int;i<n.length;i++){
kaisu += 1;
display(n[kaisu]);
}
}
public var n:Vector.<int> = new Vector.<int>(4);
public var a:int =0;
public var s:int =0;
function display(q:int):void{//show the picture(ue,migi,shita,hidari) 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
{
ue.visible= false;
migi.visible= false;
shita.visible= false;
hidari.visible= true;
}
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
display(0);
}
protected function button2_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
display(0);
}
protected function right_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
display(1);
}
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//put random number in array
{
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];
}
]]>
</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="↓"
/>
<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="80" y="49" smooth="true" source="assets/migi.png"/>
<s:Image id="good" x="-21" y="84" width="363" height="103" visible="false" source="assets/good.png"/>