Corona中文站

强大、易学的跨平台(iOS/Android)开发框架。QQ群1:74390406(满) 群2:221929599

导航

iOS 设备多点触控和屏幕坏点检测程序代码
本段代码由 CocoaChina 会员“jinwyp”分享,能检测 iOS 设备多点触控上限,并能以显示纯色的方式检查屏幕是否有坏点。
import flash.events.TouchEvent;

import flash.events.MouseEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.display.Sprite;

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

var text1:String;
var text2:String;
var text3:String;
var touchtotal:int = 0;
var touchMoveID:int = 0;

var touchgrouplength:int;
var touchgroup:Array = new Array();
var ballgroup:Array = new Array();
var myline1:Sprite = new Sprite();
var tempballnum:int;
var tempflagx:Boolean;
var tempflagy:Boolean;
var tempflag:Boolean;
var color:uint = rgb();

if (Multitouch.supportedGestures)
{
text1 = "● SupportsGesture, Support " + Multitouch.maxTouchPoints.toString() + " MaxTouchPoint ";
}
else
{
text1 = "● No supports Gesture ";
}

if (Multitouch.supportsGestureEvents)
{
text2 = "SupportsGestureEvents ";
}
else
{
text2 = "No supports GestureEvents ";
}

if (Multitouch.supportsTouchEvents)
{
text3 = "SupportsTouchEvents";
}
else
{
text3 = "No supports TouchEvents";
}


mytext1.text = text1 + text2 + text3;

startbutton.addEventListener(TouchEvent.TOUCH_TAP, taphandler);

function taphandler(evt:TouchEvent):void
{
removeChild(startbutton);
removeChild(group1);
removeChild(group2);
stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}


function onTouchBegin(eBegin:TouchEvent)
{
touchtotal = touchtotal + 1;
mytext2.text = "● You have touched " + touchtotal + "points";
touchMoveID = eBegin.touchPointID;

tempflagy = (eBegin.stageY > touchbox.y) && (eBegin.stageY < (touchbox.y + touchbox.height));
tempflagx = (eBegin.stageX > touchbox.x) && (eBegin.stageX < (touchbox.x + touchbox.width));
tempflag = tempflagy && tempflagx;

if (tempflag)
{
var ball1:Sprite = new ball();
ball1.x = eBegin.stageX - 35;
ball1.y = eBegin.stageY - 35;
ball1.name = "ball" + touchMoveID.toString();
ballgroup.push(ball1);
addChild(ball1);

touchgroup.push(touchMoveID);

switch (ballgroup.length)
{
case 0 :
break;
case 1 :
break;
case 2 :
var myline1:Sprite = new Sprite();
myline1.name = "line" + (ballgroup.length-1);
myline1.graphics.clear();
myline1.graphics.lineStyle(4, color, 1);
myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);
addChild(myline1);
break;

default :
var myline2:Sprite = new Sprite();
myline2.name = "line" + (ballgroup.length-1);
myline2.graphics.clear();
myline2.graphics.lineStyle(4,color, 1);
myline2.graphics.moveTo(ballgroup[ballgroup.length-2].x + ballgroup[ballgroup.length-2].width/2, ballgroup[ballgroup.length-2].y + ballgroup[ballgroup.length-2].height/2);
myline2.graphics.lineTo(ballgroup[ballgroup.length-1].x + ballgroup[ballgroup.length-1].width/2, ballgroup[ballgroup.length-1].y + ballgroup[ballgroup.length-1].height/2);
addChild(myline2);

var myline3:Sprite = new Sprite();
myline3.name = "line" + (ballgroup.length);
myline3.graphics.clear();
myline3.graphics.lineStyle(4,color, 1);
myline3.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline3.graphics.lineTo(ballgroup[ballgroup.length-1].x + ballgroup[ballgroup.length-1].width/2, ballgroup[ballgroup.length-1].y + ballgroup[ballgroup.length-1].height/2);
addChild(myline3);

if (ballgroup.length > 3)
{
removeChild(getChildByName("line" + (ballgroup.length-1)));
}
}


}

}

