アクションスクリプト
タイマー機能に問題があります。
フォロープログラムを作りたいです。まず、乱数を生成して配列を作成します。2番目:格納された配列によって3秒間隔で機能を実行します。
しかし、タイマー機能を使用する場合、3秒間隔で実行する機能の引数は使用できません。
エラーメッセージ:RangeError:Error#1125:index 7 is out of range 4. at 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"/>