-
Client Software Programmer
Multi Touch
Hi, i have a grid array of buttons, but when i add multitouch zoom code to it which is found at the end of the script, only the last button in the array zooms in and out, any idea how to get it all into some sort of container in as3 and just be able to zoom the whole thing. Thanks
PHP Code:
import flash.events.MouseEvent;
var rows:int = 40;
var cols:int = 50;
for (var py:int = 0; py <rows; py++)
{
for (var px:int = 0; px <cols; px++)
{
var grid:Grid = new Grid();
grid.x = 200 + grid.width * px;
grid.y = 50 + grid.height * py;
grid.addEventListener(MouseEvent.ROLL_OVER,doFunction);
addChild(grid);
}
}
function doFunction(e:MouseEvent):void
{
trace(e.currentTarget);
trace(MovieClip(root).color_black.currentFrame);
if (MovieClip(root).color_black.currentFrame == 2)
{
e.currentTarget.gotoAndStop(1);
}
if (MovieClip(root).color_grey.currentFrame == 2)
{
e.currentTarget.gotoAndStop(2);
}
if (MovieClip(root).color_white.currentFrame == 2)
{
e.currentTarget.gotoAndStop(3);
}
if (MovieClip(root).color_yellow.currentFrame == 2)
{
e.currentTarget.gotoAndStop(4);
}
if (MovieClip(root).color_green.currentFrame == 2)
{
e.currentTarget.gotoAndStop(5);
}
if (MovieClip(root).color_blue.currentFrame == 2)
{
e.currentTarget.gotoAndStop(6);
}
if (MovieClip(root).color_brown.currentFrame == 2)
{
e.currentTarget.gotoAndStop(7);
}
if (MovieClip(root).color_red.currentFrame == 2)
{
e.currentTarget.gotoAndStop(8);
}
}
color_black.addEventListener(MouseEvent.CLICK, go);
function go(event:MouseEvent): void {
color_black.gotoAndStop(2);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);
}
color_grey.addEventListener(MouseEvent.CLICK, go2);
function go2(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(2);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);
}
color_white.addEventListener(MouseEvent.CLICK, go3);
function go3(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(2);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);
}
color_yellow.addEventListener(MouseEvent.CLICK, go4);
function go4(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(2);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);
}
color_green.addEventListener(MouseEvent.CLICK, go5);
function go5(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(2);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);
}
color_blue.addEventListener(MouseEvent.CLICK, go6);
function go6(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(2);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(1);;
}
color_brown.addEventListener(MouseEvent.CLICK, go7);
function go7(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(2);
color_red.gotoAndStop(1);
}
color_red.addEventListener(MouseEvent.CLICK, go8);
function go8(event:MouseEvent): void {
color_black.gotoAndStop(1);
color_grey.gotoAndStop(1);
color_white.gotoAndStop(1);
color_yellow.gotoAndStop(1);
color_green.gotoAndStop(1);
color_blue.gotoAndStop(1);
color_brown.gotoAndStop(1);
color_red.gotoAndStop(2);
}
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM , onZoom);
function onZoom (e:TransformGestureEvent):void{
grid.scaleX *= (e.scaleX+e.scaleY)/2;
grid.scaleY *= (e.scaleX+e.scaleY)/2;
}
-
.
Hi Alloy,
You can shorten that lot down using arrays and loops, try this
PHP Code:
import flash.events.MouseEvent;
var rows:int = 40;
var i:int;
var colorArray:Array = new Array(color_black,color_grey,color_white,color_yellow,color_green,color_blue,color_brown,color_red);
for (i = 0; i < colorArray.length; i++)
{
colorArray[i].addEventListener(MouseEvent.CLICK, go);
}
for (i = 0; i < 2000; i++)
{
var grid:Grid = new Grid();
grid.x = 200 + Math.floor(i % rows) * (grid.width + 1);
grid.y = 50 + Math.floor(i / rows) * (grid.height + 1);
grid.name = "Grid Member:" + (i + 1);
grid.addEventListener(MouseEvent.ROLL_OVER,doFunction);
addChild(grid);
}
function doFunction(event:MouseEvent):void
{
trace(event.currentTarget.name);
for (i = 0; i < colorArray.length; i++)
{
if (colorArray[i].currentFrame == 2)
{
colorArray[i].gotoAndStop(i + 1);
}
}
}
function go(event:MouseEvent):void
{
for (i = 0; i < colorArray.length; i++)
{
colorArray[i].gotoAndStop(1);
}
event.currentTarget.gotoAndStop(2);
}
I havent tried messing with the mulitouch thing yet, as I don't use it.
Im not even sure how you test it as I dont have a touch screen
just ssaw the container part too
PHP Code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
var rows:int = 40;
var i:int;
var colorArray:Array = new Array(color_black,color_grey,color_white,color_yellow,color_green,color_blue,color_brown,color_red);
var container:MovieClip = new MovieClip();
addChild(container);
with (container)
{
x = 200;
y = 50;
}
for (i = 0; i < colorArray.length; i++)
{
colorArray[i].addEventListener(MouseEvent.CLICK, go);
}
for (i = 0; i < 2000; i++)
{
var grid:Grid = new Grid();
grid.x = Math.floor(i % rows) * (grid.width + 1);
grid.y = Math.floor(i / rows) * (grid.height + 1);
grid.name = "Grid Member:" + (i + 1);
grid.addEventListener(MouseEvent.ROLL_OVER,doFunction);
container.addChild(grid);
}
function doFunction(event:MouseEvent):void
{
trace(event.currentTarget.name);
for (i = 0; i < colorArray.length; i++)
{
if (colorArray[i].currentFrame == 2)
{
colorArray[i].gotoAndStop(i + 1);
}
}
}
function go(event:MouseEvent):void
{
for (i = 0; i < colorArray.length; i++)
{
colorArray[i].gotoAndStop(1);
}
event.currentTarget.gotoAndStop(2);
}
Last edited by fruitbeard; 08-28-2014 at 11:50 AM.
-
Client Software Programmer
you use the adobe air phone tools, for example you set 1 point for zoom and than u seperate or closen the next point and it simulates it, i use that and my android to test it thanks for the shortening code http://i.imgur.com/pLAOgIG.png
-
Client Software Programmer
i can no longer change states in my array but i got the zoom working thanks to your container did you eliminate the ROLL_OVER stuff
Last edited by AS3.0; 08-28-2014 at 12:37 PM.
-
Client Software Programmer
I fixed it, Thanks I went back to my old long code but kept the container
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|