function onTouchMove(eMove:TouchEvent)
{
getChildByName("ball" + eMove.touchPointID).x = eMove.stageX - 35;
getChildByName("ball" + eMove.touchPointID).y = eMove.stageY - 35;

switch (ballgroup.length)
{//删除已有的线
case 0 :
break;
case 1 :
break;
case 2 :
removeChild(getChildByName("line1"));
break;
default :
for (var m:int =1; m<=ballgroup.length; m++)
{
removeChild(getChildByName("line" + m.toString()));
}

}

switch (ballgroup.length)
{//重新画一遍所有的线
case 0 :
break;
case 1 :
break;
case 2 :
var myline1:Sprite = new Sprite();
myline1.name = "line1";
myline1.graphics.clear();
myline1.graphics.lineStyle(4, color, 1);
myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);
addChild(myline1);
break;

default :
for (var n:int =1; n {
var myline2:Sprite = new Sprite();
myline2.name = "line" + n.toString();
myline2.graphics.clear();
myline2.graphics.lineStyle(4,color, 1);
myline2.graphics.moveTo(ballgroup[n-1].x + ballgroup[n-1].width/2, ballgroup[n-1].y + ballgroup[n-1].height/2);
myline2.graphics.lineTo(ballgroup[n].x + ballgroup[n].width/2, ballgroup[n].y + ballgroup[n].height/2);
addChild(myline2);
}

var myline3:Sprite = new Sprite();
myline3.name = "line" + (ballgroup.length);
myline3.graphics.clear();
myline3.graphics.lineStyle(4,color, 1);
myline3.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline3.graphics.lineTo(ballgroup[ballgroup.length-1].x + ballgroup[ballgroup.length-1].width/2, ballgroup[ballgroup.length-1].y + ballgroup[ballgroup.length-1].height/2);
addChild(myline3);
}





//eEnd.target.stopTouchDrag(eEnd.touchPointID);
//eEnd.target.removeChildAt(1);
}

function onTouchEnd(eEnd:TouchEvent)
{
touchtotal = touchtotal - 1;
mytext2.text = "● You have touched " + touchtotal + "points";
removeChild(getChildByName("ball" + eEnd.touchPointID));


switch (ballgroup.length)
{
case 0 :
break;
case 1 :
break;
case 2 :
removeChild(getChildByName("line1"));
break;
default :
for (var m:int =1; m<=ballgroup.length; m++)
{
removeChild(getChildByName("line" + m.toString()));
}

}

touchgrouplength = touchgroup.length;
for (var j:int=0; j {
if (touchgroup[j] == eEnd.touchPointID)
{
touchgroup.splice(j, 1);
ballgroup.splice(j, 1);
break;
}
}

switch (ballgroup.length)
{//重新画一遍所有的线
case 0 :
break;
case 1 :
color = rgb();
break;
case 2 :
var myline1:Sprite = new Sprite();
myline1.name = "line1";
myline1.graphics.clear();
myline1.graphics.lineStyle(4, color, 1);
myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);
addChild(myline1);
break;
default :
for (var n:int =1; n {
var myline2:Sprite = new Sprite();
myline2.name = "line" + n.toString();
myline2.graphics.clear();
myline2.graphics.lineStyle(4,color, 1);
myline2.graphics.moveTo(ballgroup[n-1].x + ballgroup[n-1].width/2, ballgroup[n-1].y + ballgroup[n-1].height/2);
myline2.graphics.lineTo(ballgroup[n].x + ballgroup[n].width/2, ballgroup[n].y + ballgroup[n].height/2);
addChild(myline2);
}



var myline3:Sprite = new Sprite();
myline3.name = "line" + (ballgroup.length);
myline3.graphics.clear();
myline3.graphics.lineStyle(4, color, 1);
myline3.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
myline3.graphics.lineTo(ballgroup[ballgroup.length-1].x + ballgroup[ballgroup.length-1].width/2, ballgroup[ballgroup.length-1].y + ballgroup[ballgroup.length-1].height/2);
addChild(myline3);
}

//stage.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
//stage.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);

}

function rgb():uint
{
return (Math.random() * 0xffffff + 0xff000000);
}

color1.addEventListener(TouchEvent.TOUCH_TAP, colorfunc1);
function colorfunc1(evt:TouchEvent):void
{
var colorbox:colorbox1 = new colorbox1();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}
function colorboxremovefunc(evt:TouchEvent):void
{
evt.target.removeEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
removeChild(getChildByName(evt.target.name));

}


color2.addEventListener(TouchEvent.TOUCH_TAP, colorfunc2);
function colorfunc2(evt:TouchEvent):void
{
var colorbox:colorbox2 = new colorbox2();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}

color3.addEventListener(TouchEvent.TOUCH_TAP, colorfunc3);
function colorfunc3(evt:TouchEvent):void
{
var colorbox:colorbox3 = new colorbox3();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}

color4.addEventListener(TouchEvent.TOUCH_TAP, colorfunc4);
function colorfunc4(evt:TouchEvent):void
{
var colorbox:colorbox4 = new colorbox4();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}

color5.addEventListener(TouchEvent.TOUCH_TAP, colorfunc5);
function colorfunc5(evt:TouchEvent):void
{
var colorbox:colorbox5 = new colorbox5();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}

color6.addEventListener(TouchEvent.TOUCH_TAP, colorfunc6);
function colorfunc6(evt:TouchEvent):void
{
var colorbox:colorbox6 = new colorbox6();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}

color7.addEventListener(TouchEvent.TOUCH_TAP, colorfunc7);
function colorfunc7(evt:TouchEvent):void
{
var colorbox:colorbox7 = new colorbox7();
addChild(colorbox);
colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
}
<< 引用iphone/iPad开发常用代码iOS程序启动画面Launcher图片的配置方法(支持iPhone、iPad) >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Walle Build 100427 Copyright 2011-2015 BuildApp.Net. All Rights Reserved.