ボタンを押し続けると動き続ける。




1.オブジェクトアクション

  • 各ボタンに記述
  • peach_mcの大きさ120×100
  • ステージ550×400

on (press) {
  peach_mc.onEnterFrame = function() {
  var rate = 10;
  peach_mc._y -= rate;
  if(peach_mc._y <= -50) {
  peach_mc._y =450;
		}
	}
}
on (release) {
	peach_mc.onEnterFrame = undefined;
}

2.イベントハンドラメソッド(匿名関数)

var rate:Number = 10;
//上ボタンの設定
top_btn.onPress = function()
{
	peach_mc.onEnterFrame = function()
	{
		peach_mc._y -= rate;
		if (peach_mc._y <= -50)
		{
			peach_mc._y = 450;
		}
	}
}
//ボタンを離した時の設定
top_btn.onRelease = function()
{
	peach_mc.onEnterFrame = undefined;
}

//下ボタンの設定
bottom_btn.onPress = function()
{
	peach_mc.onEnterFrame = function()
	{
		peach_mc._y += rate;
		if (peach_mc._y >= 450)
		{
			peach_mc._y = -50;
		}
	}
}

bottom_btn.onRelease = function()
{
	peach_mc.onEnterFrame = undefined;
}

//左ボタンの設定
left_btn.onPress = function()
{
	peach_mc.onEnterFrame = function()
	{
		peach_mc._x -= rate;
		if (peach_mc._x <= -60)
		{
			peach_mc._x = 610;
		}
	}
}
left_btn.onRelease = function()
{
	peach_mc.onEnterFrame = undefined;
}

//右ボタンの設定
right_btn.onPress = function()
{
	peach_mc.onEnterFrame = function()
	{
		peach_mc._x += rate;
		if (peach_mc._x >= 610)
		{
			peach_mc._x = -60;
		}
	}
}
right_btn.onRelease = function()
{
	peach_mc.onEnterFrame = undefined;
}