ActionScript 3 删除对象,iPhone App样式

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 删除对象,iPhone App样式相关的知识,希望对你有一定的参考价值。

private var timer:Timer = new Timer(1000); //The time to hold the mouse button down the icon in order to show the delete button
private var tiltTimer:Timer = new Timer(80); //The time of the rotation change, makes the shake effect
private var rotationValue:int = 2; //The rotation desired for the shake
private var tween:Tween; //A tween instance to animate the alert dialog

public function Main():void
{

/*Hide elements*/
	hideObjects(appIcon.deleteButton, deleteAlert, darkScreen);

/*Add necesary listeners*/
	deleteAlert.cancelBtn.addEventListener(MouseEvent.MOUSE_UP, cancel);
	deleteAlert.deleteBtn.addEventListener(MouseEvent.MOUSE_UP, deleteApp);
	appIcon.deleteButton.addEventListener(MouseEvent.MOUSE_UP, displayAlert);
	appIcon.addEventListener(MouseEvent.MOUSE_UP, stopTimer);
	appIcon.addEventListener(MouseEvent.MOUSE_DOWN, pressAndHold);
}

/*Hide objects function*/
private function hideObjects(...objects):void
{
	for(var i:int = 0; i < objects.length; i++)
	{
		objects[i].visible = false;
	}
}

/*Starts the timer when the mouse is down*/
private function pressAndHold(e:MouseEvent):void
{
	timer.start();
	timer.addEventListener(TimerEvent.TIMER, showDeleteButton);
}

/*If mouse up, timer stops*/
private function stopTimer(e:MouseEvent):void
{
	timer.stop();
}

/*if the hold timer completes, the delete button is shown and the icon shakes*/
private function showDeleteButton(e:TimerEvent):void
{
	timer.stop();
	appIcon.deleteButton.visible = true;
	tiltTimer.addEventListener(TimerEvent.TIMER, tilt);
	tiltTimer.start();
}

/*The shake function, changes the rotation every time the tiltTimer completes*/
private function tilt(e:TimerEvent):void
{
	appIcon.rotation = rotationValue;
	rotationValue *=  -1;
}

/*if the delete button is pressed the alert is shown*/
private function displayAlert(e:MouseEvent):void
{
	deleteAlert.visible = true;
	darkScreen.visible = true;
	tween = new Tween(deleteAlert,"scaleX",Back.easeOut,0.3,1,0.5,true);
	tween = new Tween(deleteAlert,"scaleY",Back.easeOut,0.3,1,0.5,true);
}

/*removes the icon if the delete button in the alert is clicked*/
private function deleteApp(e:MouseEvent):void
{
	hideObjects(appIcon, deleteAlert, darkScreen);
}

/* removes the alert, stops the tilt and doesn't remove the icon, called by the cancel button*/
private function cancel(e:MouseEvent):void
{
	hideObjects(appIcon.deleteButton, deleteAlert, darkScreen);
	tiltTimer.stop();
	appIcon.rotation = 0;
}

以上是关于ActionScript 3 删除对象,iPhone App样式的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3删除对象函数

ActionScript 3 从TextFlow中删除所有FlowElement对象

Actionscript 3:当元素是对象/类实例时,识别要删除的数组元素

Actionscript 3 - 如何在删除该事件后保留该事件的值

如何从 Actionscript 3.0 中的数组 B 中的数组 A 中删除元素?

ActionScript 3.0 当你单击一个对象时,我如何使它进入下一个场景?