论坛风格切换切换到宽版
  • 22537阅读
  • 0回复

iPad Multitouch color test  多点触摸 测试 颜色坏点 保存图片到相册 [复制链接]

上一主题 下一主题
 

发帖
1077
  • 来源:原创
  • 编程环境:FlashCS5
  • 平台:iPhone iPad IOS系统
  • 是否解决:已解决
  • 作品案例类别:游戏
  • 组件或控件:
自己做的测试Ipad 的多点触摸 测试, 可以方便测试出最多支持多少个点同时触摸, 答案是11个.
iTouch4 最多支持5个点
还有支持测试红 蓝 黄 等纯色 用来测试屏幕是否有坏点.

iPad版本可以把图形保存到相册里面
下载 iPad 版本   MutitouchTestHD.rar (4570 K) 下载次数:3510

下载 iphone iTouch 版本   MutitouchTest.rar (4006 K) 下载次数:2159





源码
  1. import flash.events.TouchEvent;
  2. import flash.events.MouseEvent;
  3. import flash.ui.Multitouch;
  4. import flash.ui.MultitouchInputMode;
  5. import flash.display.Sprite;
  6. Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
  7. var text1:String;
  8. var text2:String;
  9. var text3:String;
  10. var touchtotal:int = 0;
  11. var touchMoveID:int = 0;
  12. var touchgrouplength:int;
  13. var touchgroup:Array = new Array();
  14. var ballgroup:Array = new Array();
  15. var myline1:Sprite = new Sprite();
  16. var tempballnum:int;
  17. var tempflagx:Boolean;
  18. var tempflagy:Boolean;
  19. var tempflagcolorbox:Boolean = true;
  20. var tempflag:Boolean;
  21. var boxlefty:Number = 135;
  22. var color:uint = rgb();
  23. if (Multitouch.supportedGestures)
  24. {
  25.     //text1 = "● MaxTouchPoint: 5 points for iTouch and 11 points for Ipad. SupportsGesture,";
  26.     text1 = "● MaxMutiTouchSupport: 5 points for iTouch and 11 points for Ipad.";
  27. }
  28. else
  29. {
  30.     text1 = "● No supports Gesture  ";
  31. }
  32. if (Multitouch.supportsGestureEvents)
  33. {
  34.     //text2 = "SupportsGestureEvents, ";
  35.     text2 = "";
  36. }
  37. else
  38. {
  39.     text2 = "No supports GestureEvents  ";
  40. }
  41. if (Multitouch.supportsTouchEvents)
  42. {
  43.     //text3 = "SupportsTouchEvents";
  44.     text3 = "";
  45. }
  46. else
  47. {
  48.     text3 = "No supports TouchEvents";
  49. }
  50. mytext1.text = text1 + text2 + text3;
  51. startbutton.addEventListener(TouchEvent.TOUCH_TAP, taphandler);
  52. function taphandler(evt:TouchEvent):void
  53. {
  54.     removeChild(startbutton);
  55.     removeChild(group1);
  56.     removeChild(group2);
  57.     stage.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
  58.     stage.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
  59.     stage.addEventListener(TouchEvent.TOUCH_END, onTouchEnd1);
  60.     savebutton.addEventListener(TouchEvent.TOUCH_TAP, savebuttonfunc);
  61.     clearbutton.addEventListener(TouchEvent.TOUCH_TAP, clearbuttonfunc);
  62.     
  63.     //myline1.cacheAsBitmap = true;
  64.     addChild(myline1);
  65. }
  66. function clearbuttonfunc(eClear:TouchEvent)
  67. {
  68.     touchgrouplength = touchgroup.length;
  69.     for (var j:int=0; j<touchgrouplength; j++)
  70.     {
  71.         removeChild(getChildByName("ball" + touchgroup[j].toString()));        
  72.     }
  73.     myline1.graphics.clear();
  74.     touchgroup.length = 0;
  75.     ballgroup.length = 0;    
  76. }
  77. function savebuttonfunc(eSave:TouchEvent)
  78. {
  79.     if (CameraRoll.supportsAddBitmapData)
  80.     { //保存图片到相册
  81.         var cameraRoll:CameraRoll = new CameraRoll();
  82.         cameraRoll.addEventListener(ErrorEvent.ERROR, onCrError);
  83.         cameraRoll.addEventListener(Event.COMPLETE, onCrComplete);
  84.         var bitmapData:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
  85.         bitmapData.draw(stage);
  86.         cameraRoll.addBitmapData(bitmapData);
  87.     }
  88.     else{
  89.         mytext1.text ="CameraRoll not supported.";
  90.     }
  91. }
  92. function onCrError(event:ErrorEvent):void
  93. {
  94.     mytext1.text ="Not enough space on your device.";
  95. }
  96. function onCrComplete(event:Event):void
  97. {
  98.     mytext1.text ="The pic have been saved to your album.";
  99. }
  100. function onTouchBegin(eBegin:TouchEvent)
  101. {
  102.     touchtotal = touchtotal + 1;
  103.     
  104.     touchMoveID = eBegin.touchPointID;
  105.     tempflagy = (eBegin.stageY > boxlefty) && (eBegin.stageY < 1024);
  106.     tempflagx = (eBegin.stageX > 0) && (eBegin.stageX < 768);
  107.     tempflag = tempflagy && tempflagx && tempflagcolorbox;
  108.     
  109.     if (tempflag)
  110.     {
  111.         mytext2.text = "● You have touched " + touchtotal + "points";
  112.         var ball1:Sprite = new ball();
  113.         ball1.x = eBegin.stageX - 35;
  114.         ball1.y = eBegin.stageY - 35;
  115.         ball1.name = "ball" + touchMoveID.toString();
  116.         ball1.cacheAsBitmap = true;
  117.         ballgroup.push(ball1);
  118.         addChild(ball1);
  119.         touchgroup.push(touchMoveID);
  120.         switch (ballgroup.length)
  121.         {//重新画一遍所有的线
  122.             case 0 :
  123.                 break;
  124.             case 1 :
  125.                 break;
  126.             case 2 :
  127.                 myline1.graphics.clear();
  128.                 myline1.graphics.lineStyle(4, color, 1);
  129.                 myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
  130.                 myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);                
  131.                 break;
  132.             default :                
  133.                 myline1.graphics.clear();
  134.                 myline1.graphics.lineStyle(4,color, 1);
  135.                 
  136.                 var allline_commands:Vector.<int> = new Vector.<int>();
  137.                 var allline_points:Vector.<Number> = new Vector.<Number>();
  138.                 
  139.                 allline_commands.push(1);//开头永远是1
  140.                 for (var n:int =0; n<ballgroup.length; n++)
  141.                 {
  142.                     allline_commands.push(2);//Move永远是2
  143.                     allline_points.push((ballgroup[n].x + ballgroup[n].width/2), (ballgroup[n].y + ballgroup[n].height/2));
  144.                 }
  145.                 allline_points.push((ballgroup[0].x + ballgroup[0].width/2), (ballgroup[0].y + ballgroup[0].height/2));
  146.                 myline1.graphics.drawPath(allline_commands, allline_points);
  147.         }
  148.     }
  149. }
  150. function onTouchMove(eMove:TouchEvent)
  151. {
  152.     if (tempflagcolorbox)
  153.     {
  154.         getChildByName("ball" + eMove.touchPointID).x = eMove.stageX - 35;
  155.         getChildByName("ball" + eMove.touchPointID).y = eMove.stageY - 35;
  156.         
  157.         switch (ballgroup.length)
  158.         {//删除已有的线重画
  159.             case 0 :
  160.                 break;
  161.             case 1 :
  162.                 break;
  163.             case 2 :                
  164.                 myline1.graphics.clear();
  165.                 myline1.graphics.lineStyle(4, color, 1);
  166.                 myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
  167.                 myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);
  168.                 break;    
  169.                 
  170.             default :
  171.                 myline1.graphics.clear();
  172.                 myline1.graphics.lineStyle(4,color, 1);
  173.                 
  174.                 var allline_commands:Vector.<int> = new Vector.<int>();
  175.                 var allline_points:Vector.<Number> = new Vector.<Number>();
  176.                 
  177.                 allline_commands.push(1);//开头永远是1
  178.                 for (var n:int =0; n<ballgroup.length; n++)
  179.                 {
  180.                     allline_commands.push(2);//Move永远是2
  181.                     allline_points.push((ballgroup[n].x + ballgroup[n].width/2), (ballgroup[n].y + ballgroup[n].height/2));
  182.                 }
  183.                 allline_points.push((ballgroup[0].x + ballgroup[0].width/2), (ballgroup[0].y + ballgroup[0].height/2));
  184.                 myline1.graphics.drawPath(allline_commands, allline_points);
  185.         }
  186.     }
  187. }
  188. function onTouchEnd1(eEnd:TouchEvent)
  189. {
  190.     touchtotal = touchtotal - 1;
  191.     mytext2.text = "● You have touched " + touchtotal + "points";
  192. }
  193. function onTouchEnd(eEnd:TouchEvent)
  194. {
  195.     touchtotal = touchtotal - 1;
  196.     
  197.     if (tempflagcolorbox)
  198.     {        
  199.         mytext2.text = "● You have touched " + touchtotal + "points";
  200.         removeChild(getChildByName("ball" + eEnd.touchPointID));
  201.     
  202.         touchgrouplength = touchgroup.length;
  203.         for (var j:int=0; j<touchgrouplength; j++)
  204.         {
  205.             if (touchgroup[j] == eEnd.touchPointID)
  206.             {
  207.                 touchgroup.splice(j, 1);
  208.                 ballgroup.splice(j, 1);
  209.                 break;
  210.             }
  211.         }
  212.     
  213.         switch (ballgroup.length)
  214.         {//重新画一遍所有的线
  215.             case 0 :
  216.                 break;
  217.             case 1 :
  218.                 myline1.graphics.clear();
  219.                 color = rgb();
  220.                 break;
  221.             case 2 :
  222.                 myline1.graphics.clear();
  223.                 myline1.graphics.lineStyle(4, color, 1);
  224.                 myline1.graphics.moveTo(ballgroup[0].x + ballgroup[0].width/2, ballgroup[0].y + ballgroup[0].height/2);
  225.                 myline1.graphics.lineTo(ballgroup[1].x + ballgroup[1].width/2, ballgroup[1].y + ballgroup[1].height/2);
  226.                 break;
  227.     
  228.             default :
  229.                 myline1.graphics.clear();
  230.                 myline1.graphics.lineStyle(4,color, 1);
  231.                     
  232.                 var allline_commands:Vector.<int> = new Vector.<int>();
  233.                 var allline_points:Vector.<Number> = new Vector.<Number>();
  234.                     
  235.                 allline_commands.push(1);//开头永远是1
  236.                 for (var n:int =0; n<ballgroup.length; n++)
  237.                 {
  238.                     allline_commands.push(2);//Move永远是2
  239.                     allline_points.push((ballgroup[n].x + ballgroup[n].width/2), (ballgroup[n].y + ballgroup[n].height/2));
  240.                 }
  241.                 allline_points.push((ballgroup[0].x + ballgroup[0].width/2), (ballgroup[0].y + ballgroup[0].height/2));
  242.                 myline1.graphics.drawPath(allline_commands, allline_points);
  243.         }
  244.     }
  245. }
  246. function rgb():uint
  247. {
  248.     return (Math.random() * 0xffffff + 0xff000000);
  249. }
  250. color1.addEventListener(TouchEvent.TOUCH_TAP, colorfunc1);
  251. function colorfunc1(evt:TouchEvent):void
  252. {
  253.     tempflagcolorbox = false;
  254.     var colorbox:colorbox1 = new colorbox1();
  255.     addChild(colorbox);
  256.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  257. }
  258. function colorboxremovefunc(evt:TouchEvent):void
  259. {
  260.     evt.target.removeEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  261.     removeChild(getChildByName(evt.target.name));
  262.     tempflagcolorbox = true;
  263. }
  264. color2.addEventListener(TouchEvent.TOUCH_TAP, colorfunc2);
  265. function colorfunc2(evt:TouchEvent):void
  266. {
  267.     tempflagcolorbox = false;
  268.     var colorbox:colorbox2 = new colorbox2();
  269.     addChild(colorbox);
  270.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  271. }
  272. color3.addEventListener(TouchEvent.TOUCH_TAP, colorfunc3);
  273. function colorfunc3(evt:TouchEvent):void
  274. {
  275.     tempflagcolorbox = false;
  276.     var colorbox:colorbox3 = new colorbox3();
  277.     addChild(colorbox);
  278.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  279. }
  280. color4.addEventListener(TouchEvent.TOUCH_TAP, colorfunc4);
  281. function colorfunc4(evt:TouchEvent):void
  282. {
  283.     tempflagcolorbox = false;
  284.     var colorbox:colorbox4 = new colorbox4();
  285.     addChild(colorbox);
  286.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  287. }
  288. color5.addEventListener(TouchEvent.TOUCH_TAP, colorfunc5);
  289. function colorfunc5(evt:TouchEvent):void
  290. {
  291.     tempflagcolorbox = false;
  292.     var colorbox:colorbox5 = new colorbox5();
  293.     addChild(colorbox);
  294.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  295. }
  296. color6.addEventListener(TouchEvent.TOUCH_TAP, colorfunc6);
  297. function colorfunc6(evt:TouchEvent):void
  298. {
  299.     tempflagcolorbox = false;
  300.     var colorbox:colorbox6 = new colorbox6();
  301.     addChild(colorbox);
  302.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  303. }
  304. color7.addEventListener(TouchEvent.TOUCH_TAP, colorfunc7);
  305. function colorfunc7(evt:TouchEvent):void
  306. {
  307.     tempflagcolorbox = false;
  308.     var colorbox:colorbox7 = new colorbox7();
  309.     addChild(colorbox);
  310.     colorbox.addEventListener(TouchEvent.TOUCH_TAP, colorboxremovefunc);
  311. }

快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个